0% found this document useful (0 votes)
23 views6 pages

OOP Lab Report-1

This lab report describes a C++ program that takes employee entry and exit times as input, calculates the duration worked by comparing the times, and outputs the duration and total salary earned based on an input salary per hour. The program includes structs to store time data, functions to input times, calculate duration, and display output, and code to handle invalid time inputs and calculate salary. The report provides the problem description, source code, and sample output of the program.

Uploaded by

Eva
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views6 pages

OOP Lab Report-1

This lab report describes a C++ program that takes employee entry and exit times as input, calculates the duration worked by comparing the times, and outputs the duration and total salary earned based on an input salary per hour. The program includes structs to store time data, functions to input times, calculate duration, and display output, and code to handle invalid time inputs and calculate salary. The report provides the problem description, source code, and sample output of the program.

Uploaded by

Eva
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Lab Report -1

Course Name: Objected Oriented Programming


Course Code: 160
Assignment: Lab report

Submitted To:
Dr. Md. Ezharul Islam
Designation: Professor
Department of Computer Science and Engineering
Jahangirnagar University

Submitted By:
Fateema Binti Taher Eva
Roll: 403
Batch: 2021-2022
Department of Computer Science and Engineering
Jahangirnagar University

Department of Computer Science and Engineering


Faculty of Mathematical and Physical Sciences
Jahangirnagar University
Savar, Dhaka
Submission Date:15.11.2023
Problem Description:

Write a programme which will input an employee’s entry ,exit time (hour ,minutes
,seconds) and salary per hour .The programme will output duration of time he
worked and total salary of the employee.

Source code :

#include <bits/stdc++.h>
using namespace std;
int flag=0;
struct Time
{
int hr;
int minn;
int sec;
};
struct employee
{
Time entry;
Time exit;
};

void input(employee &e){


cout << "Enter first employee's entry time (hours minutes seconds ): " <<endl;
cin >> e.entry.hr >> e.entry.minn >> e.entry.sec;
cout << "Enter first employee's exit time (hours minutes seconds ): " <<endl;
cin >> e.exit.hr >> e.exit.minn >> e.exit.sec;
}

Time duration(employee &e){


Time d;

if((e.entry.hr>=0 && e.entry.hr <24) && (e.exit.hr>=0 && e.exit.hr <24 ) && (e.entry.minn>=0
&& e.entry.minn<60) && (e.exit.minn>=0 && e.exit.minn <60) && (e.entry.sec>=0 && e.entry.sec
<60) && (e.exit.sec>=0 && e.exit.sec <60) )
{

if(e.exit.sec>=e.entry.sec) {
d.sec = e.exit.sec - e.entry.sec; }
else {
e.exit.sec=e.exit.sec+60;
d.sec = e.exit.sec - e.entry.sec;
e.exit.minn--;

if(e.exit.minn>=e.entry.minn) {
d.minn = e.exit.minn - e.entry.minn; }
else {
e.exit.minn=e.exit.minn+60;
d.minn = e.exit.minn - e.entry.minn;
e.exit.hr--;
}
if(e.exit.hr>=e.entry.hr) {
d.hr = e.exit.hr - e.entry.hr; }
else
{
e.exit.hr=e.exit.hr+24;
d.hr=e.exit.hr-e.entry.hr;

}
return d;
}
else
{

flag =1;
return d;
}

void display(const Time& t){


cout << "Time duration of " << "employee: ";
cout <<t.hr << " hr " << t.minn << " m " << t.sec <<" s "<<endl;
}

int main()
{
employee e1;
input(e1);
double salary,salaryperhour1;

cout<<"Enter Salary Per Hour"<<endl;


cin>>salary;

Time d1;
d1 = duration(e1);

if( flag ==0){

display(d1);

int hour1;
hour1 =d1.hr;

salaryperhour1=hour1*salary;

cout<<"Employee's salary is : "<<salaryperhour1<<endl;

}
else if (flag==1)
{
cout<<"Invalid Time Entered "<<endl;
}

return 0;
}
Output:

You might also like