Object Oriented Programming Lab Journal - Lab 4
Object Oriented Programming Lab Journal - Lab 4
Enrollment #: _________________________________
Class: _________________________________
Objective
This lab is in continuation of your first lab on objects and classes. This session will introduce
pointers to classes, dynamic memory allocation of objects and separating class definition from
implementation.
Go through Lab 4 of the manual, attempt the given programs and verify their outputs. Once you
are done, perform the following tasks.
Tasks :
2. Declare an object of type Distance and a pointer to Distance. Assign the address of the
object to the pointer.
3. Write C++ statements to call function display() of class Distance using: object , pointer to
object.
4. Declare a pointer to Distance and allocate memory for an object using the keyword new.
5. Suppose the Distance class has a constructor Distance(int f, int i). Allocate memory for
an object of class Distance using the keyword new in such a way that this constructor is
invoked.
Exercise 1
a. Declare a class Time with three fields hour, minute and second
b. Provide a ppropria te constructors to initialize the data members.
c. Provide separa te get() an set()methods for each of th e data
members.
d. Provide a method display() to print the time.
e. In th e main(), using dynamic memory alloca tion, allocate memory
for two Time obj ects, currentTime and Flig thTime.
f. From main(), call the function getHour() for both the Time
objects and provid e the estimated number of hours in the departure o f
your flight. (No need to tak e into account minutes or seconds)
Exercise 2
+++++++++++++++++++++++++