(COMP2012)[2016](f)midterm_=vngkoee^_10579.pdf

Void n int y string d double c if curnum maxnum

Info icon This preview shows pages 17–20. Sign up to view the full content.

View Full Document Right Arrow Icon
void School::addStudent(string n, int y, string d, double c) { if (curNum < maxNum) { students[curNum].setStudent(n, y, d, c); curNum++; } else cout "Reached maximum quota" endl; } // *** 5 missing member functions: *** // - School(const School& s) // - School() // - const School& operator = (const School& s) // - const Student * getHighestCGAStudent() const; // - Student ** getLowerThanThreshold(double t) const; Your task is to complete the remaining 5 member functions that satisfy the following requirements: Perform deep copy in the copy constructor and assignment operator function, i.e. operator= . Deallocate dynamic memory properly in the destructor The member function getHighestCGAStudent() should return a pointer to the stu- dent object which has the highest CGA among the list of student objects pointed by students (Hint: Make good use of operator> provided in the Student class) The member function getLowerThanThreshold(double t) should return a list of student objects which the CGA score is lower than the parameter value t . You could assume that the number of students with CGA lower than t is bounded by maxNum , and NULL should be put after the last object to indicate the end of the list if the number of returned objects is less than maxNum . The given testing program main.cpp will compile, run, and produce the output below. 17 (COMP2012)[2016](f)midterm~=vngkoee^_10579.pdf downloaded by xjiae from at 2018-03-13 17:27:22. Academic use within HKUST only.
Image of page 17

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
#include < iostream > / * main.cpp * / #include School.h #include Student.h using namespace std; int main() { School school( "Happy School" , 10); school.addStudent( "Peter" , 2, "CSE" , 3.2); school.addStudent( "Mary" , 3, "MATH" , 3.5); school.addStudent( "John" , 4, "ACCT" , 4.1); school.addStudent( "William" , 3, "IELM" , 2.9); const Student * s = school.getHighestCGAStudent(); if (s != NULL) { cout "Student with the highest CGA" endl; cout "----------------------------" endl; cout * s endl; } Student ** list = school.getLowerThanThreshold(3.0); cout "Student(s) with CGA < 3.0" endl; cout "-------------------------" endl; for ( int i=0; list[i] != NULL; i++) cout * (list[i]) endl; } Output of the testing program: Student with the highest CGA ---------------------------- Name: John Year: 4 Department: ACCT CGA: 4.1 Student(s) with CGA < 3.0 ------------------------- Name: William Year: 3 Department: IELM CGA: 2.9 18 (COMP2012)[2016](f)midterm~=vngkoee^_10579.pdf downloaded by xjiae from at 2018-03-13 17:27:22. Academic use within HKUST only.
Image of page 18
Answer: /* File ”School.cpp” */ Implement all the missing member functions of the class School here: School::School( const School& s) { // 1 point students = NULL; * this = s; } School:: School() { // 1 point if (students != NULL) delete [] students; } const School& School:: operator =( const School& s) { if ( this != &s) { // 1 point if (students != NULL) delete [] students; // 1 point name = s.name; // 1 point maxNum = s.maxNum; // 0.5 point curNum = s.curNum; // 0.5 point students = new Student[s.maxNum]; // 1 point for ( int i=0; i < s.curNum; i++) // 1 point students[i] = s.students[i]; } return * this ; // 1 point } const Student * School::getHighestCGAStudent() const { Student * student = NULL; if (curNum > 0) { student = &(students[0]); // 1 point for ( int i=1; i < curNum; i++) { // 1 point if (students[i] > * student) // 1 point student = &(students[i]); // 1 point } } return student; // 1 point } 19 (COMP2012)[2016](f)midterm~=vngkoee^_10579.pdf downloaded by xjiae from at 2018-03-13 17:27:22. Academic use within HKUST only.
Image of page 19

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 20
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern