Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 7

Department of Electrical Engineering

CS:152L Object Oriented Programming

Course Instructor: Mr. Syed Basit Ali Dated: 2nd March, 2020

Lab Engineer: Hamid Ali Semester: 2nd

Session: Fall2020 Batch: BSEE2019

Lab 3. Introduction to Classes

Lab Report Viva Total


Name Roll No
Marks/10 Marks/5 Marks/15

Ehitsham khalil Bsee19005

Checked on: _______________________________


Signature: __________________________________
1.1 Objective
The goal of this handout is to observe how a program works, how an output is displayed of
your work and also to get a know-how of how programming needs to be done step by step.
1.2 Equipment and Component
Component Description Value Quantity
Computer Available in lab 1

1.3 Conduct of Lab


1. Students are required to perform this experiment individually.
2. In case the lab experiment is not understood, the students are advised to seek help from
the course instructor, lab engineers, assigned teaching assistants (TA) and lab
attendants.
1.4 Theory and Background
Classes in C++
1.5 Lab Tasks

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"

//bsee19005 ehitsham khalil


#include <iostream>
using namespace std;
class Employee
{
public:
char Name[50];
int hourlyslry;
float workhour[30];
float Calculateslry();
void Print();
};
void Employee::Print(){
cout << Name << endl;
}

float Employee::Calculateslry(){
float s = 0;
for (int i = 0; i < 5; i++) {

cout << "hours work for day:" << i + 1 << endl;


cin >> workhour[i];
s = s + workhour[i];
}
cout << "ttl Slry: " << endl;
return hourlyslry*s;
}
int main(){

Employee x;

strcpy_s(x.Name, "name: ehitsham");

x.Print();

x.hourlyslry = 125;
cout << " hourly slry= " << x.hourlyslry << endl;

cout << x.Calculateslry() << 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]

//bsee19005 ehitsham khalil


#include "stdafx.h"
#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 for 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 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();
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 (200 <= a && a < 1000){


float j = 0;
j = (a * 5) / 100;
cout << "tax is 5 percent :: " << j << "will be tax";
}
else {

if (1000 <= a && a < 2000) {


float j = 0;
j = (a * 10) / 100;
cout << "tax is 10 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;

cout << "ttl Slry : ";


return a;
}

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();

cout << x.Calculateslry() << "$" << endl;


}

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 {

if (1000 <= a && a < 2000) {


float j = 0;
j = (a * 10) / 100;

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;
}

You might also like