Advertisement
Guest User

Untitled

a guest
Apr 25th, 2018
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4. using namespace std;
  5. const int MAX = 600;
  6.  
  7. double average(int sum, int quantity);
  8.  
  9. int main() {
  10. string name[MAX];
  11. int grade[MAX];
  12. int quantity = 0;
  13. int x = 0;
  14. double avg = 0;
  15. int sum = 0;
  16.  
  17. ifstream inFS;
  18. int inFile = 0; // Data value from file
  19. inFS.open("indata3.txt");
  20. if (!inFS.is_open()) {
  21. cout << "Could not open file myfile.txt." << endl;
  22. return 1; // 1 indicates error
  23. }
  24.  
  25. while (!inFS.eof())
  26. {
  27. cin >> name[x] >> grade[x];
  28. x++;
  29. }
  30.  
  31. cout << "Enter quantity of grades to be processed ("<< x<< "): " << endl;
  32. cin >> quantity;
  33.  
  34. for (x = 0; x < quantity; x++)
  35. {
  36. sum = sum + grade[x];
  37. }
  38.  
  39. avg = average(sum, quantity);
  40. cout << "Average grade: " << avg;
  41.  
  42. for (x = 0; x<quantity; x++) {
  43. cout << "Name" << name[x] << " Grade: " << grade[x] << "Comments: ";
  44. if (grade[x]<avg) {
  45. cout << " below average" << endl;
  46. }
  47. else if (grade[x] > avg) {
  48. cout << " above average" << endl;
  49. }
  50. else {
  51. cout << " average" << endl;
  52. }
  53. }
  54.  
  55.  
  56. return 0;
  57. }
  58.  
  59. double average(int sum, int quantity)
  60. {
  61. int avg = 0;
  62. avg = sum / quantity;
  63. return avg;
  64.  
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement