This program runs correct until I get to the last function with the two dot-operators in the main. The program ends without giving me what I am asking for. I want it to return the best student and then the student's name. Can someone tell me how to fix this?
Code:
#include <iostream>
#include <string>
using namespace std;
class Grade
{
public:
void enterInfo();
double getWeight();
double getWeightedScore();
private:
string ID;
double mWeight;
double mScore;
};
class Student
{
public:
void enterInfo();
bool AreGoodWeights();
void showInfo();
string showName();
double addWeightedScoresTogether();
private:
string aName;
Grade mGrade1;
Grade mGrade2;
};
class Seminar
{
public:
void enterTheStudentsInfo();
void showTheFinalGrades();
Student getBestStudent();
private:
Student mStudent1;
Student mStudent2;
Student mStudent3;
};
int main()
{
Seminar EngLit;
EngLit.enterTheStudentsInfo();
EngLit.showTheFinalGrades();
cout << "The student with the highest final grade is: ";
EngLit.getBestStudent().showName();
return 0;
}
void Student::enterInfo()
{
cout << "Please enter your name: ";
cin >> aName;
cout << endl;
tryagain:
mGrade1.enterInfo();
mGrade2.enterInfo();
if (mGrade1.getWeight() + mGrade2.getWeight() == 1.0)
{
}
else
{
cout << "Your weights don't match up. Let's try this again." << endl;
goto tryagain;
}
}
void Grade::enterInfo()
{
cout << "Enter the ID of this test: ";
cin >> ID;
cout << endl;
cout << "What is the weight of this test?: ";
cin >> mWeight; // this will enter weight BEFORE it is in decimal form
cout << endl;
cout << "What is the score for this test?: ";
cin >> mScore;
cout << endl;
}
double Grade::getWeight()
{
return mWeight;
}
bool Student::AreGoodWeights()
{
if (mGrade1.getWeight() + mGrade2.getWeight() == 1.0) // if the weights (in decimal form) are equal to 1.0
{
return true; // then continue the program
}
else // otherwise
{
return false; // end the program
}
}
double Grade::getWeightedScore()
{
return mScore * mWeight;
}
void Seminar::enterTheStudentsInfo()
{
mStudent1.enterInfo();
mStudent2.enterInfo();
mStudent3.enterInfo();
}
string Student::showName()
{
return aName;
}
double Student::addWeightedScoresTogether()
{
return mGrade1.getWeightedScore() + mGrade2.getWeightedScore();
}
void Seminar::showTheFinalGrades()
{
cout << "Final Grades:" << endl;
cout << mStudent1.showName() << " : " << mStudent1.addWeightedScoresTogether() << endl;
cout << mStudent2.showName() << " : " << mStudent2.addWeightedScoresTogether() << endl;
cout << mStudent3.showName() << " : " << mStudent3.addWeightedScoresTogether() << endl;
}
Student Seminar::getBestStudent()
{
if (mStudent1.addWeightedScoresTogether() > mStudent2.addWeightedScoresTogether() &&
mStudent1.addWeightedScoresTogether() > mStudent3.addWeightedScoresTogether())
{
return mStudent1;
}
else if (mStudent2.addWeightedScoresTogether() > mStudent1.addWeightedScoresTogether()
&& mStudent2.addWeightedScoresTogether() > mStudent3.addWeightedScoresTogether())
{
return mStudent2;
}
else if (mStudent3.addWeightedScoresTogether() > mStudent1.addWeightedScoresTogether()
&& mStudent3.addWeightedScoresTogether() > mStudent2.addWeightedScoresTogether())
{
return mStudent3;
}
}