/****************************************************************************** Lab Exercise #6, Part C Assumptions about the data: The data set will contain no more than 10 items The student name will contain no more than 20 characters The exam scores will range from 0 to 100 Note: Functions "process" and "mean" are not currently implemented. ******************************************************************************/ using namespace std; #include #include struct Student { char Name[20]; int Score; }; void read( Student [], int, int& ); void process( const Student [], int ); double mean( const Student [], int ); /*----------------------------------------------------------------------------- Name: main Purpose: Control the overall operation of the program Output: Appropriate error messages -----------------------------------------------------------------------------*/ int main() { const int Size = 10; // The upper bound on the number of students int Num; // The actual number of students Student List[Size]; // The list of student names and exam scores // Read the data records read( List, Size, Num ); // Check to see if there were any data records in the file if (Num == 0) { cerr << "\n** No data values entered **\n\n"; } else { // Check to see if there were too many data records in the file if (Num == Size && !cin.eof()) { cerr << "\n** Too many records (first " << Size << " used) **\n\n"; } // Process the data records process( List, Num ); } } /*----------------------------------------------------------------------------- Name: read Purpose: Read the data records from the input stream Receive: List[] -- the array of student names and exam scores Size -- the upper bound on the number of data records Num -- the actual number of data records Return: List[] -- the array of student names Num -- the actual number of data records Input: Zero or more data records (student name and exam score) -----------------------------------------------------------------------------*/ void read( Student List[], int Size, int& Num ) { Student Temp; Num = 0; for (;;) { cin >> Temp.Name >> Temp.Score; if (cin.fail() || Num >= Size) break; List[Num] = Temp; Num++; } } /*----------------------------------------------------------------------------- Name: mean Purpose: Calculate the average exam score Receive: List[] -- the array of student names and exam scores Num -- the actual number of data records Return: The average exam score -----------------------------------------------------------------------------*/ double mean( const Student List[], int Num ) { //******************************* // Compute and return the average //******************************* } /*----------------------------------------------------------------------------- Name: process Purpose: Process each data record Receive: List[] -- the array of student names and exam scores Num -- the actual number of data records Output: An appropriate report header Each data record (student name and exam score) The average exam score -----------------------------------------------------------------------------*/ void process( const Student List[], int Num ) { //*************************** // Display the column headers //*************************** cout << "\n"; cout << "Student name Score\n"; cout << "-------------------- -----\n"; //********************* // For each data record //********************* { //******************************************* // Display the current student name and score //******************************************* // cout << resetiosflags( ios::right ) << setiosflags( ios::left ); // cout << setw(20) << List[I].Name << " " .... ; } //***************************************** // Get the average by calling "mean" // Display the average (two decimal places) //***************************************** }