Question: Need to make this CPP file ask for student name, assignment, and grade. Then when you exit the program it displays the number of students

Need to make this CPP file ask for student name, assignment, and grade. Then when you exit the program it displays the number of students and the mean of all the grades.

here is the code I have so far.

"

#include

#include

#include

#include

#include

#include

using namespace std;

int main()

{

string filename = "students.txt";

cout << "Student File ";

ifstream input_file;

input_file.open(filename);

if (input_file) {

// initialize variables

string student, assignment;

vector students, assignments;

double grade;

vector<double> grades;

cout << "Enter student: ";

cin >> student;

cout << "Enter assignment: ";

cin >> assignment;

cout << "Enter grade: ";

cin >> grade;

students.push_back(student);

assignments.push_back(assignment);

grades.push_back(grade);

char choice;

cout << "Save changes? y/n: ";

cin >> choice;

ofstream output_file;

if (choice = 'y') {

output_file.open(filename);

for (int i = 0; i < students.size(); ++i) {

student = students[i];

assignment = assignments[i];

grade = grades[i];

output_file << student << '\t' << assignment << '\t' << grade << ' ';

}

output_file.close();

cout << "Your changes have been saved. ";

}

else if (choice = 'n')

cout << "Your changes have not been saved! ";

}

input_file.close();

}"

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!