- #1
FallArk
- 127
- 0
So, I was asked to make a program that will calculate my own grade, and it is required to use subclasses inside a class.
main is posted below and cannot be changed:
what I have done:
My idea is to find the general case of this program, then use it as a template to fill the others. I was thinking that create a class that will ask the user(myself in this case) to input the grade, and then declare this subclass in class Grade, the getexercises function then have a for loop to keep asking for input until the user input -1. But as of now, the loop will not exit when -1 is entered, and it keeps going #1... #2... #3... #1... etc, instead of going 1...2...3...4...5...6...
Help!
main is posted below and cannot be changed:
Code:
int main() {
Grade gradeMe;
gradeMe.getExercises();
gradeMe.getClickers();
gradeMe.getLabs();
gradeMe.getTraces();
gradeMe.getAssignments();
gradeMe.getTests();
gradeMe.getPrefinal();
gradeMe.getFinal();
gradeMe.displayTotals();
}
what I have done:
Code:
class Grade {
public:
class Textbook{
public:
int textbookPts;
int i = 1;
int bookPts() {
cout << "Enter textbook exercise #" << i << " (out of 10 points): ";
cin >> textbookPts;
++i;
return textbookPts;
}
};
Textbook Text[10];
int getExercises() {
for (int x = 0; x < 10; ++x){
Text[x].bookPts();
textbookSum += Text[x].bookPts();
if (Text[x].bookPts() == -1)
break;
textbookTotal = x * 10;
}
cout << textbookSum << " out of " << textbookTotal << " points for textbook grade" << endl;
return textbookSum;
}
private:
int textbookSum = 1;
int textbookTotal = 0;
};
My idea is to find the general case of this program, then use it as a template to fill the others. I was thinking that create a class that will ask the user(myself in this case) to input the grade, and then declare this subclass in class Grade, the getexercises function then have a for loop to keep asking for input until the user input -1. But as of now, the loop will not exit when -1 is entered, and it keeps going #1... #2... #3... #1... etc, instead of going 1...2...3...4...5...6...
Help!