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
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.
Similar Questions
Design a structure in C to represent an employee's information, including their name, employee ID, department, and salary. Additionally, write a program that allows users to input employee data, display employee information, and update an employee's salary. write a code for demonstrating the implementation of the structure and program functionalities.input and output Enter employee details:Enter employee name: John DoeEnter employee ID: 101Enter department: SalesEnter salary: 50000Employee Information:Name: John Employee ID: 101 Department:Sales Salary: 50000.00Enter new salary: 55000Salary updated successfully.Updated Employee Information:Name: JohnEmployee ID: 101Department: SalesSalary: 55000.00
Write a C program to store the information of employees in a company using structures. Each employee should have the following details:Employee code (integer)Employee name (string)Salary (float)Department number (integer)The program should allow the user to input the number of employees (n) and then input the details of each employee. i.Display the employee name with the maximum salary.ii. Display the average salary of all employees in the company.Test Case:3 // number of employees101 //Enter employee code:John Doe // Enter employee name:50000.00 // Enter salary:1 // Enter department number:102Jane Smith60000.001103Suresh Raina55000.002Output:Jane Smith55000.00 // avg of all employees salary
Write a program that would print the information (name, year of joining, salary, address) of threeemployees by creating a class named 'Employee
Consider a scenario where you need to manage records of employees in a company. Create aprogram in C that utilizes structures to handle employee information. The program shouldperform the following tasks:a. Define a structure named Employee with the following attributes:Employee ID (integer)Employee Name (string)Department (string)Salary (float)b. Create an array of structures to store information for a maximum of 5 employees.c. Display the information of the employees.
Problem StatementWrite a program to demonstrate Multilevel InheritanceInput FormatInput the details of the student containing the Name, Roll No, Branch, College, marksOutput FormatPrint the details of the studentsSample InputNik12fCSEVJIT9.2Sample OutputNik12fCSEVJIT9.2
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.