0% found this document useful (0 votes)
43 views

OOP Lab Report - 2

The document describes a lab report assignment to update a previous program on object oriented programming by passing structures as arguments, passing structures by reference, overloading functions to calculate duration, using default arguments, and making display function arguments constant. It includes the problem description, source code implementing these updates, and sample output.

Uploaded by

Eva
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views

OOP Lab Report - 2

The document describes a lab report assignment to update a previous program on object oriented programming by passing structures as arguments, passing structures by reference, overloading functions to calculate duration, using default arguments, and making display function arguments constant. It includes the problem description, source code implementing these updates, and sample output.

Uploaded by

Eva
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Lab Report -2

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: 51
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:10.10.2023
Problem Description :

Rewrite/update the program in Lab-1 using the following features:

1. Pass structure as an argument in a function, and return structure elements


from a function.

2. Pass structure variables as references (pass by reference).

3. Apply function overloading for the duration calculation function (either send
an employee's structure variable or two individual time-structure variables in the
company program).

4. Use the default value/arguments for starting time as 9:00 AM (in the company
program ).

5. In the display function, make the arguments constant.

6. (optional) Make use of the features: 'static', 'inline functions', etc if applicable.
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;
}
employee input(){
employee e;
cout << "Enter second employee's entry time (hours minutes seconds ): " <<endl;
cin >> e.entry.hr >> e.entry.minn >> e.entry.sec;
cout << "Enter second employee's exit time (hours minutes seconds) : " <<endl;
cin >> e.exit.hr >> e.exit.minn >> e.exit.sec;
return e;
}
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;
}

}
Time duration(Time en, Time ex){
Time d;
if((en.hr>=0 && en.hr <24) && (ex.hr>=0 && ex.hr <24 ) && (en.minn>=0 && en.minn<60) &&
(ex.minn>=0 && ex.minn <60) && (en.sec>=0 && en.sec <60) && (ex.sec>=0 && ex.sec <60) )
{

d.sec = ex.sec - en.sec;


if(ex.sec>=en.sec) {
d.sec = ex.sec - en.sec; }
else {
ex.sec=ex.sec+60;
d.sec = ex.sec - en.sec;
ex.minn--;

if(ex.minn>=en.minn) {
d.minn = ex.minn - en.minn; }
else {
ex.minn=ex.minn+60;
d.minn = ex.minn - en.minn;
ex.hr--;

}
if(ex.hr>=en.hr) {
d.hr = ex.hr - en.hr; }
else
{
ex.hr=ex.hr+24;
d.hr=ex.hr-en.hr;

}
return d;
}

else
{

flag =1;
return d;
}

}
void display(const Time& t, int n){
cout << "Time duration of " << n << "employee: ";
cout << t.hr << " hr " << t.minn << " m " << t.sec <<" s "<< endl;
}

int main()
{
employee e1, e2;
input(e1);
e2 = input();
Time d1, d2;
d1 = duration(e1);
d2 = duration(e2.entry, e2.exit);
if( flag ==0){

display(d1, 1);
display(d2, 2); }
else if (flag==1)
{
cout<<"Invalid Time Entered "<<endl;
}

return 0;
}
Output:

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy