Â
The Code given below can be used in TURBO C++ Compilers: -
#include<iostream.h>
#include<conio.h>
// base class 1
class DA
{
public:
double da;
void CalcDA(double basic)
{
da = 0.7 * basic;
}
};
// base class 2
class HRA
{
public:
double hra;
void CalcHRA(double basic)
{
hra = 0.3 * basic;
}
};
// base class 3
class PF
{
public:
double pf;
void CalcPF(double basic)
{
pf = 0.1 * basic;
}
};
// first sub class
class GrossSal : public DA, public HRA
{
public:
double gs;
void GS(double basic)
{
DA::CalcDA(basic);
HRA::CalcHRA(basic);
gs = basic + da + hra;
cout << "Gross Salary = Rs." << gs << "/-\n";
}
};
// second sub class
class NetSal : public PF
{
public:
double ns;
void NS(double basic)
{
PF::CalcPF(basic);
ns = basic - pf - 100;
cout << "Net Salary = Rs." << ns << "/-\n";
}
};
// main function
void main()
{
clrscr();
int empId;
char empName[25];
long basic;
cout << "Enter Employee ID: ";
cin >> empId;
cout << "Enter Employee Name: ";
cin >> empName;
cout << "Enter basic salary of Employee: ";
cin >> basic;
GrossSal obj1;
NetSal obj2;
obj1.GS(basic);
obj2.NS(basic);
getch();
}
//.......Coded by SHREYA IDATE
The Code given below can be used in gcc/g++ Compilers: -
#include <iostream>
using namespace std;
// base class 1
class DA
{
public:
double da;
void CalcDA(double basic)
{
da = 0.7 * basic;
}
};
// base class 2
class HRA
{
public:
double hra;
void CalcHRA(double basic)
{
hra = 0.3 * basic;
}
};
// base class 3
class PF
{
public:
double pf;
void CalcPF(double basic)
{
pf = 0.1 * basic;
}
};
// first sub class
class GrossSal : public DA, public HRA
{
public:
double gs;
void GS(double basic)
{
DA::CalcDA(basic);
HRA::CalcHRA(basic);
gs = basic + da + hra;
cout << "Gross Salary = Rs." << gs << "/-\n";
}
};
// second sub class
class NetSal : public PF
{
public:
double ns;
void NS(double basic)
{
PF::CalcPF(basic);
ns = basic - pf - 100;
cout << "Net Salary = Rs." << ns << "/-\n";
}
};
// main function
int main()
{
int empId;
char empName[25];
long basic;
cout << "Enter Employee ID: ";
cin >> empId;
cout << "Enter Employee Name: ";
cin >> empName;
cout << "Enter basic salary of Employee: ";
cin >> basic;
GrossSal obj1;
NetSal obj2;
obj1.GS(basic);
obj2.NS(basic);
return 0;
}
//.......Coded by SHREYA IDATE
#ENJOY CODING
Write a C++ program using a class employee to store the employee_code, surname, forename, and basic pay. The following deductions should also be included: income tax at 20% of Basic Pay and a fixed rate of $10.00 for social security, while the following allowances (not taxable) should be included: housing allowance = $650.00, and motor vehicle allowance = $100.00. Use the functions get ( ), calculate ( ) and display ( ) to perform the following functions: (15 Marks) a) Accept the employee_code, surname, forename, and basic pay. b) Calculate the Net Salary = (Basic Pay - Deductions ) + Allowances c) Display the Net Salary
ReplyDelete// Write a C++ program using a class employee to store the employee_code, surname, forename, and basic pay. The following deductions should also be included: income tax at 20% of Basic Pay and a fixed rate of $10.00 for social security, while the following allowances (not taxable) should be included: housing allowance = $650.00, and motor vehicle allowance = $100.00. Use the functions get ( ), calculate ( ) and display ( ) to perform the following functions: (15 Marks) a) Accept the employee_code, surname, forename, and basic pay. b) Calculate the Net Salary = (Basic Pay - Deductions ) + Allowances c) Display the Net Salary
Delete#include
using namespace std;
class Employee
{
private:
int employee_code;
string surname;
string forename;
float basic_pay;
float deductions;
float allowances;
float net_salary;
public:
void get()
{
cout << "Enter the employee code: ";
cin >> employee_code;
cout << "Enter the surname: ";
cin >> surname;
cout << "Enter the forename: ";
cin >> forename;
cout << "Enter the basic pay: ";
cin >> basic_pay;
}
void calculate()
{
deductions = basic_pay * 0.2;
allowances = 650.00 + 100.00;
net_salary = (basic_pay - deductions) + allowances;
}
void display()
{
cout << "Employee code: " << employee_code << endl;
cout << "Surname: " << surname << endl;
cout << "Forename: " << forename << endl;
cout << "Basic pay: " << basic_pay << endl;
cout << "Deductions: " << deductions << endl;
cout << "Allowances: " << allowances << endl;
cout << "Net salary: " << net_salary << endl;
}
};
int main()
{
Employee employee;
employee.get();
employee.calculate();
employee.display();
return 0;
}
Post a Comment
FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP