Write a program to compute numeric grades for a course. The course records are i
ID: 3623196 • Letter: W
Question
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 students first name, then one space , then ten 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 be the same as the data in the input file except that there will be one additional number (double) at the end of each line. This number will be the average of the students ten quiz scores.
PLZ do it without using array!
Explanation / Answer
please rate - thanks
#include <iostream>
#include <fstream>
using namespace std;
void calculate(ifstream&, ofstream&);
int main()
{
ifstream in;
ofstream out;
in.open("input.txt"); //open file
if(in.fail()) //is it ok?
{ cout<<"input file did not open please check it ";
system("pause");
return 1;
}
out.open("output.txt"); //open file
calculate(in,out);
out.close();
in.close();
return 0;
}
void calculate(ifstream& in, ofstream& out)
{int i,sum,a;
string first,last;
double avg;
in>>first;
while(in)
{sum=0;
in>>last;
out<<first<<" "<<last<<" ";
for(i=0;i<10;i++)
{in>>a;
out<<a<<" ";
sum+=a;
}
avg=sum/10.;
out<<avg<<endl;
in>>first;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.