//employee.h
#include <iostream>
using namespace std;
#include <cstring>
class employee
{
private:
int empno;
char name[50];
char address[50];
int monthlyothours[3];
double monthlyotpayments[3];
double averageotpayment;
public:
employee(int pempno,char pname[],char paddress[]);
void inputmonthlyhours();
void claculatemonthlyotpayments();
void calculateaverageotpayment();
void displayemployeedetails();
};
//employee.cpp
#include "employee.h"
#include <iostream>
using namespace std;
#include <cstring>
employee :: employee(int pempno,char pname[],char paddress[])
{
empno=pempno;
strcpy(name,pname);
strcpy(address,paddress);
}
void employee::inputmonthlyhours()
{
for(int i=0;i<3;i++)
{
cout<<"Enter monthly ot hours for month "<<i+1<<" ";
cin>>monthlyothours[i];
}
}
void employee::claculatemonthlyotpayments()
{
for(int i=0;i<3;i++)
{
int ot=monthlyothours[i];
if(ot>=0&&ot<=15)
{
monthlyotpayments[i]=ot*100;
}
else if(ot>=16&&ot<=40)
{
monthlyotpayments[i]=ot*150;
}
else if(ot>40)
{
monthlyotpayments[i]=ot*250;
}
}
}
void employee::calculateaverageotpayment()
{ double sum=0;
for(int i=0;i<3;i++)
{
sum=sum+monthlyotpayments[i];
}
averageotpayment=sum/2.0;
}
void employee::displayemployeedetails()
{
cout<<"Employee No "<<empno<<endl;
cout<<"Name "<<name<<endl;
cout<<"Address "<<address<<endl<<endl;
cout<<"\t\t\t"<<"month 1 "<<"month 2 "<<"month 3 "<<endl;
cout<<"Monthly ot hours "<<monthlyothours[0]<<" "<<monthlyothours[1]<<" "<<monthlyothours[2]<<endl;
cout<<"Monthly ot payments "<<monthlyotpayments[0]<<" "<<monthlyotpayments[1]<<" "<<monthlyotpayments[2]<<endl;
cout<<"Monthly average payments "<<averageotpayment<<endl;
}
//paper2b _l.cpp
#include "employee.h"
#include <iostream>
using namespace std;
int main()
{
employee emp1(3789,"Ranjith Perera","51,Galle Road,Dehiwala.");
emp1.inputmonthlyhours();
emp1.claculatemonthlyotpayments();
emp1.calculateaverageotpayment();
emp1.displayemployeedetails();
return 0;
}
0 comments:
Post a Comment