A company is interested in implementing a payroll system for its employees. You are requested to develop such program in which you must: Declare the base class emp. Use the function called getInfo(), to get the employee details. Declare the derived class salary. Declare and define the function getSalary() to get the salary details. Define the function calculateNet() to find the net pay. Read the number of employees. Call the function getInfo(),getSalary() and calculateNet() to each employees. Test the above operations by writing a complete C++ program using single inheritance
#include <iostream>
#include <string>
using namespace std;
//Declare the base class emp.
class emp{
private:
string name;
int Id;
string phone;
public:
//Use the function called getInfo(), to get the employee details.
void getInfo(){
cout<<"Enter the employee name: ";
getline(cin,name);
getline(cin,name);
cout<<"Enter the employee Id: ";
cin>>Id;
cout<<"Enter the employee phone: ";
getline(cin,phone);
getline(cin,phone);
}
//Constructor
emp (){
}
//destructor
~emp (){}
};
// Declare the derived class salary.
class salary: public emp{//single inheritance
private:
float salaryAmount;
public:
//Constructor
salary (){
}
//destructor
~salary (){}
//Declare and define the function getSalary() to get the salary details.
void getSalary(){
cout<<"Enter the salary: ";
cin>>salaryAmount;
}
// Define the function calculateNet() to find the net pay.
float calculateNet(){
float tax=0.06*salaryAmount;
return salaryAmount-tax;
}
};
//The start point of the program
int main (){
int number;
// Read the number of employees.
cout<<"Enter the number of employees: ";
cin>>number;
for(int i=0;i<number;i++){
salary salaryEmployee;
//Call the function getInfo(),getSalary() and calculateNet() to each employees.
salaryEmployee.getInfo();
salaryEmployee.getSalary();
cout<<"\nThe net pay: "<<salaryEmployee.calculateNet()<<"\n\n";
}
system("pause");
return 0;
}
Comments
great work it really helped with my assignment
Leave a comment