Advertisement
Guest User

Untitled

a guest
Nov 21st, 2019
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.89 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.  
  10. int grade;
  11.  
  12. int gradeRanges[8] = {0,0,0,0,0,0,0,0};
  13.  
  14. ifstream File;
  15.  
  16. string NameofFile;
  17.  
  18.  
  19. cout << "(Note: It helps if it's a .txt file with each line of the text file containing an individual score.)" << endl << endl; //Note
  20. cout << "Enter file name (i.e: pathway to the file in your desktop): ";
  21. cin >> NameofFile;
  22.  
  23. File.open(NameofFile.c_str());
  24.  
  25. int lineNum(1); //This variable counts the number of lines in the file
  26.  
  27. double studentPercent = 0;
  28. double students = 0;
  29.  
  30. cout << endl;
  31. while (File >> grade)
  32. {
  33. if (grade < 25)
  34. gradeRanges[0]++;
  35. else if (grade < 50)
  36. gradeRanges[1]++;
  37. else if (grade < 75)
  38. gradeRanges[2]++;
  39. else if (grade < 100)
  40. gradeRanges[3]++;
  41. else if (grade < 125)
  42. gradeRanges[4]++;
  43. else if (grade < 150)
  44. gradeRanges[5]++;
  45. else if (grade < 175)
  46. gradeRanges[6]++;
  47. else if (grade <= 200)
  48. gradeRanges[7]++;
  49. else
  50. cerr << "There is an invalid value in your file " << lineNum << endl;
  51.  
  52.  
  53. lineNum++;
  54.  
  55. }
  56.  
  57. cout << endl;
  58. cout << "Score Results"<< endl;
  59. int totalStudents = 0;
  60. for (size_t i = 0; i < 8; i++){
  61. totalStudents = totalStudents + gradeRanges[i];
  62. }
  63.  
  64. cout << setprecision(1) << fixed;
  65. for (size_t i = 0 ; i < 8; i++)
  66. {
  67. students = gradeRanges[i] + (students - students);
  68. studentPercent = (students / totalStudents);
  69. studentPercent = studentPercent * 100;
  70.  
  71.  
  72. cout << "Number of grade between " << i * 25 << " - " << (i+1)*25 - 1 << ": " << gradeRanges[i] << " - " << studentPercent << " %" << endl;
  73. }
  74.  
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement