Question: / * Exercises: 1 . Modify and fix the program.. 2 . Run the program with the following data: 9 0 4 5 7 3
Exercises:
Modify and fix the program..
Run the program with the following data:
Record the output here:
Modify the program so it reads from the file gradfile.txt
instead of from the keyboard.
Run the program with the gradfile.txt
hint: The input file needs to be in the same directory as your c project files.
Replace the cin with an ifstream variable.
Record the output here:
This program will read in a group of trst scores positive integers from to
from the keyboard and then calculate and output the average score
as well as the highest and lowest score. There will be a maximum of scores.
#include
using namespace std;
typedef int GradeType; declares a new data type: an integer array of elements
float findAverageconst GradeType, int; finds average of all grades
int findHighestconst GradeType, int; finds highest of all grades
int findLowestconst GradeType, int; finds lowest of all grades
int main
GradeType grades; the array holding the grades.
int numberOfGrades; the number of grades read.
int pos; index to the array.
float avgOfGrades; contains the average of the grades.
int highestGrade; contains the highest grade.
int lowestGrade; contains the lowest grade.
Read in the values into the array
pos ;
cout "Please input a grade from to or to stop endl;
cin gradespos;
while grades
TODO: Fill in the blanks with the correct index
pos;
cout "Please input a grade from to or to stop endl;
cin grades; TODO: Fill in the blanks with the correct index
numberOfGrades pos; TODO: Fix by assigning the correct value to numberOfGrades
avgOfGrades findAveragegrades numberOfGrades; call to the function to find average
cout endl
"The average of all the grades is avgOfGrades endl;
TODO: assign highestGrade the return value of the findHigehstGrade function
cout "The highest grade is highestGrade endl;
TODO: assign lowestGrade the return value of the findLowestGrade function
TODO: print the lowest grade
float findAverageconst GradeType array, int size
float sum ; holds the sum of all the numbers
for int pos ; pos size; pos
sum arraypos;
return sum size;
int findHighestconst GradeType array, int size
int highest array; holds the highest number
for int pos ; pos size; pos
TODO: if the current number is higher than highest, set highest to the current number
return highest;
int findLowestconst GradeType array, int size
int lowest array; holds the lowest number
TODO: write the loop to find the lowest number
return lowest;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
