Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Libraries used
- #include <iostream>
- #include <fstream>
- using namespace std
- void main()
- {
- //Varaible Declaration
- ifstream fin;
- int InputGrade, grades[5] = { 0 }, sum = 0, count = 0;
- // Welcome message
- cout << "---------------------------------------------\n"
- << " Mihai's Grades Satistics Evaluator \n"
- << "---------------------------------------------\n\n";
- //Opening input file (with all the grades to be processed)
- fin.open("A4Q3.dat");
- //Extracting each grade from file
- fin >> InputGrade
- while (fin) //while reading file
- {
- if (InputGrade >= 90) // grades[0] is an array counting the number of grades >= 90
- grades[0]++;
- else if (InputGrade >= 80) //grades[1] " " " " >= 80
- grades[1]++;
- else if (InputGrade >= 65) //...
- grades[2]++;
- else if (InputGrade >= 50) //...
- grades[3]++;
- else if (InputGrade < 50) //...
- grades[4]++;
- count++; //count tracks the total number of grades inputted
- sum += InputGrade; //sum tracks the total of the grades added up
- }
- cout << "Class Average is: " << (sum / count) << "\n" //prints class average (total divided by the number of grades)
- << "Grades >= 90: " << setprecision(3) << (grades[0] * 1.0 / count) * 100 << "% \n" //prints percentage of grades >= 90 ( # of grades * 1.0 (for double) / ( total # of grades) * 100 (for percentage)
- << "Grades >= 80: " << setprecision(3) << (grades[1] * 1.0 / count) * 100 << "% \n" //..
- << "Grades >= 65: " << setprecision(3) << (grades[2] * 1.0 / count) * 100 << "% \n"
- << "Grades >= 50: " << setprecision(3) << (grades[3] * 1.0 / count) * 100 << "% \n"
- << "Grades < 50: " << setprecision(3) << (grades[4] * 1.0 / count) * 100 << "% \n" //..
- << "Thank you! \n";
- InputGrades.close();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement