Question: C++ program to analysis student exm scores. In class we've discussed using arrays to store exm scores for a class, and writing functions to input
C++ program to analysis student exm scores.
In class we've discussed using arrays to store exm scores for a class, and writing functions to input the data, compute the median, etc. And in lab this week you wrote a function to compute standard deviation. We're going to put all these pieces together to write a program that analyzes a set of 3 exms across a semester.
The input file will consist of 4 columns: last 4 digits of UIN, exm 1, exm 2, and exm 3 . The end of the file will be marked by -1 -1 -1 -1. Here's an example (this is the first test case):
1234 80 81 82 2231 90 89 88 2561 100 12 12 3009 100 70 79 3754 60 59 70 4101 50 89 100 4202 10 20 30 5981 18 20 20 6299 30 30 28 7890 88 87 88 8171 100 80 90 9906 59 69 79 -1 -1 -1 -1
The program is going to compute and output the number of students, the average of each exm, the median of each exm, the population standard deviation of each exm, and a histogram (A's, B's, C's, D's, F's) of each exm. Here's the output for the above input sequence:
** Exaaam Analysis ** Filename: exaams-12.txt Num Students: 12 ** Averages: Exaam 1: 65.4167 Exaam 2: 58.8333 Exaam 3: 63.8333 ** Medians: Exaam 1: 70 Exaam 2: 69.5 Exaam 3: 79 ** Standard Deviations: Exaam 1: 31.354 Exaam 2: 28.609 Exaam 3: 30.3118 ** Histograms: A,B,C,D,F Exaam 1: 4, 2, 0, 1, 5 Exaam 2: 0, 5, 1, 1, 5 Exaam 3: 2, 3, 3, 0, 4 ** Done **
A partially-designed program is being provided --- you need to modify both files ("main.cpp" and "functions.cpp") in order to complete the program. There is a function defined in "functions.cpp" for each of the above computations, many of which we have discussed in class / lab. Modify "main.cpp" to call these functions and orchestrate a solution.
The tests cases involve 3 input files: "exaams-12.txt", "cs123.txt", and "cs456.txt". The zybook system does not show you the contents of the input files, but the files have been made available on the course web page until "Projects", then "project08-inputfiles". Here's a link to that folder.
BEFORE YOU START
We need to avoid a bug in some browsers. Above the editor pane you'll see the text "Current file: main.cpp", with a little drop-down arrow to the right. Click the drop-down and select "functions.cpp". Then click the link "Load default template..." --- this will ensure the file is properly loaded for you to edit; you only need to do this once.
NOTES
You'll need 3 arrays, one for each exaam. These are already declared for you in main(); assume at most 1,000 students.
Even though you have 3 arrays, you only need 1 of each function. Exaample: to compute the average of exm 1, call the ComputeAvg() function and pass it array exaam1. To compute the average of exm 2, call the same function, just pass array exam2instead.
Recall that in order to compute the median, the data must be sorted; a Sort() function is provided, just call from main() before you call ComputeMedian().
In this assignment exm scores are integers, so notice the array parameter to the StandardDev() function has been changed from double to int. That's the only change, the body of the function remains the same (so you can reuse your answer from lab).
The Histogram() function is a new one. The function has no return value --- void -- because C++ does not allow a function to return an array. Instead, main() needs to pass Histogram() an array parameter called hist, and the function "returns" the histogram data by storing into the hist parameter. The hist array is an integer array of size 5.
/*main.cpp*/
// // Exaam analysis program. // // <
#include
using namespace std;
// // function declarations: // int InputData(string filename, int exam1[], int exam2[], int exam3[]); void Sort(int A[], int N); double ComputeAvg(int A[], int N); double ComputeMedian(int A[], int N); double StandardDev(int A[], int N); void Histogram(int A[], int N, int histogram[]);
// // main: // int main() { int exam1[1000]; int exam2[1000]; int exam3[1000]; int N; string filename;
// // input filename from keyboard: // cin >> filename;
// // Input data and perform analysis: // cout << "** Exaam Analysis **" << endl; cout << "Filename: " << filename << endl;
N = InputData(filename, exam1, exam2, exam3);
cout << "Num Students: " << N << endl;
cout << "** Averages:" << endl;
cout << "** Medians:" << endl;
cout << "** Standard Deviations:" << endl;
cout << "** Histograms: A,B,C,D,F" << endl;
cout << "** Done **" << endl;
return 0; }
-------------------------------------------------------------------------------
/*functions.cpp*/
// // Analysis functions: average, median, sort, histogram, etc. // // <
#include
using namespace std;
// // InputData() // // Given an input file of the following format: // // uin exam1 exam2 exam3 // uin exam1 exam2 exam3 // . // . // . // -1 -1 -1 -1 // // Inputs the data and stores the exam1 scores into array exam1, // exam2 scores into array exam2, and exam3 scores into array // exam3. The uins are discarded. The function returns the # // of students N that were input and stored into the arrays. // int InputData(string filename, int exam1[], int exam2[], int exam3[]) { // // TODO: //
return -1; }
// // Sort() // // Sorts the given array of N integers into ascending order. // Uses selection sort, which is fine for small values of N, // N < 10,000. // // If you want to see different sorts "in action", here's a // great web site for algorithm visualizations: // http://www.sorting-algorithms.com/ // void Sort(int A[], int N) { int indexOfMin;
// // Selection sort: select the min element, move to front, // repeat. // for (int i = 0; i < N - 1; i=i+1) { // // find the min in range i..N, and then move min element // to the front of range: // indexOfMin = i; // assume the first is the min:
for (int j = i + 1; j < N; j=j+1) // look for a smaller one: { if (A[j] < A[indexOfMin]) { indexOfMin = j; } }
// // we have index of min element, swap with first element so // that we have sorted one element to the front: // if (indexOfMin != i) // swap: { int T = A[i]; A[i] = A[indexOfMin]; A[indexOfMin] = T; } }//for
// // A is now sorted: // return; }
// // ComputeAvg() // // Returns the average of N integers in array A; it // is assumed that N > 0. // double ComputeAvg(int A[], int N) { // // TODO: //
return -1; }
// // ComputeMedian() // // Given an array A of N integers in sorted order, returns // the median value. If N is even, the median is the avg // of the middle values. // double ComputeMedian(int A[], int N) { // // TODO: //
return -1; }
// // StandardDev() // // Given an array A containing N real numbers, computes and returns // the population standard deviation. The function should not change // the contents of the array. // double StandardDev(int A[], int N) { // // TODO: //
return -1; }
// // Histogram() // // Given an array of N scores, computes the # of A's, B's, // C's, D's, and F's. Definition of letter grades follows // the standard 90-80-70-60: // // A: 90..100 // B: 80..89 // C: 70..79 // D: 60..69 // F: 0..59 // // The histogram is returned via the 3rd parameter "hist". // This parameter is assumed to be of size 5. The # of A's // will be hist[0], B's [1], C's [2], D's [3], and F's [4]. // void Histogram(int A[], int N, int hist[]) { // // TODO: //
return; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
