userxbw

Students grades without 2d arrays C++

Sep 2nd, 2022 (edited)
1,651
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.44 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. // amount of students
  6. #define ROW 5
  7. // amount of subjects
  8. #define COL 4
  9.  
  10. char getGrade(int x);
  11.  
  12. int main(){
  13.  
  14. string student[ROW]={};
  15. /*
  16. each student
  17. has a seperate
  18. array for total
  19. amount of subjects
  20.  
  21. requirements is 5
  22. students
  23. */
  24. double s1[COL]={};
  25. double s2[COL]={};
  26. double s3[COL]={};
  27. double s4[COL]={};
  28. double s5[COL]={};
  29. char grades[COL]={};
  30. double percent,t1,t2,t3,t4,t5;
  31. int s=0,c=0,average;
  32.  
  33. for(int d=0;d<ROW;d++){
  34. cout<<"\nENTER <student> NAME\n";
  35. cin>>student[d];
  36. if(s==COL)s=0; // reset
  37. c=COL;
  38.     while(s<COL){
  39.     cout<<(c--)<<" Enter grade percent\n";
  40.     cin>>percent;
  41.         if(percent<0||percent>100)
  42.             {cout<<"ERROR ENTER PERCENT AGAIN!!\n";
  43.             c+=1; //reset count
  44.             continue;
  45.         }
  46.         switch(d){
  47.             case 0:s1[s]=percent;break;
  48.             case 1:s2[s]=percent;break;
  49.             case 2:s3[s]=percent;break;
  50.             case 3:s4[s]=percent;break;
  51.             case 4:s5[s]=percent;break;
  52.         }//end switch
  53.         s++;
  54.     } //while
  55.  } // for
  56. cout<<endl<<endl<<endl;
  57. //create grades
  58. for(int i=0;i<ROW;i++){
  59.     for(int p=0;p<COL;p++){
  60.         switch(i){
  61.             case 0:(average)=((round(t1+=s1[p]))/COL);break;
  62.             case 1:(average)=((round(t2+=s2[p]))/COL);break;
  63.             case 2:(average)=((round(t3+=s3[p]))/COL);break;
  64.             case 3:(average)=((round(t4+=s4[p]))/COL);break;
  65.             case 4:(average)=((round(t5+=s5[p]))/COL);break;
  66.         }//end switch
  67.     } //.end inner fot
  68.        grades[i]=getGrade(average);
  69. /* Could just call the grades() function in cout
  70.    but the requirements it to store the grade in
  71.    an char array
  72.    */
  73.     cout<<(i+1)<<". "<<student[i]<<" Average is "<<average<<"\n"
  74.     "This student recived an [[ "<<grades[i]<<" ]] to show "
  75.     "the amount of effort\nput in for the year\n\n";
  76.  
  77. } // end outer for
  78.  
  79. return 0;
  80. }
  81.  
  82. char getGrade(int x){
  83.  
  84. #ifdef __linux__
  85. // for GCC
  86. cout<<"linux\n";
  87.     switch(x){
  88.         case 80 ... 100:return 'A';
  89.         case 70 ... 79:return 'B';
  90.         case 60 ... 69:return 'C';
  91.         case 50 ... 59:return 'D';
  92.         case 40 ... 49:return 'E';
  93.     }
  94. #elif _WIN32
  95. cout<<"windoz\n";
  96.  
  97. //  METHOID FOR WINDOWS
  98.  
  99. if(x>=80&&x<=100) return 'A';
  100. else if(x>=70&&x<=79)return 'B';
  101. else if(x>=60&&x<=69)return 'C';
  102. else if(x>=50&&x<=59)return 'D';
  103. else if(x>=40&&x<=49)return 'E';
  104. #endif
  105.  
  106. return 'F';
  107. }
  108.  
  109.  
Advertisement
Add Comment
Please, Sign In to add comment