fork download
  1. #include <iostream>
  2. #include <iomanip>
  3.  
  4. using namespace std;
  5.  
  6. const int NUM_TESTS = 4, STU_NUM = 5, STU_LENGTH = 20;
  7.  
  8. void getNames(char [][STU_LENGTH]);
  9. void getScores(char [][STU_LENGTH], char [], double [][NUM_TESTS]);
  10. void calcAverages(double tests[][NUM_TESTS]);
  11. //void display();
  12.  
  13.  
  14.  
  15.  
  16.  
  17. int main()
  18. {
  19. char names[STU_NUM][STU_LENGTH];
  20. double tests[STU_NUM][NUM_TESTS];
  21. char gradeLetter[STU_NUM];
  22.  
  23. getNames(names);
  24. getScores(names,gradeLetter,tests);
  25. calcAverages(tests);
  26.  
  27. cout << "\n";
  28. system("PAUSE");
  29. return 0;
  30.  
  31. }
  32.  
  33. // Function that will ask for and store names
  34.  
  35. void getNames(char names[][STU_LENGTH])
  36. {
  37. for(int i=0;i < STU_NUM;i++)
  38. {
  39. cout << "Please enter student " << i+1 << " name : ";
  40. cin.getline(names[i],STU_LENGTH);
  41. }
  42. }
  43.  
  44.  
  45. // Function that will ask for and store scores for each student
  46.  
  47. void getScores(char names[][STU_LENGTH], char gradeLetter[], double tests[][NUM_TESTS])
  48. {
  49.  
  50.  
  51. for(int i = 0; i < STU_NUM; i++)
  52. {
  53.  
  54. for(int j = 0; j < NUM_TESTS; j++)
  55. {
  56. cout << "Please enter " << names[i] << " grades";
  57. cout << (j+1) << ": ";
  58. cin >> tests[i][j];
  59. }
  60.  
  61. }
  62.  
  63. }
  64.  
  65.  
  66. void calcAverages(double tests[][NUM_TESTS])
  67. {
  68. double averages[STU_NUM];
  69. double tempSum[STU_NUM];
  70.  
  71.  
  72. cout << "The test scores are: ";
  73.  
  74. for(int i=0;i < STU_NUM;i++)
  75. {
  76. for(int j=0;j < NUM_TESTS;j++)
  77. {
  78. tempSum[i] += tests[i][j];
  79. cout << tempSum[i] <<" ";
  80. }
  81. }
  82.  
  83. cout << "The sums are: ";
  84. for(int p=0;p < STU_NUM;p++)
  85. {
  86. cout << tempSum[p] << " ";
  87. }
  88.  
  89. }
Success #stdin #stdout #stderr 0s 4340KB
stdin
John Adam
Raymond Woo
Rick Smith
Ray Bartlett
Mary Russell

3
93
91
100

3
65
68
63

3
50
58
53

3
62
64
69

3
93
90
98
stdout
Please enter student 1 name : Please enter student 2 name : Please enter student 3 name : Please enter student 4 name : Please enter student 5 name : Please enter John Adam grades1: Please enter John Adam grades2: Please enter John Adam grades3: Please enter John Adam grades4: Please enter Raymond Woo grades1: Please enter Raymond Woo grades2: Please enter Raymond Woo grades3: Please enter Raymond Woo grades4: Please enter Rick Smith grades1: Please enter Rick Smith grades2: Please enter Rick Smith grades3: Please enter Rick Smith grades4: Please enter Ray Bartlett grades1: Please enter Ray Bartlett grades2: Please enter Ray Bartlett grades3: Please enter Ray Bartlett grades4: Please enter Mary Russell grades1: Please enter Mary Russell grades2: Please enter Mary Russell grades3: Please enter Mary Russell grades4: The test scores are: 3  96  187  287  3  68  136  199  3  53  111  164  3  65  129  198  3  96  186  284  The sums are: 287  199  164  198  284  
stderr
sh: 1: PAUSE: not found