1. You will read grades from a file called gradebook.txt 2. The number of grade
ID: 3769673 • Letter: 1
Question
1. You will read grades from a file called gradebook.txt 2. The number of grade may vary – They are not always 10 3. You will read everything using String then convert grades to int 4. Create two two-dimensional arrays one for first name, last name and one for
grades. 5. Count to see how many grades you have. 6. Create two more arrays one for average for each student and one for average for each test. 7. Create three SVG files to display
a. Average of each student b. Average of each test c. Sorted test average of course 8. Each bar should be different color preferably green for the highest and red for the lowest with decreeing green and increasing red as we go from highest to lowest.
Explanation / Answer
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <cstdlib>
using namespace std;
void read(ifstream& infile, ofstream& outfile);
void avg(ifstream& infile, ofstream& outfile);
int main()
{
ifstream infile;
ofstream outfile;
read(infile, outfile);
avg(infile, outfile);
}
void read(ifstream& infile, ofstream& outfile)
{
infile.open("gradebook.txt");
if(infile.fail())
{
cout << "Input file opening is failed." << endl;
exit(1);
}
outfile.open("output.txt");
if(outfile.fail())
{
cout << "Output file opening is failed." << endl;
exit(1);
}
}
void avg(ifstream& infile, ofstream& outfile)
{
string fname, lname;
char score[256];
stringstream temp11;
double sum11, avg11;
int score11,cn;
while(infile)
{
infile.getline(score,256);
temp11 << score;
cn = 0;
temp11 >> fname >> lname;
outfile << fname << " " << lname << " ";
while(temp11>>score)
{
sum11+=score11;
cn++;
outfile << score11 << " ";
}
avg11=sum11/cn;
outfile << avg11 << endl;
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.