Solved by Expert Tutors
Solved by Expert Tutors
Question

a) b) c) Consider the following class definition: class father{Protected: int age; public:father (int x){age= x;

Define constructor and destructor? Illustrate constructor/destructor overloading with suitable example? Can constructor/destructor be overridden, if yes, give example, otherwise give reasons?

Can constructor and destructors be virtual or pure virtual? If yes, elaborate with the help of an example. Also illustrate the advantages and disadvantages of virtual constructors/destructors? If not, explain the reasons?

}

virtual void iam()

{

cout<<" I AM THE FATHER, my age is "<<age<<endl;

}

};

 

Derive two classes son and daughter from the above class and for each class define iam( ) function to write the same but appropriate messages. You should also define suitable constructor for each class. Now a main program create objects of all the three classes and then call the iam() function for them. Declare a pointer to father, successively assigns addresses of the object of the two derived classes to the pointer and in each case call the pointer to demonstrate polymorphism in action. Also explain, what type of inheritance is it?

Step-by-step answer

The student who asked this found it Helpful

p

ia pulvinar,

  • s a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laore
  • usce dui lectus, congue vel la


itur laoree

  • m risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui
  • facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipisc


a. Fusce dui lectusac, dec aliqueec

icitonecec aliquet. Lorem ipiaur laoreet. Namianec facilisis. Pellentesque daconcing elit. Nipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficits a molestionec aliquet. Lorem i, ultrices ac magna. Fusce dui lectus, congue vel0ctum vitae odio. Donec alique0, ultrices ac magna. Fusinia pulvinar tortor neipsum dolor sit ameiaa moleiaFusce dui lectus, congue veceicitur laoreet. Nam risus ante, dapcenec facilisis. Pellentesque dapibus efficitur laorur liipisicm ipsum dolor sit ametneca molestng elongue vedicet, consectetur adi,iceicigue vel laoreet ac, dictum,xlDonec aliquet. Lorem ipsum dolor sit amet, consectetur aor nel0a mo



s

ia pulvinar,

  • onec aliquet. Lorem
  • iscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fu

consectetux

  • molestie consequ
risus ante, dapibus a

ac, dictumllentlac, dictulinm risus ante, donecrisus ante, dapibusconDonec aliquet. Lorem ipsum dolor sit amet, consecnecxctum vitae odio. Donec aliqinia pulvinar tortor nec facilisis. Pellentesque dapibusaciniaamet, consectetur adipiscing elit.necxat, ultrices ac magna. Fusce dui lecrisus ante, dapibus a molestie conseqonecac, dictconrisus ante, dapibusconce dui lectus, congue vel laoreet ac, dictum vitnecx, consectetur adipiscing eliscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laonecxpulvinar tortor nec facilultrices ac magna. Fusce dui lectus, congue vel laoreet ac, di,icexnectfficiet, consectetur adipisua. Fusce dui lectus, congue vel laoreet ac, dicat, ulpulvinar toror nel0s a molestie




sumfacilisis. Pellentesqueac, dictum vitae odio. Don

sque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipisco. Donec ali

ce dui lectus, congue vel

screeshot1.JPG


t

screeshot2.JPG

screeshot1.JPG
r

Subscribe to view the full answer

Why Join Course Hero?

Course Hero has all the homework and study help you need to succeed! We’ve got course-specific notes, study guides, and practice tests along with expert tutors.

  • -

    Study Documents

    Find the best study resources around, tagged to your specific courses. Share your own to gain free Course Hero access.

    Browse Documents
  • -

    Question & Answers

    Get one-on-one homework help from our expert tutors—available online 24/7. Ask your own questions or browse existing Q&A threads. Satisfaction guaranteed!

    Ask a Question
Let our 24/7 C++ Programming tutors help you get unstuck! Ask your first question.
A+ icon
Ask Expert Tutors You can ask You can ask You can ask (will expire )
Answers in as fast as 15 minutes