1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
|
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
using namespace std;
void readscore (int &, int &, int &, int &, int, ifstream &);
void printscore (int , int , int, int);
int main()
{
int id, score, num, ave, test;
ifstream data ("test_scores.txt");
readscore (id,test,num,ave,score,data);
printscore(id,score,num,ave);
return 0;
}
void readscore (int &id, int &test, int &num, int &ave, int score, ifstream &data)
{
test = 0;
if (!data)
cout << "Error File Does Not Exist, Please Try Again" << endl;
else
num = 0;
do
{
num = num + 1;
data >> id >> score;
test += score;
cout << num << " " << id << " " << test << endl; // to check # of students and addition *will remove later
}
while ( id != 0);
ave = test/num;
data.close();
}
void printscore (int id,int score, int num,int ave)
{
ifstream data ("test_scores.txt");
cout << "\n\t\tSCIENCE DEPARTMENT FALL 2018"<< endl;
cout << "\t\t TEST ANALYSIS\n"<< endl;
cout << "\t\tThe class average is " << ave << endl;
for(int num = -1; id !=0;num++)
{
void filewrite(int &, int &,int &,int &, ifstream &);
filewrite(id,score,num,ave,data);
}
}
void filewrite(int &id, int &score,int &ave,int &num, ifstream &data)
{
string msg;
ofstream fout;
fout.open("studentlist.txt");
data >> id >> score;
cout << "\nStudent Test Score Message"<< endl;
if (score > ave)
msg = "above average";
else if (score == ave)
msg = "is equal to average";
else
msg = "below average";
fout << num <<" "<< id <<" "<< score<< " " << msg << endl;
fout.close();
}
| |