Professional Documents
Culture Documents
Department of Electrical Engineering CS:152L Object Oriented Programming
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]
// bsee19020 (T_1).cpp
// Muhammad Hammad:
#include <iostream>
using namespace std;
//Introducing Class Employee
class Employee
{
// the variables are shown Public
public:
char name[50];
int hourlysalary;
float workhours[30];
float Calculatesalary();
void Print();
};
// Function defination for Printing the Employee details
void Employee::Print(){
cout << name << endl;
}
//Function Defination for Calculating the salary
float Employee::Calculatesalary(){
float s = 0;
for (int i = 0; i < 5; i++) {
//Taking inout for Workhours
cout << "Employee's work hours for day no." << i + 1 << endl;
cin >> workhours[i];
s = s + workhours[i];
}
cout << "Total Salary: " << endl;
return hourlysalary*s;
}
int main(){
// using Employee class in main
Employee x;
// copying data to a string
strcpy_s(x.name, "Employee Name: \nHammad");
//Using function to print
x.Print();
// Providing Value
x.hourlysalary = 125;
cout <<"Provided hourly salary = "<< x.hourlysalary << endl;
//Using function to calculate salary
cout << x.Calculatesalary() <<"$"<< 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]
// Bsee19020_(T -2).cpp
//Muhamamd Hammad
#include <iostream>
using namespace std;
//Introducing Class Employee
class Employee
{
// the variables are shown Public
public:
char name[50];
int hourlysalary[30];
float workhours[30];
float Calculatesalary();
void Print();
float wages();
float inputhours();
};
float Employee::wages(){
float k = 0;
for (int i = 0; i < 5; i++) {
//Taking inout for Workhours
cout << "Employee's salary for day no." << i + 1 << endl;
cin >> hourlysalary[i];
k = k + hourlysalary[i];
}
return k;}
float Employee::inputhours() {
float s = 0;
for (int i = 0; i < 5; i++) {
//Taking input for Workhours
cout << "Employee's work hours for day no." << i + 1 << endl;
cin >> workhours[i];
s = s + workhours[i];
}
return s;}
// Function defination for Printing the Employee details
void Employee::Print() {
cout << name << endl;}
//Function Defination for Calculating the salary
float Employee::Calculatesalary() {
float a = inputhours() * wages();
// Tax for value below 200 is 0%
if (a < 200){
float j = 0;
j = (a * 0) / 100;
cout << "Tax is 0% and " << j << "$ will be the tax";
}
// Tax for value between 200$ & 1000$ is 5%
if (200 <= a && a < 1000){
float j = 0;
j = (a * 5) / 100;
cout << "Tax is 5% and " << j << "$ will be the tax";
}
else {
// Tax for value between 1000$ & 2000$ is 10%
if (1000 <= a && a < 2000) {
float j = 0;
j = (a * 10) / 100;
cout << "Tax is 10% and " << j << "$ will be the tax";
}
//Tax for Value above 2000$ is 15%
if (2000 <= a) {
float j = 0;
j = (a * 15) / 100;
cout << "Tax is 15% and " << j << "$ will be the tax";}
}
cout << endl;
//Printing Total Salary
cout << "Total Salary : ";
return a;
}
int main() {
//Using Class Employee
Employee x;
strcpy_s(x.name, "Employee Name: \nHammad");
// Printing Employee's name
x.Print();
//Using function to calculate salary and tax
cout << x.Calculatesalary() << "$" << endl;
}
Q.3 Define a function to calculate the Net Income of the month after the deduction of tax.
[5 Marks]
// Bsee19020_(T - 3).cpp
//Muhamamd Hammad
#include <iostream>
using namespace std;
//Introducing Class Employee
class Employee
{
// the variables are shown Public
public:
char name[50];
int hourlysalary[30];
float workhours[30];
float Calculatesalary();
void Print();
float wages();
float inputhours();
};
float Employee::wages() {
float k = 0;
for (int i = 0; i < 5; i++) {
//Taking inout for Workhours
cout << "Employee's salary for day no." << i + 1 << endl;
cin >> hourlysalary[i];
k = k + hourlysalary[i];
}
return k;
}
float Employee::inputhours() {
float s = 0;
for (int i = 0; i < 5; i++) {
//Taking input for Workhours
cout << "Employee's work hours for day no." << i + 1 << endl;
cin >> workhours[i];
s = s + workhours[i];
}
return s;
}
// Function defination for Printing the Employee details
void Employee::Print() {
cout << name << endl;
}
//Function Defination for Calculating the salary
float Employee::Calculatesalary() {
float a = inputhours() * wages();
// Tax for value below 200 is 2.5%
if (a < 200){
float j = 0;
j = (0 * 2.5) / 100;
j = a - j;
//CALCULATING THE SALARY AFTER DEDUCTING THE TAX
cout << "Tax is 0% and " << j << "$ will be the remaining salary";
}
// Tax for value between 200$ & 1000$ is 5%
if (200 <= a && a < 1000){
float j = 0;
j = (a * 5) / 100;
j = a - j;
//CALCULATING THE SALARY AFTER DEDUCTING THE TAX
cout << "Tax is 5% and " << j << "$ will be the remaining salary";
}
else {
// Tax for value between 1000$ & 2000$ is 10%
if (1000 <= a && a < 2000) {
float j = 0;
j = (a * 10) / 100;
//CALCULATING THE SALARY AFTER DEDUCTING THE TAX
j = a - j;
cout << "Tax is 10% and " << j << "$ will be the remaining salary";
}
//Tax for Value above 2000$ is 15%
if (2000 <= a) {
float j = 0;
j = (a * 15) / 100;
//CALCULATING THE SALARY AFTER DEDUCTING THE TAX
j = a - j;
cout << "Tax is 15% and " << j << "$ will be the remaining salary";
}
}
cout << endl;
//Printing Total Salary
cout << "Total Salary : ";
return a;
}
int main() {
//Using Class Employee
Employee x;
strcpy_s(x.name, "Employee Name: \nHammad");
// Printing Employee's name
x.Print();
//Using function to calculate salary and tax
cout << x.Calculatesalary() << "$" << endl;
}