// FILE: ReadScor.cpp // READS AN ARRAY OF EXAM SCORES FOR A LECTURE SECTION // RETURNS THE ARRAY OF SCORES AND THE NUMBER OF SCORES READ. #include #include "apvector.h" void read_scores (apvector & scores, // OUT: array to contain all scores read int& section_size) // OUT: number of elements read // Pre: None // Post: The data values are stored in array scores. // The number of values read is stored in section_size. { // Local data ... const int sentinel = -1; // sentinel value int temp_score; // temporary storage for each score read // Read each array element until done. cout << "Enter next score after the prompt or enter " << sentinel << " to stop." << endl; section_size = 0; // initial class size cout << "Score: "; cin >> temp_score; while ((temp_score != sentinel)) { if (section_size == scores.length()) scores.resize(scores.length() + (scores.length() + 2) / 2); scores[section_size] = temp_score; // save score just read section_size++; cout << "Score: "; cin >> temp_score; } // end while // Sentinel was read or array is filled. } // end read_scores