Trusted by millions of Kenyans
Study resources on Kenyaplex

Get ready-made curriculum aligned revision materials

Exam papers, notes, holiday assignments and topical questions – all aligned to the Kenyan curriculum.

a)Show how to overload the constructor for the following class so that unitialized objects can also be created. (When creating uninitialized objects, give x and...

a)Show how to overload the constructor for the following class so that unitialized objects can also be created. (When creating uninitialized objects, give x and y the value 0.)
class myclass {
int x, y;
public:
myclass(int i, int j) { x=i; y=j;}
// ...
};

b)Using the class from question(a) above, show how you can avoid overload myclass() by using default arguments.

Answers


Davis

a)class myclass {
int x, y;
public:
myclass(int i, int j) {x=i; y=j;}
myclass() { x=0; y=0;}
};

b)class myclass {
int x, y;
public:
myclass( int i=0, int j=0) { x=i; y=j;}
};

Githiari answered the question on May 31, 2018 at 18:00

Answer Attachments

Exams With Marking Schemes

Related Questions