fork(5) download
  1. // This program will read in a group of test scores( positive integers from 1 to 100)
  2.  
  3. // from the keyboard and then calculates and outputs the average score
  4.  
  5. // as well as the highest and lowest score. There will be a maximum of 100 scores.
  6.  
  7.  
  8.  
  9.  
  10.  
  11.  
  12.  
  13. #include <iostream>
  14.  
  15. using namespace std;
  16.  
  17.  
  18.  
  19. typedef int GradeType[100]; // declares a new data type:
  20.  
  21. // an integer array of 100 elements
  22.  
  23.  
  24.  
  25.  
  26.  
  27. float findAverage (const GradeType, int); // finds average of all grades
  28.  
  29. int findHighest (const GradeType, int); // finds highest of all grades
  30.  
  31. int findLowest (const GradeType, int); // finds lowest of all grades
  32.  
  33.  
  34.  
  35. int main()
  36.  
  37.  
  38.  
  39. {
  40.  
  41. GradeType grades; // the array holding the grades.
  42.  
  43. int numberOfGrades; // the number of grades read.
  44.  
  45. int pos; // index to the array.
  46.  
  47.  
  48.  
  49. float avgOfGrades; // contains the average of the grades.
  50.  
  51. int highestGrade; // contains the highest grade.
  52.  
  53. int lowestGrade; // contains the lowest grade.
  54.  
  55.  
  56.  
  57. // Read in the values into the array
  58.  
  59.  
  60.  
  61. pos = 0;
  62.  
  63. cout << "Please input a grade from 1 to 100, (or -99 to stop)" << endl;
  64.  
  65. cin >> grades[pos];
  66.  
  67.  
  68.  
  69. while (grades[pos] != -99)
  70.  
  71. {
  72. pos++;
  73. cin >> grades[pos];
  74.  
  75.  
  76. // Fill in the code to read the grades
  77.  
  78.  
  79.  
  80. }
  81.  
  82.  
  83.  
  84. numberOfGrades = (pos + 1); // Fill blank with appropriate identifier
  85.  
  86.  
  87.  
  88. findAverage(grades, numberOfGrades); // call to the function to find average
  89.  
  90.  
  91.  
  92. avgOfGrades = findAverage(grades, numberOfGrades);
  93.  
  94.  
  95.  
  96. cout << endl << "The average of all the grades is " << avgOfGrades << endl;
  97.  
  98.  
  99.  
  100.  
  101.  
  102. findHighest(grades, numberOfGrades);
  103.  
  104.  
  105.  
  106.  
  107.  
  108. cout << endl << "The highest grade is " << highestGrade << endl;
  109.  
  110.  
  111.  
  112.  
  113.  
  114. findLowest(grades, numberOfGrades);
  115.  
  116. lowestGrade = findLowest(grades, numberOfGrades);
  117.  
  118. cout << endl << "The lowest grade is " << lowestGrade << endl;
  119.  
  120.  
  121.  
  122. return 0;
  123.  
  124. }
  125.  
  126.  
  127.  
  128. //****************************************************************************
  129.  
  130. // findAverage
  131.  
  132. //
  133.  
  134. // task: This function receives an array of integers and its size.
  135.  
  136. // It finds and returns the average of the numbers in the array
  137.  
  138. // data in: array of floating point numbers
  139.  
  140. // data returned: avarage of the numbers in the array
  141.  
  142. //
  143.  
  144. //****************************************************************************
  145.  
  146.  
  147.  
  148. float findAverage (const GradeType array, int size)
  149.  
  150.  
  151.  
  152. {
  153.  
  154.  
  155.  
  156. float sum = 0; // holds the sum of all the numbers
  157.  
  158.  
  159.  
  160. for (int pos = 0; pos < size; pos++)
  161. {
  162.  
  163.  
  164. sum = sum + array[pos];
  165.  
  166.  
  167.  
  168. {
  169.  
  170.  
  171.  
  172.  
  173. return (sum / size); //returns the average
  174.  
  175.  
  176.  
  177. }
  178.  
  179.  
  180.  
  181. //****************************************************************************
  182.  
  183. // findHighest
  184.  
  185. //
  186.  
  187. // task: This function receives an array of integers and its size.
  188.  
  189. // It finds and returns the highest value of the numbers in
  190.  
  191. // the array
  192.  
  193. // data in: array of floating point numbers
  194.  
  195. // data returned: highest value of the numbers in the array
  196.  
  197. //
  198.  
  199. //****************************************************************************
  200.  
  201.  
  202.  
  203. int findHighest (const GradeType array, int size)
  204.  
  205.  
  206.  
  207. {
  208.  
  209.  
  210. int count;
  211. int highest;
  212. highest = array[0];
  213.  
  214. for (count = 0; count < size; count++)
  215. {
  216. if(array[count] > highest)
  217. {
  218. highest = array[count];
  219. }
  220. }
  221.  
  222. return highest;
  223.  
  224. }
  225.  
  226.  
  227.  
  228.  
  229.  
  230.  
  231. //****************************************************************************
  232.  
  233. // findLowest
  234.  
  235. //
  236.  
  237. // task: This function receives an array of integers and its size.
  238.  
  239. // It finds and returns the lowest value of the numbers in
  240.  
  241. // the array
  242.  
  243. // data in: array of floating point numbers
  244.  
  245. // data returned: lowest value of the numbers in the array
  246.  
  247. //
  248.  
  249. //****************************************************************************
  250.  
  251.  
  252.  
  253. int findLowest (const GradeType array, int size)
  254.  
  255.  
  256.  
  257. {
  258.  
  259. int count;
  260. int lowest;
  261. lowest = array[0];
  262.  
  263. for(count = 0; count < size; count++)
  264. {
  265. if(lowest < array[count])
  266.  
  267. lowest = array[count];
  268.  
  269. }
  270.  
  271. return lowest;
  272.  
  273.  
  274. }
  275.  
  276.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘float findAverage(const int*, int)’:
prog.cpp:207:1: error: a function-definition is not allowed here before ‘{’ token
prog.cpp:274:1: error: expected ‘}’ at end of input
prog.cpp:274:1: error: expected ‘}’ at end of input
prog.cpp:274:1: warning: control reaches end of non-void function [-Wreturn-type]
stdout
Standard output is empty