Answer to Question #176587 in C++ for Muhammad Ahmed

Question #176587

Write three derived classes inheriting functionality of base class person (should have a member function that ask to enter name and age) and with added unique features of student, and employee, and functionality to assign, change and delete records of student and employee. And make one member function for printing address of the objects of classes (base and derived) using this pointer. Create two objects of base class and derived classes each and print the addresses of individual objects. Using calculator, calculate the address space occupied by each object and verify this with address spaces printed by the program


1
Expert's answer
2021-03-29T05:48:20-0400
#include<iostream>


using namespace std;


class person

{

    protected:

        char *name;

        int age;

    public:

        void getdata()

        {

            cout<<"Enter the name: ";

            cin>>name;

            cout<<"Enter the age: ";

            cin>>age;

        }

        void showdata()

        {

            cout<<"Name: "<<name<<endl;

            cout<<"Age: "<<age;


        }

        void print_address(void)

        {

            cout<<"\n The address of object is "<<this;

        }


};


class student: public person

{

    private:

        int ID;

    public:

        void getdata()

        {

            cout<<"Enter the information for student"<<endl;

            person::getdata();

            cout<<"Enter Student ID: ";

            cin>>ID;

        }

        void showdata()

        {

            cout<<"The information on student is"<<endl;

            person::showdata();

            cout<<"\nID : "<<ID;

        }

};


class employee: public person

{

        private:

            float salary;

        public:

            void getdata()

            {

                cout<<"Enter the information on employee "<<endl;

                person::getdata();

                cout<<"Enter Emplyee's salary: ";

                cin>>salary;

            }

            void showdata()

            {

                cout<<"\nThe information on Employee is ";

                person::showdata();

                cout<<"\nSalary: "<<salary<<endl;

            }


};



int main()

{

    student s;

    employee e;

    s.getdata();

    e.getdata();

    s.showdata();

    e.showdata();

    s.print_address();

    e.print_address();

    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

Unknown
31.03.21, 13:49

I don't think that this is the answer of question, as your answer is missing the unique functionality part which should allow user to assign, delete and change records of students and employees.

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS