Knowee
Questions
Features
Study Tools

Write a programme in C++ which read and print employee information with department and pf information using hierarchical inheritance

Question

Write a programme in C++ which read and print employee information with department and pf information using hierarchical inheritance.

🧐 Not the exact question you are looking for?Go ask a question

Solution

Sure, here is a simple program in C++ that uses hierarchical inheritance to read and print employee information with department and PF information.

#include<iostream>
using namespace std;

class Employee {
    protected:
        string name;
        int id;
    public:
        void read() {
            cout << "Enter Employee Name: ";
            cin >> name;
            cout << "Enter Employee ID: ";
            cin >> id;
        }
        void print() {
            cout << "Employee Name: " << name << endl;
            cout << "Employee ID: " << id << endl;
        }
};

class Department : public Employee {
    protected:
        string deptName;
    public:
        void read() {
            Employee::read();
            cout << "Enter Department Name: ";
            cin >> deptName;
        }
        void print() {
            Employee::print();
            cout << "Department Name: " << deptName << endl;
        }
};

class PF : public Employee {
    protected:
        double pfAmount;
    public:
        void read() {
            Employee::read();
            cout << "Enter PF Amount: ";
            cin >> pfAmount;
        }
        void print() {
            Employee::print();
            cout << "PF Amount: " << pfAmount << endl;
        }
};

int main() {
    Department dept;
    PF pf;
    cout << "Enter Department Employee Details" << endl;
    dept.read();
    cout << "Enter PF Employee Details" << endl;
    pf.read();
    cout << "Department Employee Details" << endl;
    dept.print();
    cout << "PF Employee Details" << endl;
    pf.print();
    return 0;
}

This program first defines a base class Employee with methods to read and print employee information. Then it defines two derived classes Department and PF that inherit from Employee and add additional information. In the main function, it creates instances of Department and PF, reads their information from the user, and then prints it.

This problem has been solved

Similar Questions

Write a programme in C++ which read and print employee information with department and pf information using hierarchical inheritance

Write a program that would print the information (name, year of joining, salary, address) of threeemployees by creating a class named 'Employee

Define a class Employee. Display the personal salary details of three employeesusing single inheritance

Question : C Programing was created at ________ at Dennis Ritchie .1. Stanford Lab2. Haward University3. AT & T Bell Laboratory4. L&T Laboratory

Construct FP tree for data given below, and find conditional pattern base and association rules.

1/1

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.