Question
Please read carefully: Write a C++ program which can be used to perform an analysis of the test score data for test 1. You will
Please read carefully:
Write a C++ program which can be used to perform an analysis of the test score data for test 1. You will have to read each score from an input file and store the score in an array. We will use an array of size 45, which is larger than the total number of students in the class. Then you will sort the scores from highest to lowest and finally you will perform an analysis on the sorted array. For the output of this assignment, your program will produce a bar chart of the test scores, where each score recorded for the test is followed by asterisks one asterisk for each student who made that score. We will ignore scores that no student got (such as 5).
Example Input Consider the following example input list of 11 scores:
92
78
92
84
96
75
100
75
75
81
84
Example output For the above input, your program output should look like this, where the total number of asterisks add up to 11:
100: *
96: *
92: **
84: **
81: *
78: *
75: ***
Notice that some scores in the output, such as 97, do not appear since there were no example input scores of 97.
Following the above output I want to know the average score and the median score of the input scores. Here are the relevant formulas:
Average grade = sum of all scores total number of tests.
Median grade = { the middle score for an odd number of tests
{the average of the 2 middle scores for an even number of tests
Reading the input from a file:
Reading from a file in C++ is just like reading data from the keyboard using cin. The only difference is that instead of you entering the data during program execution, you enter the data into a file using an editor and then your program reads your prepared data from the file. If you make an error in the input data, then you just correct the data file. If you make an error while typing from the keyboard or miss a line, then you have to start over. So if you have a lot of data, it is much easier to put it in a file and let the program read from the file.
The steps to Follow to Read From an Input File:
To read from a file, you first must include two more libraries at the top of your file:
#include
#include
#include
using namespace std;
Then you declare an ifstream object, which is described in the included library:
ifstream inStream; // an input object which "knows" how to read from a file
Then you use the inStream object to open the file you wish to read from:
inStream.open("tests.scores");
Next you test to make sure the file is opened. (You might have mistyped the file name.):
if (inStream.fail()){
cerr << "Input file opening failed!" << endl;
exit(1); // quit the program if the file failed to be opened
}
Reading from a file is like reading input from the keyboard until the user indicates he or she wants to quit, except that we reach the end of the file. There is an end of file test for this which we can use to make a read loop:
int next;
inStream >> next;
while (!infile.eof()){
cout << next; // cout is used just as an example
inStream >> next;
}
After we finish reading from a file,we should close it:
inStream.close();
Requirements:
You will need at least two functions in your programs in addition to main:
int read data( int scores[ ], ifstream& inputStream);
void analyze(int scores[ ], int number of scores);
Add other functions if they are needed,such as the selection sort function of Display 7.12 (but modified to sort in decreasing order).
Use a const declaration for the array size, but do not use any other global variables.
Carefully choose self-descriptive variable names to help document your program.
Use blank lines as separators, if necessary, to help set off blocks of statements which should be logically grouped together.
Do not forget the average and median computations.
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