Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

any can help me for this code, am trying to calculate each student score , total

ID: 3762452 • Letter: A

Question

any can help me for this code, am trying to calculate each student score , total average and grade using vector. but it prints wrong for the last student score and total average. it addes extra in put for the last student. i don't know why. it suppose print 74.2 average but it print out 72.2

here is the input given

Oneill 59 67 56 70 97
Hess 91 50 85 62 63
Ritter 81 67 99 62 97
Munoz 52 68 55 52 94
Bright 87 97 89 78 100
Pennington 56 67 86 65 82
Dawson 98 91 78 58 56
Ashley 54 60 72 75 89
Todd 87 51 81 68 51
Swanson 98 69 90 92 56

and here is my code what i try

#include <iostream>
#include <string>
#include <vector>
#include <iomanip>
using namespace std;

#define NUM_SCORES 5

//Student class
class Student{
public :

   //set name
   void set_name( const string& name );
   //set score at index
void set_score( int index, int score );
   //get name
string get_name() const;
   //get score
int get_score( int index ) const;
   //get total
int get_total() const;
   //get average
float get_average() const;
   //get grade
char get_grade() const;
private:
   string name;
   int scores[NUM_SCORES];
};


//set name
void Student::set_name( const string& name ){
   this->name = name;
}

//set score at index
void Student::set_score( int index, int score ){
   scores[index] = score;
}

//get name
string Student::get_name() const{
   return name;
}

//get score
int Student::get_score( int index ) const{
   return scores[index];
}

//get tStudent::otal
int Student::get_total() const{
   int total = 0;
   for (int i = 0; i < NUM_SCORES; i++)
   {
       total += scores[i];
   }
   return total;
}

//get average
float Student::get_average() const{
   return (float)get_total() / (float)NUM_SCORES;
}

//get grade
char Student::get_grade() const{
   float average = get_average();
   if (average >= 90)
   {
       return 'A';
   }else if (average >= 80)
   {
       return 'B';
   }else if (average >= 70)
   {
       return 'C';
   }else if (average >= 60)
   {
       return 'D';
   }else
   {
       return 'F';
   }
}

//function to read and store data into vector of Student
vector<Student> readData();

//compute avg scores for all students
double computeAVGAllStudents(vector<Student> students);

//function to output the results
void output(vector<Student> students);

//main function
int main(){
   //read students
   vector<Student> students = readData();

   //output result
   output(students);

   return 0;  
}

//function to read and store data into vector of Student
//precondition: N/A
//postcondition: students are loaded to vector
vector<Student> readData(){

   vector<Student> students;

   string name;
   int score;
   while (!cin.eof())
   {
       Student student;
       //read name
       cin >> name;

       student.set_name(name);

       //read scores
       for (int i = 0; i < NUM_SCORES; i++)
       {
           cin >> score;
           student.set_score(i, score);
       }

       //add student to vector
       students.push_back(student);
   }
   return students;
}

//compute avg scores for all students
//precondition: students is not empty
//postcondition: the average scores for all students are returned
double computeAVGAllStudents(vector<Student> students){
   double sum = 0;
   for (int i = 0; i < students.size(); i++)
   {
       sum += students[i].get_average();
   }
   return sum / (double)students.size();
}

//function to output the results
//precondition: students is not empty
//postcondition: the student information and statistics are printed on console
void output(vector<Student> students){
   //print header
   cout << fixed;
   cout << setw(15) << left << "Name" << setw(8) << "Score 1"
       << setw(8) << "Score 2"<< setw(8) << "Score 3"
       << setw(8) << "Score 4"<< setw(8) << "Score 5"
       << setw(10) << "Average"<< setw(5) << "Grade" << endl;
   cout << "-------------- ------- ------- ------- ------- ------- ------- -------" << endl;
   //for each records
   for (int i = 0; i < students.size(); i++)
   {
       cout << setw(14) << left << students[i].get_name() << right << setw(8) << students[i].get_score(0)
       << setw(8) << students[i].get_score(1) << setw(8) << students[i].get_score(2)
       << setw(8) << students[i].get_score(3) << setw(8) << students[i].get_score(4)
       << setw(8) << setprecision(1) << students[i].get_average() << setw(8) << students[i].get_grade() << endl;
   }
   cout << " -----" << endl;
   cout << setw(52) << right << "Average" << setw(10) << right << computeAVGAllStudents(students) << endl;
   cout << " =====" << endl;
}

please help thank you

Explanation / Answer

#include // allows the program to output data to the screen 02 #include 03 #include 04 #include 05 #include 06 #include "students.h" // gradebook class defintion 07 08 09 using std::cout; // program uses cout 10 using std::cin; // program uses cin 11 using std::endl; // program uses endl 12 using std::setprecision; // set numeric output precision 13 using std::fixed; // ensures that decimal point is displayed 14 using std::setw; 15 16 17 void students::displayMessage() 18 { 19           20     cout