aprsc7

Pass row by row array

Nov 17th, 2019 (edited)
273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.99 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. void readData();
  5. int calTotMarks(int[]);
  6. void display();
  7.  
  8. const int STUDENTS = 5;
  9.  
  10. int studMarks[STUDENTS][5], totMarks[STUDENTS];
  11.  
  12. int main()
  13. {
  14.     readData();
  15.     for(int i=0; i<STUDENTS; i++) //pass row by row array
  16.         totMarks[i] = calTotMarks( studMarks[i] );
  17.     display();
  18. }
  19.  
  20. void readData()
  21. {
  22.     cout << "Enter 5 marks for each student:\n";
  23.     for(int i=0; i<STUDENTS; i++)
  24.     {
  25.         cout << "Student " << i+1 << " : ";
  26.         for(int j=0; j<5; j++)
  27.             cin >> studMarks[i][j];
  28.     }
  29. }
  30.  
  31. int calTotMarks(int subject[])
  32. {
  33.     int total=0;
  34.     for(int i=0; i<5; i++)
  35.         total += subject[i];
  36.     return total;
  37. }
  38.  
  39. void display()
  40. {
  41.     cout << "\nStudent\tMark1\tMark2\tMark3\tMark4\tMark5\tTotalMarks\n";
  42.     for(int i=0; i<STUDENTS; i++)
  43.     {
  44.         cout << i+1 << "\t" ;
  45.         for(int j=0; j<5; j++)
  46.             cout  << studMarks[i][j] << "\t";
  47.         cout << totMarks[i] << endl;
  48.     }
  49. }
Add Comment
Please, Sign In to add comment