write a program that reads grades in the integer range 1 – 100 from a file, writ
ID: 3764109 • Letter: W
Question
write a program that reads grades in the integer range 1 – 100 from a file, writes out the grades, computes their average, and finds out how many grades are above average and how many grades are below average. All output should be written to the console window. The first number in the text document is the number of grades within the file, and the file will only have integers.
Requirements: Write a method that calculates and then returns the average of the array of information.
Write a method that determines how many are above the average and returns that number.
Write a method that determines how many are below the average and returns that number.
The main method should handle output (Methods to calculate the average and how many grades are above and below the average should return values, and not print out anything).
Bonus: Catch the error and output to the console that the file name does not exist. That means if the file doesn’t exist, instead of getting an error and the program ending, your program outputs the message that the file doesn’t exist.
Explanation / Answer
#include #include #include #include using namespace std; int main() { fstream infile("grades.txt",ios::in); if(!infile){cerrRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.