Guest User

Arkham Knight Elakiri C++

a guest
Mar 31st, 2014
17
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.10 KB | None | 0 0
  1. //Coded BY Arkham Knight ELAKIRI /2014/03/31
  2.  
  3. #include <iostream>
  4. #include <iomanip>
  5.  
  6. using namespace std;
  7.  
  8. /*
  9. 1. View all studentdata
  10. 2. View a student’s data using the ID
  11. 3. Show the highest and the lowest final marks
  12. */
  13.  
  14. void allStudentData();
  15. void idStudent();
  16. void showHighLowMarks();
  17. void menu();
  18.  
  19. int main()
  20. {
  21.     menu();
  22. }
  23.  
  24. int sR[3][5];
  25. void menu()
  26. {
  27.     //|StudentID 0 | TMA1 1| TMA2 2| BCAT 3| Final 4
  28.     //student column names
  29.     sR[0][0] = 0;
  30.     sR[0][1] = 1;
  31.     sR[0][2] = 2;
  32.     sR[0][3] = 3;
  33.     sR[0][4] = 4;
  34.  
  35.     //student One
  36.     sR[1][0] = 1232;
  37.     sR[1][1] = 10;
  38.     sR[1][2] = 23;
  39.     sR[1][3] = 45;
  40.     sR[1][4] = 56;//final mark
  41.  
  42.     //student two
  43.     sR[2][0] = 2343;
  44.     sR[2][1] = 45;
  45.     sR[2][2] = 43;
  46.     sR[2][3] = 24;
  47.     sR[2][4] = 78;//final mark
  48.  
  49.  
  50.     cout << "----------  Menu -----------" << endl;
  51.     cout << "" << endl;
  52.     cout << "1. View all studentdata" << endl;
  53.     cout << "2. View a student’s data using the ID" << endl;
  54.     cout << "3. Show the highest and the lowest final marks " << endl;
  55.     cout << "" << endl;
  56.     cout << "Type a desired value from the given menu and press the ENTER key to proceed" << endl;
  57.     int givenVal = 0;
  58.     cin >> givenVal;
  59.     cin.ignore();
  60.  
  61.     switch (givenVal)
  62.     {
  63.     case 1:
  64.         allStudentData();
  65.         break;
  66.     case 2:
  67.          idStudent();
  68.         break;
  69.     case 3:
  70.          showHighLowMarks();
  71.         break;
  72.     default:
  73.         cout << "an Error is occurred" << endl;
  74.         cin.clear();//clear the input buffer
  75.         menu();
  76.         break;
  77.     }
  78.     cin.get();
  79. }
  80.  
  81. void allStudentData()
  82. {
  83.     cout << " ";  for(int i=0;i<40;i++){ cout << "_";}  cout << endl;
  84.     cout << "|" << setw(11) << "StudentID 0" << "|" << setw(6) << "TMA1 1" << "|" <<  setw(6) << "TMA2 2" << "|" << setw(6) << "BCAT 3" << "|" <<  setw(7) << "Final 4|" << endl;
  85.     cout << "|" << setw(11) << sR[1][0] << "|" <<  setw(6) << sR[1][1] << "|" <<  setw(6) << sR[1][2] << "|" <<  setw(6) << sR[1][3] << "|" << setw(7) << sR[1][4] << "|" << endl;
  86.     cout << "|" << setw(11) << sR[2][0] << "|" <<  setw(6) << sR[2][1] << "|" <<  setw(6) << sR[2][2] << "|" <<  setw(6) << sR[2][3] << "|" << setw(7) << sR[2][4] << "|" << endl;
  87.     cout << " ";  for(int i=0;i<40;i++){ cout << "_";}  cout << endl;
  88. }
  89.  
  90. void idStudent()
  91. {
  92.     cout << "Id the of the student to see" << endl;
  93.     int stdID;
  94.     cin >> stdID;
  95.     cin.ignore();
  96.     for(int i=0;i<3;i++)
  97.     {
  98.         for(int j=0;j<5;j++)
  99.         {
  100.             if(sR[i][j] == stdID)
  101.             {
  102.                 cout << "Student ID.is :" << sR[i][j] << endl;
  103.                 cout << "TMA1.......is :" << sR[i][j+1] << endl;
  104.                 cout << "TMA2.......is :" << sR[i][j+1] << endl;
  105.                 cout << "BCAT.......is :" << sR[i][j+2] << endl;
  106.                 cout << "Final......is :" << sR[i][j+4] << endl;
  107.                 break;
  108.             }
  109.         }
  110.     }
  111.    
  112. }
  113.  
  114. void showHighLowMarks()
  115. {
  116.     int fM[2];//for receiving final marks
  117.     int k=0;
  118.  
  119.     for(int i=1;i<3;i++)
  120.     {
  121.         for(int j=0;j<5;j++)
  122.         {
  123.             if(j==4)//final mark value
  124.             {
  125.                 fM[k] = sR[i][j];
  126.                 k++;
  127.             }
  128.         }
  129.     }
  130.  
  131.     //sorting
  132.     for(int i=0;i<1;i++)
  133.     {
  134.         int temp = fM[i+1];
  135.         if(temp < fM[i])
  136.         {
  137.             fM[i+1] = fM[i];
  138.             fM[i] = temp;
  139.         }
  140.     }
  141.  
  142.     cout << "The Highest value is..." << fM[1]  << endl;
  143.     cout << "The Lowest value is...." << fM[0]  << endl;
  144. }
Advertisement
Add Comment
Please, Sign In to add comment