Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <string>
- using namespace std;
- int main()
- {
- int grade;
- int gradeRanges[8] = {0,0,0,0,0,0,0,0};
- ifstream File;
- string NameofFile;
- cout << "(Note: It helps if it's a .txt file with each line of the text file containing an individual score.)" << endl << endl; //Note
- cout << "Enter file name (i.e: pathway to the file in your desktop): ";
- cin >> NameofFile;
- File.open(NameofFile.c_str());
- int lineNum(1); //This variable counts the number of lines in the file
- double studentPercent = 0;
- double students = 0;
- cout << endl;
- while (File >> grade)
- {
- if (grade < 25)
- gradeRanges[0]++;
- else if (grade < 50)
- gradeRanges[1]++;
- else if (grade < 75)
- gradeRanges[2]++;
- else if (grade < 100)
- gradeRanges[3]++;
- else if (grade < 125)
- gradeRanges[4]++;
- else if (grade < 150)
- gradeRanges[5]++;
- else if (grade < 175)
- gradeRanges[6]++;
- else if (grade <= 200)
- gradeRanges[7]++;
- else
- cerr << "There is an invalid value in your file " << lineNum << endl;
- lineNum++;
- }
- cout << endl;
- cout << "Score Results"<< endl;
- int totalStudents = 0;
- for (size_t i = 0; i < 8; i++){
- totalStudents = totalStudents + gradeRanges[i];
- }
- cout << setprecision(1) << fixed;
- for (size_t i = 0 ; i < 8; i++)
- {
- students = gradeRanges[i] + (students - students);
- studentPercent = (students / totalStudents);
- studentPercent = studentPercent * 100;
- cout << "Number of grade between " << i * 25 << " - " << (i+1)*25 - 1 << ": " << gradeRanges[i] << " - " << studentPercent << " %" << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement