Any expert know how to write this program? Average each student score and assigned a letter grade

Use this information student names and test score
Andrew Miller 87.5 89 65.75 37 98.5
John Doe 86 88 85.25 90 95
John Smith 52 82 79 88.5 85
Jane Deer 90 93 91 92.75 94
William Clinton 95 97 95.75 90 92
George Jones 89 81.5 75 85.25 88
Sarah White 75.5 78 85 88 84
Bill Able 88 90 86.75 91 93.5
Larry Brown 99 95 98 96.5 97
Amanda Ernst 76 79.5 77 82 84.25
Richard Farmer 84.75 87 80 85 86
Sam Green 87 91.75 85 88 90
Paula Hamilton 98 100 97.5 95 98.5
Jesus Javiar 77.5 82 85 78 86
Christy King 86 89.25 92 90 94.75
Bob Bush 70 75.5 77 79 81.25
Jerry Landers 95.5 97 96 92.75 94
Sally Moore 97 99 98.25 94 99
Nancy Nadler 91 93.25 90 89 92.5
Tina Templar 85 82 88.75 84 90

This is given information
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>

using namespace std;

int main()
{
//Declare variables;
ifstream inFile; //input file stream variable
ofstream outFile; //output file stream variable

double testScore;
double sum = 0;
string firstName;
string lastName;

inFile.open("test.txt");
outFile.open("testavg.txt");

outFile << fixed << showpoint;
outFile << setprecision(2);

cout << "Processing data" << endl;

inFile >> firstName >> lastName;
outFile << "Student name: " << firstName
<< " " << lastName << endl;
outFile << "Test scores: ";

inFile >> testScore; //Read the first test score
outFile << setw(6) << testScore; //Output the test score
sum = sum + testScore; //Update sum

inFile >> testScore; //Read the second test score
outFile << setw(6) << testScore; //Output the test score
sum = sum + testScore; //Update sum

inFile >> testScore; //Read the third test score
outFile << setw(6) << testScore; //Output the test score
sum = sum + testScore; //Update sum

inFile >> testScore; //Read the fourth test score
outFile << setw(6) << testScore; //Output the test score
sum = sum + testScore; //Update sum

inFile >> testScore; //Read the fifth test score
outFile << setw(6) << testScore; //Output the test score
sum = sum + testScore; //Update sum

outFile << endl;

outFile << "Average test score: " << setw(6)
<< sum / 5.0 << endl;

inFile.close();
outFile.close();

// Simple Hold Screen Code for Command Prompt C++ Compilers
char holdscr; // This character and section is to hold screen open
cout << "\n\n\tPress a character and Enter to exit program. ";
cin >> holdscr;

return 0;



This is a very common beginner's homework. You need to learn to write it yourself.

I recommend you use a struct to store the student names and the array of grades. Then write something to read a student into one of those structs. Then do it as many times as there are students to read from the file.

Once done, you can compute things like averages from the arrays.

To get the class average, compute the average for each student, then average those.

Good luck.
Topic archived. No new replies allowed.