0

A Daughter and a Son class inherit the Mother class. Each of the classes has print() which outputs the name as class member vari

23rd Apr 2020, 6:30 PM
Daniel Ngwasi
Daniel Ngwasi - avatar
1 Odpowiedź
+ 2
A Daughter and a Son class inherit the Mother class. Each of the classes has print() which outputs the name as class member variable. In the following user code void callprint(Mother *p){ p->print(); } int main(){ Daughter *d; d = new Daughter (“Jessica”); Mother * m; m= new Mother (“Jasmine”); callPrint(m); Son *s; s = new Son (“Jeffrey”); m = d; callPrint(m); s = m; callPrint(m); system(“pause’); return 0; } What are the multiple flaws in the code? Cite them(Marks 7) Rectify the code and use polymorphism of three Mother pointer variables to output the Mother, Daughter and Son names using callPrint()(Marks 8)
23rd Apr 2020, 6:30 PM
Daniel Ngwasi
Daniel Ngwasi - avatar