Advertisement
Guest User

Untitled

a guest
Nov 28th, 2014
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. //Libraries used
  2. #include <iostream>
  3. #include <fstream>
  4. using namespace std
  5.  
  6. void main()
  7. {
  8. //Varaible Declaration
  9. ifstream fin;
  10. int InputGrade, grades[5] = { 0 }, sum = 0, count = 0;
  11.  
  12. // Welcome message
  13. cout << "---------------------------------------------\n"
  14. << " Mihai's Grades Satistics Evaluator \n"
  15. << "---------------------------------------------\n\n";
  16.  
  17. //Opening input file (with all the grades to be processed)
  18. fin.open("A4Q3.dat");
  19.  
  20. //Extracting each grade from file
  21. fin >> InputGrade
  22. while (fin) //while reading file
  23. {
  24. if (InputGrade >= 90) // grades[0] is an array counting the number of grades >= 90
  25. grades[0]++;
  26. else if (InputGrade >= 80) //grades[1] " " " " >= 80
  27. grades[1]++;
  28. else if (InputGrade >= 65) //...
  29. grades[2]++;
  30. else if (InputGrade >= 50) //...
  31. grades[3]++;
  32. else if (InputGrade < 50) //...
  33. grades[4]++;
  34. count++; //count tracks the total number of grades inputted
  35. sum += InputGrade; //sum tracks the total of the grades added up
  36. }
  37.  
  38. cout << "Class Average is: " << (sum / count) << "\n" //prints class average (total divided by the number of grades)
  39. << "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)
  40. << "Grades >= 80: " << setprecision(3) << (grades[1] * 1.0 / count) * 100 << "% \n" //..
  41. << "Grades >= 65: " << setprecision(3) << (grades[2] * 1.0 / count) * 100 << "% \n"
  42. << "Grades >= 50: " << setprecision(3) << (grades[3] * 1.0 / count) * 100 << "% \n"
  43. << "Grades < 50: " << setprecision(3) << (grades[4] * 1.0 / count) * 100 << "% \n" //..
  44. << "Thank you! \n";
  45.  
  46. InputGrades.close();
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement