I have an assignment due soon and need help with it i dont want the work done for me but just some guidance here is the assignment.
write a program that reads a students name together his or her test scores the program should then compute the average test score for each student and assign the appropriate grade. the grade scale is as follows:
90-100, A; 80-89, B; 70-79, C; 60-69, D; 0-59, F.
your program must use the following functions:
A. a void function, calculateAverage, to determine the average of the five test scores for each student. use a loop to read and sum the five test scores. (this function does not output the average test score that task must be done in the function main.)
B. a value-returning function, calculateGrade, to determine and return each students grade. (this function does not output the grade that task must be done in the function main.)
test your program on the following data read the data from a file and send the output to a file do not use any global variables use the appropriate parameters to pass values in and out of functions
johnson 85 83 77 91 76
aniston 80 90 95 93 48
cooper 78 81 11 90 73
gupta 92 83 30 69 87
blair 23 45 96 38 59
clark 60 85 45 39 67
kennedy 77 31 52 74 83
bronson 93 94 89 77 97
sunny 79 85 28 93 82
smith 85 72 49 75 63
The output should be of the following form: (fill in the last two columns in the last line showing the class average.)
Student test1 test2 test3 test4 test5 average grade
johnson 85 83 77 91 76
aniston 80 90 95 93 48
cooper 78 81 11 90 73
gupta 92 83 30 69 87
blair 23 45 96 38 59
cla 60 85 45 39 67
kennedy 77 31 52 74 83
bronson 93 94 89 77 97
sunn 79 85 28 93 82
smith 85 72 49 75 63
class average =
here is what i have so far the comments in the program are from my professor
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
|
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
using namespace std;
string grade;
void calculateAverage(ifstream, int avg, int sum)
//you need a function that will use the average from the calculateAverage funntion
//to calculate the grade and print out the letter grade based on the average
{
while (inFile)
{
inFile >> score1 >> score2 >> score3 >> score4 >> score5;
sum = score1 + score2 + score3 + score4 + score5;
}
avg = sum;
}
//ah, here is the grade function.
char calculateGrade(double avg)
{
if (avg >= 90)
return 'A';
else if (avg >= 80)
return 'B';
else if (avg >= 70)
return 'C';
else if (avg >= 60 )
return 'D';
else return 'F';
}
int main()
{
int score1, score2, score3, score4, score5;
//you need to declare the varialbes you are going to be using here
//cournter, course average, class average, name , and grade,
//you can tell my looking at the datafile. they have names and scores
//you will also need to know the average to determine grade and counter to
//for the logic statement
ifstream inFile;
ofstream outFile;
inFile.open("Ch5_Ex14Data.txt");
if (!inFile)
{
cout << "There was an error opening the file" << endl;
}
/*
if statement to check if the file is open and error statement
output file to store grade goes next
formating statement to align the output in the new output file
command to write the Student Test1 Test2 Test3 Test4 Test5 Average Grade
use a for loop to place the names and scores into the file
you will be using the infle and outfile commands for this.
use the function to calculate the grade
calculateAverage(infile, outfile, courseAvg);
to get the correct answers you need to first get the average for each student then use
the studeant averagte to get the class average.
print out the class average
close the outfile and infile
you are done
*/
|