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

Write a C++ program that will read student data from a file, compute average tes

ID: 3716882 • Letter: W

Question

Write a C++ program that will read student data from a file, compute average test scores and grades for the course, and output the data in a file. The data that will be stored in the output file are the student names, average test scores and grades only for the students that have a grade of C or better.

Use the input data below:

Each line contains the first name, last name, and 5 test scores. Each data is separated by whitespace. For example, in the first line Michael is the first name, Jackson is the last name, and 50 80 100 95 67 are the five test scores. You may use an array of structs to store the data.

Output the data in a file named outputData.txt. Each line should contain the first name, last name, the average test score and grade only for the students with grade C or better. You are free to output and format the data as you prefer.

Grades are assigned as following:

Average Test Score Grade

>=90 A

>=80 B

>=70 C

>=60 D

<60 F

-You don't have to check if user input is invalid. The program will be tested for valid inputs.

-Your program must have at least these three functions (You are free to implement more functions, if necessary):

-Function to read the students' data from the file

-Function to assign the relevant grade to each student

-Function to output the names, average scores and grades of the students with a grade of C or better to a file.

Explanation / Answer

#include <iostream>

#include <string>

#include <fstream>

using namespace std;

const int SIZE = 22;

struct Records {

string firstname;

string lastname;

int m1;

int m2;

int m3;

int m4;

int m5;

}record[SIZE];

int GetAvg(Records *record){

int avg = (record->m1 + record->m2 + record->m3 + record->m4 + record->m5) / 5;

return avg;

}

string GetGrade(int avg){

string grade = "";

if (avg >= 90)

{

grade = "A";

}

else if (avg >= 80)

{

grade = "B";

}

else if (avg >= 70)

{

grade = "C";

}

else if (avg >= 60)

{

grade = "D";

}

else if (avg < 60)

{

grade = "F";

}

return grade;

}

void readData(){

ifstream in("indata.txt");

if (!in){

cerr << "File can't be opened! " << endl;

system("PAUSE");

exit(1);

}

for (int i = 0; i < SIZE; i++){

in >> record[i].firstname >> record[i].lastname

>> record[i].m1 >> record[i].m2 >> record[i].m3 >> record[i].m4 >> record[i].m5;

}

}

void writeOutData(){

int avg;

string grade;

std::ofstream outfile("outputdata.txt");

for (int i = 0; i< SIZE; i++) {

avg = GetAvg(&record[i]);

grade = GetGrade(avg);

if (avg >= 70)

{

outfile << record[i].firstname << " " << record[i].lastname << " Avg: " << avg << " Grade : " << grade << std::endl;

cout << record[i].firstname << " " << record[i].lastname << " Avg: " << avg << " Grade : " << grade << std::endl;

}

}

outfile.close();

}

int main(){

readData();

writeOutData();

cin.ignore();

return 0;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote