0

Need help with private class. C++

What am I missing for this program to work? namespace Program2 { class student { private: double quiz1, quiz2; double midtermExam, finalExam; char letterGrade; public: //Constructors student() //Short hand: student(): quiz1(0.0), quiz2(0,0), finalExam(0,0), midtermExam(0,0), letterGrade('F') { quiz1 = 0.0; quiz2 = 0.0; midtermExam = 0.0; finalExam = 0.0; letterGrade = 'F'; } student(double newQuiz1, double newQuiz2, double newMidtermExam, double newFinalExam, char newLetterGrade) { quiz1 = newQuiz1; quiz2 = newQuiz2; midtermExam = newMidtermExam; finalExam = newFinalExam; letterGrade = newLetterGrade; } void setQuiz1(double newScore) { quiz1 = newScore; } double getQuiz1() { return quiz1; } void setQuiz2(double newScore) { quiz2 = newScore; } double getQuiz2() { return quiz2; } void setMidtermExam(double newScore) { midtermExam = newScore; } double getMidtermExam() { return midtermExam; } void setFinalExam(double newScore) { finalExam = newScore; } double getFinalExam() { return finalExam; } void setLetterGrade(char newGrade) { letterGrade = newGrade; } char getLetterGrade() { return letterGrade; } }; } int main() { using namespace Program2; cout << "\nEnter number of students: "; int number; cin >> number; student *listOfStudents = new student[number]; for (int i = 0; i < number; i++) { double score1; cout << "Enter student " << i + 1 << " Quiz 1: "; cin >> score1; listOfStudents[i].setQuiz1; double score2; cout << "Enter student " << i + 1 << " Quiz 2: "; cin >> score2; listOfStudents[i].setQuiz2; double score3; cout << "Enter student " << i + 1 << " Midterm Exam: "; cin >> score3; listOfStudents[i].setMidtermExam; double score4; cout << "Enter student " << i+1 << " Final Exam: "; cin >> score4; listOfStudents[i].setFina

23rd Sep 2018, 2:34 AM
Pinhead Larry
Pinhead Larry - avatar
3 Réponses
+ 2
Pinhead Larry looking into your code, it seems you have not used get and set method properly.. these are functions and take care of argument while calling functions.. if argument is not there, braces are required to call function.. refer below for changes to be done: 1. pass score as argument, taken as input from cin, to assign value to class variable as below : listOfStudents[i].setMidtermExam(score3); 2. set grade as below rather than setting as equal to Operator , because set method need one argument of char type : else if (averagePercent >= .90) { listOfStudents[i].setLetterGrade('A'); } 3. here as below, call method with paranthesis like getquiz1() instead of getquiz1 ommiting paranthesis: listOfStudents[i].getQuiz1() / 10 * .125
23rd Sep 2018, 4:12 AM
Ketan Lalcheta
Ketan Lalcheta - avatar
+ 1
Pinhead Larry do one thing please...copy your code links and paste it here to look into it..
23rd Sep 2018, 3:49 AM
Ketan Lalcheta
Ketan Lalcheta - avatar
0
rest of code double score4; cout << "Enter student " << i+1 << " Final Exam: "; cin >> score4; listOfStudents[i].setFinalExam; double averagePercent = (listOfStudents[i].getQuiz1 / 10 * .125) + (listOfStudents[i].getQuiz2 / 10 * .125) + (listOfStudents[i].getMidtermExam / 100 * .25) + (listOfStudents[i].getFinalExam / 100 * .5); if (listOfStudents[i].getQuiz1 < 0 || listOfStudents[i].getQuiz2 > 10 || listOfStudents[i].getQuiz2 < 0 || listOfStudents[i].getQuiz2 > 10 || listOfStudents[i].getMidtermExam < 0 || listOfStudents[i].getMidtermExam > 100 || listOfStudents[i].getFinalExam < 0 || listOfStudents[i].getFinalExam > 100) { i--; cout << "Wrong input, try again." << endl; continue; } else if (averagePercent >= .90) { listOfStudents[i].getLetterGrade = 'A'; } else if (averagePercent < .90 && averagePercent >= .80) { listOfStudents[i].getLetterGrade = 'B'; } else if (averagePercent < .80 && averagePercent >= .70) { listOfStudents[i].getLetterGrade = 'C'; } else if (averagePercent < .70 && averagePercent >= .60) { listOfStudents[i].getLetterGrade = 'D'; } else if (averagePercent < .60) { listOfStudents[i].getLetterGrade = 'F'; } } for (int i = 0; i < number; i++) { cout << "Quiz 1 score for student " << i + 1 << listOfStudents[i].getQuiz1 << endl; cout << "Quiz 2 score for student " << i + 1 << listOfStudents[i].getQuiz2 << endl; cout << "Midterm exam score for student " << i + 1 << listOfStudents[i].getMidtermExam << endl; cout << "Final exam score for student " << i + 1 << listOfStudents[i].getFinalExam << endl; cout << "Letter grade for student " << i + 1 << listOfStudents[i].getLetterGrade << endl; } delete[] listOfStudents; }
23rd Sep 2018, 2:37 AM
Pinhead Larry
Pinhead Larry - avatar