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

Problem Instructions Write a program to compute numeric grades for a course. The

ID: 3633374 • Letter: P

Question


Problem Instructions

Write a program to compute numeric grades for a course. The course records are in a file ( grade.txt** ) that will serve as the input file.

The input file is in exactly the following format: Each line contains a student's last name, then one space, then student's first name, then one space, then ten (10) quiz scores all on one line. The quiz scores are whole numbers and are separated by one space.

Your program will take its input from this file and send its output to a second file. The data in the output file will contain the last name, initial of the first name, grade average (of type double) at each line. This grade average will be the average of the student's ten quiz scores.

You should prompt the user for filenames or paths.

Example:

Please type in the INPUT filename or path: grades.txt
Please type in the OUTPUT filename or path: avgGrades.txt
Smith J 10
Lee S 8.6
Parker P 8.9
Sanchez J 6.3
Chen S 5.5
Michael G 5.3


** Text file:
Smith John 10 10 10 10 10 10 10 10 10 10
Lee Samantha 10 9 10 9 10 5 10 8 7 8
Parker Peter 9 9 9 9 8 8 10 9 9 9
Sanchez Julia 2 5 6 4 5 7 6 9 9 10
Chen Stanley 1 2 3 4 5 6 7 8 9 10
Michael George 2 2 2 2 5 8 8 8 8 8

Explanation / Answer

please rate - thanks

#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;
int main()
{ifstream in;
ofstream out;
char filename[20];
char initial;
string first,last;
int grades[10],i,sum;
double average;
cout<<"Please type in the INPUT filename or path: ";
cin>>filename;
in.open(filename);
if(in.fail())
   { cout<<"input file did not open please check it ";
    system("pause");
     return 1;
    }
cout<<"Please type in the OUTPUT filename or path: ";
cin>>filename;   
out.open(filename);
in>>last;
while(in)
{in>>first;
initial=first[0];
sum=0;
for(i=0;i<10;i++)
     {in>>grades[i];
     sum+=grades[i];
     }
average=sum/10.;
out<<last<<" "<<initial<<" "<<setprecision(1)<<fixed<<average<<endl;
in>>last;
}
out.close();   
in.close();

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