0% found this document useful (0 votes)
61 views3 pages

Object Oriented Programming Lab Journal - Lab 4

This lab journal document provides instructions for exercises on object-oriented programming in C++. It describes tasks to: 1) Declare a Distance class with feet and inches integer fields and an object and pointer of that class. 2) Call the display() function of the Distance class using an object and pointer. 3) Declare a pointer to Distance and allocate memory for an object using new. 4) Allocate memory for a Distance object using new while invoking the constructor. It then provides two exercises: 1) Create a Time class with hour, minute, second fields and appropriate methods, and allocate Time objects in main. 2) Implement exercise 1 by putting the class in a header, methods in a cpp, and main in another

Uploaded by

Burhan
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)
61 views3 pages

Object Oriented Programming Lab Journal - Lab 4

This lab journal document provides instructions for exercises on object-oriented programming in C++. It describes tasks to: 1) Declare a Distance class with feet and inches integer fields and an object and pointer of that class. 2) Call the display() function of the Distance class using an object and pointer. 3) Declare a pointer to Distance and allocate memory for an object using new. 4) Allocate memory for a Distance object using new while invoking the constructor. It then provides two exercises: 1) Create a Time class with hour, minute, second fields and appropriate methods, and allocate Time objects in main. 2) Implement exercise 1 by putting the class in a header, methods in a cpp, and main in another

Uploaded by

Burhan
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/ 3

Lab Journal – Lab 4

Object Oriented Programming

Lab Journal - Lab 4


Name: _________________________________

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 :

Write C++ code fragments for the following.

1. Declare a class Distance with fields feet and inches (integers).

2. Declare an object of type Distance and a pointer to Distance. Assign the address of the
object to the pointer.

Object Oriented Programming Page 1


Lab Journal – Lab 4

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

Write a complete C++ program with the fo llowing features.

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)

Object Oriented Programming Page 2


Lab Journal – Lab 4

Exercise 2

Implement the progra m in ex ercise 1 by pu tting the class d efinition in a


header file, the class implementation in a cpp file and the main program in
a separa te cpp file.

Do Exercises 1 and 2 and get them checked by your instructor.

S No. Exercise Checked By:


1. Exercise 1
2. Exercise 2

+++++++++++++++++++++++++

Object Oriented Programming Page 3

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