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
#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;
}
Comments
Leave a comment