OOP Lab MID TERM SOLUTION (Maybe)
OOP Lab MID TERM SOLUTION (Maybe)
}
};
Write all the required functions (members as well as non-members) such that the
int main ( ) function works correctly with no logical errors.
(Note: DO not write any getter and setter functions for this question. Writing getters and
setters will result in deduction of marks.)
(5 marks) //destructor
Student::~Student (){
If (Name)
delete [] Name;
}
Q2 (20)
a) For the Student class of Q1, given above, write the required functions so that the main
function given below executes successfully. Do not write code for ‘cout’ and overloaded
constructor as they are part of Q1.
b) Write the output of the program.
int main ( ) {
Student s1 (“Happy Cow”, 4, 3.5, 5000);
cout << s1++ << endl; //s1++ increases the scholarship of s1 by 10%.
// However, if scholarship of object is zero (0), then it
// increases it by 500.0
s1[0] = ‘N’;
cout << s1 << endl;
s1[6] = s2[8];
cout << s1 << endl;
}
return temp;
}
b)
// The output of the program is as follows, according to code I have written.
(5 marks)
Q3 (10)
For the Student class of Q1, given above, write the required member(s)/function(s) so that the
main function given below executes successfully.
Modify cout of Q1 so that it prints an additional member, University, to which all students
created through this Student class belong. This member is not part of any object of Student class.
It is also constant and its value is “University of Central Punjab”.
int main () {
Student sArray[10];
Student ss(“Object Oriented Programming”, 3, 2.0, 0);
cout << ss << endl;
}
Ans:
(2 marks)
Student::Student() = default;
(3 marks)
//data member declaration in the private part of Student class declaration
(3 marks)
//data member initialization outside of Student class declaration, preferably, immediately
// after Student class declaration.
(2 marks)
//modification in cout code