Advertisement
A_Tammaa

Grade calculator

Apr 19th, 2019
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.49 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. #include <string>
  5. #include <math.h>
  6. #include <set>
  7. #include <map>
  8. #include <queue>
  9. #include <deque>
  10. #include <fstream>
  11. #include <iomanip>
  12. #include <windows.h>
  13. typedef long long ll;
  14. using namespace std;
  15. void findCount(ifstream &read,string s) {
  16.     read.open(s);
  17.     vector<char> Grade;
  18.     string temp;
  19.     cout << setprecision(2) << showpoint << fixed;
  20.     while (getline(read, temp)) {
  21.         int Grade_finder = temp.size();
  22.         Grade.push_back(temp[Grade_finder - 1]);
  23.     }
  24.     sort(Grade.begin(), Grade.end());
  25.     float counter = 0, total = Grade.size() - 1;
  26.     for (int i = 0; i < total; i++) {
  27.         if (Grade[i] == Grade[i + 1]) {
  28.             counter++;
  29.         }
  30.         else {
  31.             counter++;
  32.             float average = (counter / total) * 100;
  33.             cout << "Number of student with the grade: " << Grade[i] << " is " << (int)counter << endl;
  34.             cout << "The percentage of the student with grade " << Grade[i] << " is " << (int)average << "% \n";
  35.             counter = 0;
  36.         }//corner case
  37.         if ((i + 1) == total) {
  38.             counter++;
  39.             cout << "Total abscent students are: " << (int)counter << endl;
  40.             break;
  41.         }
  42.     }
  43.     cout << "Total student attended: " << Grade.size()<<"\n";
  44.     read.close();
  45. }
  46.  
  47. int main() {
  48.     ifstream read,math,checker;
  49.     string s;
  50.     cout << "INTRODUCTION TO PROGRAMMING GRADES \n";
  51.     s = "Grades.txt";
  52.     findCount(read,s);
  53.     cout << "MATHEMATICS FOR COMPUTER SCIENTIST GRADES \n";
  54.     s = "MathGrade.txt";
  55.     findCount(math,s);
  56.     s = "Checker.txt";
  57.     tellgdetector(checker,s);
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement