Answer to Question #260611 in C++ for siri

Question #260611

create Father class and Son class derived from that Father class. Has same member function activity. Father activity is go to office. Student Task is goto Schoo.


1. Wap to display the only Son task without display the father activity by using virtual function.


2. Wap to display only Father activity without display son activity using virtual function.


3. Wap to display Both father and son activity by using virtual function.



1
Expert's answer
2021-11-03T07:44:08-0400
#include <iostream>
#include <string>


using namespace std;


class Father
{
  public:
      void activity()
      {
          cout<<"Father activity is to go office"<<endl;
      }
} ;
class Student: public Father
{
    public:
    void activity()
    {
        cout<<"The student task is go to school"<<endl;
    }
    void both()
    {
      cout<<"Father activity is to go office while ";
      cout<<"The student task is go to school"<<endl;
    }
};




int main()
{
 
   Father *father = new Father;
   Student *student = new Student;
   student->activity();// display the only Son task without display the father activity
   father->activity(); //  display only Father activity without display son activity
   student->both();    //  display Both father and son activity by using virtual function
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS