Computer Science, asked by TbiaSamishta, 1 year ago

C++ program to calculate employee salary using class

Answers

Answered by honeysingh96
3
* Arooj Mohammed C++ Ch14ConEx5
*/
//Employee.cpp – calculates and displays a new salary
#include <iostream>
#include <string>
using std::cout;
using std::cin;
using std::endl;
using std::string;
//declaration section
class Employee {
public:
//initializes varaibles
Employee();
//assigns program value to variables
void AssignValue(string, float );
//returns name
string DisplayName();
//returns salary
double DisplaySalary();
//calculates new salary
double CalcNewSalary();
private :
string name;
double salary;
double raiseRate;
};
//implementation sectoin
Employee::Employee() {
name = "";
salary = 0;
raiseRate = 0.0;
} //end of default constructor
void Employee::AssignValue(string n, double s, double r) {
name = n;
salary = s;
raiseRate = r; } //end of AssignValue method
string Employee::DisplayName(); {
return name; } //end of DisplayName method
double Employee::DisplaySalary(); {
return salary; } //end of DisplaySalary() method
double Employee::CalcNewSalary() {
if (raiseRate >= 0)
{
salary = salary * raiseRate;
}
else
{
salary = 0.00;
} //end if
return salary; } //end of CalcNewSalary method
int main() {
//create Employee object
Employee hireEmployee;
//declare variables
string name = "";
double pay = 0;
double rate = 0.0;
//get name, salary, and raise percentage
cout << "Employee's name: " ;
getline(cin, name);
cout << "Employee's current salary: " ;
cin >> pay;
cout << "Raise rate: " ;
cin >> rate;
//assign name and salary to the Employee object
hireEmployee.AssignValue(name, pay, rate);
//use the Employee object to display the name and current salary
cout << "Name: "
<< hireEmployee.DisplayName() << endl;
cout << "Salary: "
<< hireEmployee.DisplaySalary() << endl;
//use the Employee object to calculate the new salary
pay = hireEmployee.CalcNewSalary();
//use the Employee object to display the new salary
cout << pay << endl; } //end of main function
Answered by aqibkincsem
12

"

#include<iostream.h>

#include<conio.h>


class employee

{

int   emp_num;

char  emp_name[20];

float emp_basic;

float sal;

float emp_da;

float net_sal;

float emp_it;


public:


 void get_details();

 void find_net_sal();

 void show_emp_details();

};


void employee :: get_details()

{

cout<<""\nEnter employee number:\n"";

cin>>emp_num;

cout<<""\nEnter employee name:\n"";

cin>>emp_name;

cout<<""\nEnter employee basic:\n"";

cin>>emp_basic;

}


void employee :: find_net_sal()

{

emp_da=0.52*emp_basic;

emp_it=0.30*(emp_basic+emp_da);

net_sal=(emp_basic+emp_da)-emp_it;

}


void employee :: show_emp_details()

{

cout<<""\n\n\nDetails of   :  ""<<emp_name;

cout<<""\n\nEmployee number:      ""<<emp_num;

cout<<""\nBasic salary     :  ""<<emp_basic;

cout<<""\nEmployee DA      :  ""<<emp_da;

cout<<""\nIncome Tax       :  ""<<emp_it;

cout<<""\nNet Salary       :  ""<<net_sal;

}


int main()

{

employee emp[10];

int i,num;

clrscr();


cout<<""\nEnter number of employee details\n"";

cin>>num;


for(i=0;i<num;i++)

 emp[i].get_details();


for(i=0;i<num;i++)

 emp[i].find_net_sal();


for(i=0;i<num;i++)

 emp[i].show_emp_details();


getch();

return 0;

}

"

Similar questions