Professional Documents
Culture Documents
Department of Electrical Engineering CS:152L Object Oriented Programming
Department of Electrical Engineering CS:152L Object Oriented Programming
Course Instructor: Mr. Syed Basit Ali Dated: 2nd March, 2020
Q.1 Create an Employee class, with attributes name, hourly salary and number of hours worked
per month. Write a function, named CalculateSalary, that calculates total salary of the Employee
and another function (Print) that prints the Employee details, including the total salary.
[5 Marks]
#include "stdafx.h"
float Employee::Calculateslry(){
float s = 0;
for (int i = 0; i < 5; i++) {
Employee x;
x.Print();
x.hourlyslry = 125;
cout << " hourly slry= " << x.hourlyslry << endl;
Q.2 In this task you assume that the total salary per month can be variable, depending upon
hourly wages and number of hours worked. Calculate net salary of the Employee for a month.
Conditioned on the net salary determine the amount of tax applicable on the Employee. If net
salary is between $200 to $1000, 5% tax incurs. If net salary is $1000 to $2000 10% tax applies.
[5 Marks]
void Employee::print() {
cout << name << endl;
}
int main() {
Employee x;
strcpy_s(x.name, "name:ehitsham");
x.print();
cout << x.Calculateslry() << "$" << endl;
}
float Employee::Calculateslry() {
float a = inputhours() * wages();
if (a < 200){
float j = 0;
j = (a * 0) / 100;
cout << "tax is 0 percent:: " << j << "will be tax";
}
if (2000 <= a) {
float j = 0;
j = (a * 15) / 100;
cout << "tax is 15percent ::" << j << " will be tax";
}
}
cout << endl;
Q.3 Define a function to calculate the Net Income of the month after the deduction of tax.
[5 Marks]
#include "stdafx.h"
//BSEE19005 EHITSHAM KHALIL
#include <iostream>
using namespace std;
class Employee
{
public:
char name[50];
int hourlyslry[30];
float workhours[30];
float Calculateslry();
void Print();
float wages();
float inputhours();
};
float Employee::wages()
{
float k = 0;
for (int i = 0; i < 5; i++)
{
cout << " slry day:" << i + 1 << endl;
cin >> hourlyslry[i];
k = k + hourlyslry[i];
}
return k;
}
float Employee::inputhours()
{
float s = 0;
for (int i = 0; i < 5; i++)
{
cout << " hours work for day:" << i + 1 << endl;
cin >> workhours[i];
s = s + workhours[i];
}
return s;
}
void Employee::Print() {
cout << name << endl;
}
int main() {
Employee x;
strcpy_s(x.name, "name:ehitsham");
x.Print();
float Employee::Calculateslry() {
float a = inputhours() * wages();
if (a < 200){
float j = 0;
j = (0 * 2.5) / 100;
j = a - j;
cout << "tax is 0 percent and remaining slry=" << j << "$" << endl;
}
if (200 <= a && a < 1000){
float j = 0;
j = (a * 5) / 100;
j = a - j;
cout << "Tax is 5 percent and remaining slry=" << j << "$" << endl;
}
else {
j = a - j;
cout << "Tax is 10 percent and the remaining slry=" << j << "$" << endl;
}
if (2000 <= a) {
float j = 0;
j = (a * 15) / 100;
j = a - j;
cout << "Tax is 15 percent and the remaining slry=" << j << "$" << endl;
}
}
cout << endl;
cout << "ttl Slry=";
return a;
}