Question
Write a C++ program, named average.cc , that reads the values from a data file, display the values, and computes and displays the largest, smallest,
Write a C++ program, named "average.cc", that reads the values from a data file, display the values, and computes and displays the largest, smallest, and the average of these values:
First, create a director "CLA5" under the "CLA" directory. Use "cd" command to change directory to the "CLA5" directory.
Next, copy the two data files into the "CLA5" directory using the command:
$cp $PUB/lab5-*.dat .
Use scite to write the program named average.cc.
$scite average.cc &
Program Requirement:
You need to write 3 user defined functions for this program: Develop each function one by one. That is to write one function, compile and run the program with that function. If successful, move on to add the 2nd function, compile and run that program. If both functions work correct, move on to add the 3rd function. Do not try to implement all the functions at once.
1-Write a function named "OpenFile". This function is responsible for:
Prompt the user to enter the data file name,
Open the data file,
Use assert function to verify that the input file is opened properly,
return the input file stream through reference parameter.
2-Write a second function named "ComputeStatistics". This function is responsbile for:
Read data one by one from the data file (remember: file streams are always passed to function as reference parameters),
Display the values as they are read in,
Count the number of values read,
Compute the statistics: smallest, largest, and average,
Return all the information (count and all the statistics) back to the calling function through reference parameters.
Question: Should the parameters corresponding to the "count", "smallest", "largest", and "average" be passed as value parameters or reference parameters?
3- Write a third function named "DisplayResults". This function is responsible for:
Display the results as shown in the example program runs,
Question: Should the parameters to this function be value parameters or reference parameters?
As you are writing these three functions, think:
What should be the type of this function? void or value returning?
What are the parameters of this function?
Should each parameter be passed by value? or by reference?
Sample run l Please enter the data file name ab5-1 data Assertion failed input Sample run 2 Please enter the data file name l ab5-1 data The values read are: 30 40 25 89 103 45 89 34 15 63 Total 12 numbers The largest number is 103 and the smallest number is 40 The average of these numbers is 42.9
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started