Answer to Question #186391 in C++ for Deepanshi singh

Question #186391

Create a class named 'Member' having the following members

1 data member

2 name

3 age

4 phone number

5 address

6 salary

It also has method named 'print salary' of the members. Two classes'employes ' & ' manager' inherits the 'member' classes . The 'employee' & 'manger' speclization and ' department ' respectively . Now, assign name , age , phone number, address & salary to an employer & a manger by making an object of both of these classes and print.


1
Expert's answer
2021-04-29T03:15:07-0400
#include <iostream>


using namespace std;


//define member class
class Member{
    public:
        string name;
        int age;
        string phoneNo;
        string address;
        double salary;
        
        void printSalary(){
            cout<<salary<<endl;
        }
};


//define employee classs
class Employee: public Member{
    private:
        string specialization;
};


//define manager class
class Manager: public Member{
    private:
        string department;
};




int main()
{
    Employee e;
    Manager m;
    
    e.name="John";
    e.age=29;
    e.phoneNo="234-23-43";
    e.address="4352-43";
    e.salary=500000;


    m.name="James";
    m.age=32;
    m.phoneNo="222-123-5";
    m.address="6542-34";
    m.salary=700000;
    cout<<m.salary;
    
    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