CS135 Grade Calculator Solved

25.00 $ 12.50 $



In this assignment, you will use C++ filestreams to read from a file a set of students’ names with their u will store the students into a series of arrays: string names LAMT_STUDENTS] (stores each student’s name), int testScores (AMT_STUDENTS] [AMT_TESTS] (a 2D array that stores each stu- dent’s test score, AMT_TESTS is a constant with the value 5 which means eac student has 5 test grades). double averages [AMT_STUDENTS] (stores each student’s test average), and char letterGrades (AMT_STUDENTS] (stores each student’s letter grade). The input file will not contain more than 20 students so AMT_STUDENTS will contain the value 20. So you have these arrays with 20 elements (or 20 rows for the 2D array), and we will use a portion of the arrays, some of the elements might not be used.

Since a 2D array cannot have each column store a different type, we use these arrays in parallel to emulate a large 2D array (think of each array as being its own column in this giant 2D array). The indices and the first index of the test Scores array) bind everything together, for example: names [0], averages [0], and letterGrades [0] contains the name, average, and letter grade for the 1st student in the list. This student’s test scores are stored in testScores[0][0], testScores[0][1], testScores [O] [2], testScores [O] (3), and test Scores [0] [4]. If I want to retrieve all the info for the 2nd student in our list, then we have to update the index in the 1D arrays and the first index in the 2D array, for example: names [1], averages [1], and letterGrades (1) contains the name, average, and letter grade for the 1st student in the list and testScores [1] [O], testScores [1][1], test Scores [1] [2], testScores [1] [3], and testScores [1] [4] contain the test scores for the 2nd student in the list and so on. You will need to implement the following functions:

• void readStudentsInfo(string names [], int tests [] [AMT_TESTS], ifstream& infile, int& studentCnt) – this function populates the string array and the 2D tests array by reading in the data from the file using the filestream variable, the integer will be an array counter to assign each name and test grades into the correct position of the names and tests array

• void computeAverage (int tests [] [AMT_TESTS], double average [], int studentCnt) – this func- tion computes each students average and stores each average into the average array, studentCnt denotes the range of elements in each array that are being used (this amount is computed in the readStudent Info) function

• char determineGrade (double average) – this function returns a letter grade based on the decimal passed in, so if the amount passed in is above or equal to 90.0 return ‘A’, if the amount is greater than or equal to 80.0 and less than 90.0 return a ‘B’ and so on

• double computeClassAverage (double averages [], int studentCnt) – computes the class aver- age, each student’s average is passed into the function along with the student counter . You will need at least one function for the output portion

In your program, you first read a filename from standard input and attempt to open a filestream, if the file is not found, re-prompt for input until a valid filename is read in. Then you will call readStudentsInfo function that will populate the names and tests arrays and updates the counter after each line has been read in. Then for each student, you will compute the average grade using the computeAverage () function and store the value into each element of the averages array. Then you will assign a letter grade to each element of the letter Grades array using the determineGrade () function. Then you display the results (see sample output) nicely aligned, as for the first line of output, the code below will do that this version is easily scalable, i.e. if I had more exams, this code will still work), feel free to change the set amount (maybe also use left and right manipulators as well)