Hello,
i have to do that :
Write a program to read class grades from a file (A5Q3.dat - which is given to you) into an array grades and to then output to the screen the following information:
Class Average
Percentage of grades >= 90
Percentage of grades < 90 and >= 80
Percentage of grades < 80 and >= 65
Percentage of grades < 65 and >= 50
Percentage of grades < 50
Show average and percentages accurate to 2 places after the decimal (xx.xx and xx.xx%).
I need to put them into functions, but i will do that if i have the correct code, but can't seem to resolve it.
what i was able to do until now is:
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 72
|
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main()
{
ifstream iFile("A5Q3.txt");//input file
ofstream oFile("A5Q3O.txt");//output file
string iLine;
int grade=100;
int record[grade];
double percent;
int count=0;
int sum;
if (iFile.good() && oFile.good()) //if file is opening
{
while(getline(iFile, iLine)) //read line by line
{
int size = iLine.length();
for(grade=0;grade<=size;grade++)
{
for(count=0;count<=size;count++)
{
if (grade>=90)
{
percent = (sum+=grade)/(count);
cout<<percent<<"%";
}
else if(grade>=80 && grade<90)
{
percent = (sum+=grade)/(count);
cout<<percent<<"%";
}
else if(grade>=65 && grade<80)
{
percent = (sum+=grade)/(count);
cout<<percent<<"%";
}
else if(grade>=50 && grade<65)
{
percent = (sum+=grade)/(count);
cout<<percent<<"%";
}
else if (grade<50)
{
percent = (sum+=grade)/(count);
cout<<percent<<"%";
}
}
}
}//END OF WHILE
cout<<endl;
cout<<"The files are now closed. "<<endl;
cout<<"You can see the text in reverse in the file A3Q3O.txt. "<<endl;
iFile.close();
oFile.close();
}//END OF IF FOR FILES OPENING.
else
cout<<"Error, can't open the input file. "<<endl;//if can't open file error msg.
return 0;
}//END OF MAIN
|
Thanks for any help.
this is what is inside the file:
55 56 90 88 34 10 0 67 76 55
81 87 72 68 73 77 97 80 85 73
33 62 74 76 91 83 84 79 88 79