1

This is the first program that i've written myself, i've been using one of those learn C++
in 21 days books and links from daniweb to learn. Using daniweb is a whole lot less boring than reading that crappy book. I'm just looking for a review, some advice, anything about my program and/or any advice you wish to give, thx in advance.

// enter 5 test scores
//takes the lowest score out of the equation and finds the average of the remaining 4 scores
//credit goes out to naya22 from daniweb for the program idea
#include "ScoreChop.h"
#include <iostream>
using namespace std;

int main()
{
    ScoreChop sessionOne;
    sessionOne.EntScores();
    sessionOne.FindLow();
    sessionOne.AvgScores();
    
    cin.get();
    cin.get();
    return 0;
}
#include <iostream>
#include <vector>
using namespace std;
class ScoreChop
{
      public:
             ScoreChop();
             ~ScoreChop();
             void EntScores();
             int FindLow();
             void AvgScores();
      private:
              int loScore;
              int avgScore;
              int score1;
              int score2;
              int score3;
              int score4;
              int score5;
              vector<int> scoreList;
};

ScoreChop::ScoreChop()
{
	score1 = 0;
	score2 = 0;
	score3 = 0;
	score4 = 0;
	score5 = 0;
	loScore = 0;
	avgScore = 0;
	scoreList.push_back(score1);
	scoreList.push_back(score2);
	scoreList.push_back(score3);
	scoreList.push_back(score4);
	scoreList.push_back(score5);
}

ScoreChop::~ScoreChop()
{
}

void ScoreChop::EntScores()
{
     
     for(int i = 0; i < 5; i++)
     {
	cout << "Enter test score " << i + 1 << ": ";
                cin >> scoreList[i];
                cout << endl;
     }
}

int ScoreChop::FindLow()
{
    loScore = scoreList[0];
    for(int i = 1; i < 5; i++)
    {
            if(loScore > scoreList[i])
                     loScore = scoreList[i];
    }
    cout << "The lowest score was " << loScore << "." << endl;
    return loScore;
}
     
void ScoreChop::AvgScores()
{
     for (int i = 0; i < 5; i++)
     {
         avgScore += scoreList[i];
     }
     cout << "the average score minus the lowest score was: " << (avgScore - loScore)/4;
     cout << endl;
}

Christopher

Votes + Comments
Thanks for using code tags correctly :)
2
Contributors
1
Reply
2
Views
8 Years
Discussion Span
Last Post by Ancient Dragon
0

you can delete score1, score2, ... score5 from the class because they are not needed. You can initialize a vector with 5 integers by using its resize() method scoreList.resize(5); and each element is initialized to 0.

So the constructor reduces to this:

ScoreChop::ScoreChop()
{
    loScore = 0;
    avgScore = 0;
    scoreList.resize(5);
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.