Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

c++ files This project involves reading student grades from an input file and processing it to calculate each student's average grade and letter grade. At

c++ files

This project involves reading student grades from an input file and processing it to calculate each student's average grade and letter grade. At the end of the program you will display various statistics. Do the main part of the program first, then come back and work on the statistics. Remember, do one part at a time. The specific tasks are: 1. ADD A COMMENT BLOCK with your name, lab name, description, input variables! 2. Read the headings from the file ch5input.txt. The file will have four headings. You can use four variables to read them in, or use a loop if you want: inputstreamvar >> heading1 >> heading2 >> heading3 >> heading4; Print out headings (use setw to make it easier). Below is part of the cout line. cout << setw(20) << heading1 << setw(10) << heading2 << 3. Note: Your output will have more headings than the input file. The input file just has headings for the first five columns, but you will be adding two more columns. Simply add the following, for example, to the end of the cout line: << setw(10) << "Average" 4. Now, using a loop: while (!inputstreamvar.eof()) Read student's record from the file "ch5input.txt" using the inputstreamvar you created. a. You will be reading FIVE items: first name, last name, test1, test2, test3. Below is a partial line similar to what you will need to include in your program: inputstreamvar >> fname >> lname >> b. For testing purposes, to verify you have correctly read in the data, print it out using a cout. It would probably be a good idea to use setws to print out the data to get it ready for your final output, but you can also save that to the end. c. Calculate the students average grade using the three tests grades you just read in. d. Assign letter grade to each student based on average grade (Hint: use switch or if). e. Finish the output line for the current record. Either add the Average and Letter grade to what you have already printed, or print the entire line starting with name and ending with letter grade. There are multiple ways to do this, but the main thing, is that the last by the time you are finished with one pass of the loop, the entire first record for the output will be printed. 5. After you get the above working, calculate statistics: a. Within the loop of step 4, add various totals/counters so that you can calculate high grade, low grade, test1 avg, test2 avg, test3 avg, class avg. b. Display a line for the class average. c. Display the highest grade d. Display the lowest grade e. Display test1 average, test2 average and test3 average 6. The data file can be called anything you like, but it must contain the following data. I will include a ch5input.txt file on the website, under these instructions, if you wish to use that file instead of creating one from scratch: Name Exam-1 Exam-2 Exam-3 JJ Watt 100 99 98 Tom Selleck 88 90 88 Salma Hayek 80 87 82 Oprah Winfrey 95 90 85 George Takei 60 70 90 Sheldon Cooper 99 99 99 Russell Peters 89 79 71 The output will look as follows (your spacing can differ a little but thats about the only change you should have). You may make one change (if desired) and add the exam averages on the same line as the class average, under their respective columns, or you can leave it as shown below. OR you could do this, which is a tiny bit more work (notice test grades dont have decimal places):

#include

#include

#include

#include

#include

using namespace std;

int main()

{

string heading1, heading2, heading3, heading4;

ifstream cinfile;

cinfile.open("ch5input.txt");

cinfile >> heading1 >> heading2 >> heading3 >> heading4;

cout << setw(20) << heading1 << setw(10) << heading2 << setw(10) << heading3 << setw(10) << heading4 << setw(10) << " Average " << setw(10) << " Letter " << endl;

string fname, lname;

int exam1, exam2, exam3;

cout << "-------------------------------------------------------------------------" << endl;

while (cinfile >> fname >> lname >> exam1 >> exam2 >> exam3) {

char letterGradeForStudent;

double avg;

avg = (exam1 + exam2 + exam3) / 3;

if (avg >= 90 && avg <= 100) {

letterGradeForStudent = 'A';

}

else if(avg >= 80) {

letterGradeForStudent = 'B';

}

else if(avg >= 70) {

letterGradeForStudent = 'C';

}

else if (avg >= 60) {

letterGradeForStudent = 'D';

}

else

letterGradeForStudent = 'F';

cout << fixed << setprecision(2) << setw(20) << fname + " " + lname << setw(10) << exam1 << setw(10) << exam2 << setw(10) << exam3 << setw(10) << avg << setw(10) << letterGradeForStudent << endl;

}

cout << "-------------------------------------------------------------------------" << endl;

// need to add the class average,

//lowest grade,

//highest grade,

//average for exam1,

//exam2,

// exam3

system("pause");

return 0;

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Construct a coloring of the graph shown using this algorithm. a b

Answered: 1 week ago

Question

2. How were various roles filled?

Answered: 1 week ago