Question: Write a C++ program that asks the user to enter students (name and score; grade should be determined on the basis of score). Student will
Write a C++ program that asks the user to enter students (name and score; grade should be determined on the basis of score). Student will be a class. Each time ask the user whether they want to add another student (do not ask how many students the user wants to enter). Store the students in a vector (so you will continuously grow the vector). After the user finishes entering students, the program should report how many students have been entered and what the average score is. It should also sort the students (and print out the info) in descending order of scores.
This is the code I have so far (I am missing outputing the number of students, the average score, and sorting in descending order of scores):
#include
using namespace std;
class Student { private: string name; float score;
public: // constructor with parameter name and score Student(string name, float score);
// get name string getName();
// get score float getScore();
getAverage(); };
int main() {
vector
do {
cout << "Enter a student's name: "; getline(cin,name);
cout << " Enter that student's score: "; cin >> score;
classSize.push_back(Student(name,score)); // adding object to vector
cout << " Would you like to add another student to the list? (y/n) "; cin >> choice;
}
while(choice=='y' || choice=='Y');
return 0; }
// member definition
Student::Student(string name1, float score1) { name1 = name; score1 = score; }
string Student::getName() { return name; }
float Student::getScore() { return score; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
