Answer to Question #199318 in C++ for Ahmed Ali

Question #199318

Write a program to display the record of an employee using base class and derived class. The name of the base class should be emp_address and name of the derived class should be emp_allowance. Use the constructor with arguments in both classes and assign data to the object of the derived class


1
Expert's answer
2021-05-27T06:24:57-0400
#include <iostream>
#include <string>
using namespace std;
class Emp_address{
    protected:
    string address, name;
    int id;
    public:
    Emp_address(int i, string a, string n){
        id = i;
        address = a;
        name = n;
    }
};
class Emp_allowance: public Emp_address{
    int allowance;
    public:
    Emp_allowance(int i, string a, string n, int s): Emp_address(i, a, n){
        allowance = s;
    }
    void show(){
        cout<<"EMp ID: "<<id<<endl;
        cout<<"Name: "<<name<<endl;
        cout<<"Address: "<<address<<endl;
        cout<<"Allowance: "<<allowance<<endl;
    }
};
int main(){
    Emp_allowance employee(23, "221 Sesame street", "Julius", 4000);
    employee.show();
    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