Lab Journal 2: Object Oriented Programming
Lab Journal 2: Object Oriented Programming
Enrollment #: 01-235162-003
Class/Section: BS-IT(3A)
Objective
The objective of this lab is to assess the problem-solving capabilities of the students using
the concepts acquired in the course on Programming Fundamentals.
Int time;
3. Declare a variable of type Time, a pointer to Time and an array of 10 Times. Assign
the address of the variable to the pointer.
int time;
int *ptime;
int a[30];
p=time;
5. Declare a structure Date. Declare another structure Project with fields: ID, startDate
and endDate. (Use nested structures).
Struct Date
{
};
Struct Project {
Int ID, StartDate,EndDate;
};
Exercise 1:
Code:
#include<iostream>
#include<string.h>
struct point
int a,b;
};
int main()
point x,z;
getinput(x);
point c=addpoints(x,z);
cout<<x.a<<" "<<x.b<<"-"<<endl;
system("pause");
cin>>p.a;
cout<<"enter b coordinate:"<<endl;
cin>>p.b;
point p3;
p3.a=p1.a+p2.a;
p3.b=p1.b+p2.b;
return p3;
Output:
Exercise 2:
i. Declare a structure Rectangle with two Points as its members, the top
left and the bottom right.
ii. Declare a variable o f type Rectangle and get user input for the two
points.
iii. Define a function computeArea() which accepts a Rectangle and
returns its area.
iv. Display the area of th e Rectangle in the main().
Code:
#include <iostream>
struct rectangle
int topleft;
int bottomright;
};
rectangle p1;
int main()
cin>>p1.topleft;
cin>>p1.bottomright;
int x=computearea(p1);
return area;
Output:
Code:
#include <iostream>
#include <string>
struct time
int hours;
int minutes;
};
struct flight
int flight_ID;
float arrrival_time;
float departure_time;
};
cin>>f1.flight_ID;
cin>>f1.arrival_time;
cin>>f1.departure_time;
return f1;
flight f;
readinput(f);
cout<<"flight ID:"<<f.flight_ID<<endl;
cout<<"arrival time:"f.arrival_time<<endl;
cout<<"departuretimr:"<<f.departure_time<<endl;
Output:
Implement the given exercises and get them checked by the instructor. Upload the
complete Word file on Piazza. If you are unable to complete the tasks in the lab session,
include those tasks in the journal and deposit this journal along with your programs (printed
or handwritten) before the start of the next lab session.