fork download
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <fstream>
  4. #include <cstdlib>
  5. #define SIZE 28
  6. using namespace std;
  7.  
  8.  
  9. int ArrayFromFile (int A[], int Q[])
  10. {
  11. int C = 0;
  12. ifstream inFile;
  13. inFile.open("grades.txt");
  14. while(C<Q &&!inFile.eof())
  15. {
  16. inFile >> A[C];
  17. C+=1;
  18. }
  19. inFile.close();
  20. if (C!=Q) cout << "Quanity of data file doesn't match array size";
  21. return C;
  22. }
  23.  
  24.  
  25. void sortArray (int A[], int Q)
  26. {
  27. int P, PASS, T;
  28. for (PASS=1; PASS<Q; PASS++)
  29. for (P=0;P<=-1-PASS;P++)
  30. if (A[P]>A[P+1]) { T=A[P]; A[P]=A[P+1]; A[P+1]=T;}
  31. }
  32.  
  33. void stats ( int A[], int Q[], int &MIN, int &MAX, float &AVG)
  34. {
  35. int TOTAL=0;
  36. int I;
  37. int COUNT=0;
  38. int T;
  39.  
  40. MIN = 100;
  41. MAX = 0;
  42. for (I=0; I<Q; I++)
  43. {
  44. if (A[T]>=Q && A[T]<=100)
  45. {
  46. COUNT+=1;
  47. TOTAL+=A[I];
  48. if (A[I]<MIN) MIN=A[I];
  49. if (A[I]<MAX) MAX=A[I];
  50. }
  51. }
  52. AVG=static_cast<float>(TOTAL/COUNT);
  53. }
  54.  
  55. void displayCatergory (int A[], int Q[], int &MIN, int &MAX, float &AVG)
  56. {
  57. int I;
  58. int QI=0, QU=0, QS=0, QO=0;
  59. cout << "Student\n\n";
  60. cout << "Score | Category\n";
  61. cout << "-------+----------\n";
  62. for (I=0; I<Q[SIZE]; I++)
  63. {
  64. cout << setw(8) << A[I] << " | ";
  65. if (A[I]<0 || A[I]>100) {QI++; cout << "Invalid";}
  66. else if (A[I]<60) { QU++; cout << "Unstatisfactory";}
  67. else if (A[I]<90) { QU++; cout << "statisfactory";}
  68. else {QO++; cout << "Outstanding";}
  69. cout << endl;
  70. }
  71. cout << "\nStatistics:\n\n";
  72. cout << setw(8) << Q << " | Scores Read From File" << endl;
  73. cout << setw(8) << QO << " | Outstanding Scores (90-100)" << endl;
  74. cout << setw(8) << QS << " | Statisfactory Scores (60-89)" << endl;
  75. cout << setw(8) << QU << " | Unstatisfactory Scores (0-59)" << endl;
  76. cout << setw(8) << QI << " | Invalid Scores (Under 0 or Over 100)" << endl;
  77. cout << setw(8) << setprecision(2) << fixed << AVG << " | Average Score" << endl;
  78. cout << setw(8) << MAX << " | Highest Score" << endl;
  79. cout << setw(8) << MIN << " | Lowest Score" << endl;
  80. }
  81. int main (void)
  82. {
  83. cout << "Student\n";
  84. cout << "4/14/15\ class example\n";
  85. cout << "Test Score Summary\n";
  86.  
  87. int SCORES;
  88. int QTY[SIZE];
  89. int MIN, MAX;
  90. float AVG;
  91.  
  92. QTY = ArrayFromFile(SCORES, QTY);
  93. sortArray(SCORES, QTY);
  94. stats(SCORES, QTY, MIN, MAX, AVG);
  95. displayCatergory(SCORES, QTY, MIN, MAX, AVG);
  96. return 0;
  97. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function 'int ArrayFromFile(int*, int*)':
prog.cpp:14:10: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
  while(C<Q &&!inFile.eof()) 
          ^
prog.cpp:20:9: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
  if (C!=Q) cout << "Quanity of data file doesn't match array size";
         ^
prog.cpp: In function 'void stats(int*, int*, int&, int&, float&)':
prog.cpp:42:14: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
  for (I=0; I<Q; I++)
              ^
prog.cpp:44:13: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
   if (A[T]>=Q && A[T]<=100)
             ^
prog.cpp: In function 'int main()':
prog.cpp:84:10: warning: unknown escape sequence: '\040'
  cout << "4/14/15\ class example\n";
          ^
prog.cpp:92:32: error: invalid conversion from 'int' to 'int*' [-fpermissive]
 QTY = ArrayFromFile(SCORES, QTY);
                                ^
prog.cpp:9:5: note: initializing argument 1 of 'int ArrayFromFile(int*, int*)'
 int ArrayFromFile (int A[], int Q[])
     ^
prog.cpp:92:5: error: incompatible types in assignment of 'int' to 'int [28]'
 QTY = ArrayFromFile(SCORES, QTY);
     ^
prog.cpp:93:22: error: invalid conversion from 'int' to 'int*' [-fpermissive]
 sortArray(SCORES, QTY);
                      ^
prog.cpp:25:6: note: initializing argument 1 of 'void sortArray(int*, int)'
 void sortArray (int A[], int Q)
      ^
prog.cpp:93:22: error: invalid conversion from 'int*' to 'int' [-fpermissive]
 sortArray(SCORES, QTY);
                      ^
prog.cpp:25:6: note: initializing argument 2 of 'void sortArray(int*, int)'
 void sortArray (int A[], int Q)
      ^
prog.cpp:94:33: error: invalid conversion from 'int' to 'int*' [-fpermissive]
 stats(SCORES, QTY, MIN, MAX, AVG);
                                 ^
prog.cpp:33:6: note: initializing argument 1 of 'void stats(int*, int*, int&, int&, float&)'
 void stats ( int A[], int Q[], int &MIN, int &MAX, float &AVG)
      ^
prog.cpp:95:44: error: invalid conversion from 'int' to 'int*' [-fpermissive]
 displayCatergory(SCORES, QTY, MIN, MAX, AVG);
                                            ^
prog.cpp:55:6: note: initializing argument 1 of 'void displayCatergory(int*, int*, int&, int&, float&)'
 void displayCatergory (int A[], int Q[], int &MIN, int &MAX, float &AVG)
      ^
stdout
Standard output is empty