Write a program to compute numeric grades for a course The c

Write a program to compute numeric grades for a course. The course records are in a file 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 the student’s first name, then one space, then ten quiz scores all on one line. The quiz scores are whole numbers and are separated by spaces. Your program will take its input from this file and send its output to a second file. The data in the output file will be the same as the data in the input file except that there will be one additional number (of type double ) at the end of each line. This number will be the average of the student’s ten quiz scores. At the same time as you output to the file, also output the student’s full name an average quiz score to the console. Use a function for computing the average of each student’s quiz scores. Pass the stream objects for the input and output file. Make sure to pass them by reference so that any changes made to their streams (advancing the stream) will be present when you get back to int main. This function should read in only the quiz scores and then output the quiz scores and average score to the output file. You may use the following prototype for the function: void calcAvg(ifstream& in, ofstream& out); Your program should be able to handle any number of students in the input file. A sample input file has been provided. There is no guarantee that this exact file will be used for grading so make sure your program is robust. Make sure your program can handle missing and unopenable files.

Sample Output: Console (given provided input file)

Damian Hess 6.5

Andrew Nielsen 6.2

Alfred Yankovic 6.9

Inga Scharf 7.6

Sample Output: “lab08_out.txt” (given provided input file)

Hess Damian 5 10 7 5 9 2 8 5 6 8 6.5

Nielsen Andrew 7 9 8 7 4 7 3 4 9 4 6.2

Yankovic Alfred 6 5 8 10 9 6 5 7 3 10 6.9

Scharf Inga 9 2 7 10 7 8 8 10 6 9 7.6

Solution

Solution:

#include <iostream>
#include <fstream>
using namespace std;
void calculate(ifstream&, ofstream&);
int main()
{
ifstream in;
ofstream out;
in.open(\"input.txt\");          
if(in.fail())            
   { cout<<\"input file did not open please check it\ \";
   system(\"pause\");
   return 1;
   }
out.open(\"output.txt\");          

calculate(in,out);
out.close();
in.close();
system(\"pause\");
return 0;
}
void calculate(ifstream& in, ofstream& out)
{int i,sum,a[10];
string first,last;
double avg;
in>>first;
while(in)
   {sum=0;
   in>>last;
   for(i=0;i<10;i++)
      {in>>a[i];
      sum+=a[i];
      }
   out<<first<<\" \"<<last<<\" \";
   for(i=0;i<10;i++)
      out<<a[i]<<\" \";
   avg=sum/10.;
   out<<avg<<endl;
   in>>first;
   }
}    

Write a program to compute numeric grades for a course. The course records are in a file that will serve as the input file. The input file is in exactly the fol
Write a program to compute numeric grades for a course. The course records are in a file that will serve as the input file. The input file is in exactly the fol

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site