
COP 3337 โ TEST 3 Spring 2001, Irvine. Do not write on this test paper. Write your answers on the
separate answer sheet provided to you. Three points on the test are counted towards clear, neat printing.
class Student {
public:
Student();
Student(const string & ID, double credits, double gradePts);
int get_Credits() const;
void ReadFromFile( ifstream & infile);
// Given an open input file stream, read a student object
// from the file
void Display() const;
// Display a student on the console
static int get_InstanceCount();
// Return the value of s_nInstanceCount
private:
string m_IdNumber;
double m_CreditsEarned;
double m_GradePoints;
static int s_nInstanceCount; // Counts the number of active
}; // Student objects in the currently running program.
Part 1: Student class
1. Write the implementation of s_nInstanceCount that would be placed in the student.cpp file.
2. Write the implementation of get_InstanceCount() in the student.cpp file.
3. Show the function prototype for a global function named CalculateGPA() that returns a double, and has one
input parameter: a constant Student reference. This function must be declared a friend of the Student class.
Part 2: StudentCollection Class
class StudentCollection {
public:
vector<int> FindCredits(int cutoff) const;
// Return a vector of integers that indicate the
// index positions of all students whose CreditsEarned
// are greater than the value in the cutoff parameter
private:
vector<Student> m_vStudents;
};
1. Write the implementation of the FindCredits() function.
Part 3:Vectors
Assume the following vector definition:
vector<double> rainFall;
1. Write a single statement that changes the vector's size to 50.
2. Write a single statement that sorts the vector in ascending order.
3. If a vector's size is 100 and a program begins to insert the 101st item by calling push_back(), the vector will
automatically resize itself by copying its contents to a new memory location. How many more items can be
inserted into the vector before this copying operation again takes place?