This blog is about providing theory as well as simple executable codes of different programming languages such as java, C, C++, and web programming, etc. This blog will be helpful to the IT students to learn about programming.

Sunday, February 12, 2023

write a program to create a employee class EMP with data member(id, name address). Derive a class SALARY with data member(basicsal, post) and again derive class RECORD with data member(month, absent, total) and display employee complete information where total is calculated by deducing total "absent" days form "basicsal".

write a program to create a employee class EMP with data member(id, name address). Derive a class SALARY with data member(basicsal, post) and again derive class RECORD with data member(month, absent, total) and display employee complete information where total is calculated by deducing total "absent" days form "basicsal".

 /*a program to create a employee class EMP with data member(id, name address). Derive a class SALARY with data member(basicsal, post) and again derive class RECORD with data member(month, absent, total) and display employee complete information where total is calculated by deducing total "absent" days form "basicsal".*/

#include<iostream>
# include<string>
using namespace std;

class EMP{
    public:
        int id;
        string name:
        string address:

    EMP(int i, string n, string a):id(i), name(n), address(a){}
};

class SALARY : public EMP {
    public:
        int basicsal;
        string post;

    SALARY(int i , string n, string a, int b, string p):
        EMP (i, n, a), basicsal(b), post(p){}
};

class RECORD : public SALARY{
    public:
        int month;
        int absent;
        int total;
    
    RECORD(int i, string n, string a, int b , string p, int m ,int ab):
        SALARY(i, n, a, b, p), month(m), absent(ab), total(b-ab){}

     void display(){
        cout<<"employee ID:"<<id<<endl;
        cout<<"employee Name:"<<name<<endl;
        cout<<"employee Address:"<<address<<endl;
        cout<<"employee Post:"<<post<<endl;
        cout<<"employee Month:"<<month<<endl;
        cout<<"employee Absent Days:"<<absent<<endl;
        cout<<"employee Total Salary:"<<total<<endl;
    }
};

int main(){
    RECORD emp(1, "sita ram", "india", 50000, "manager", 4,6);
    emp.display();
    return 0;
}

In this example, the 'EMP' class serves as the base class for the 'SALARY' and 'RECORD' classes, which are derived from it using the 'public' keyword. The 'SALARY' class adds the data members 'basicsal' and 'post', and the 'RECORD' class adds the data members 'month' , 'absent' and 'total' member is calculated by subtracting the 'absent' days form the 'basicsal'. The 'display()' function is used to display all the employee information.



No comments:

Post a Comment

If you have any doubts, please let me know

Slider Widget