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

OOP Lab 4

(1) The Time class stores time in seconds only, and converts hours, minutes, and seconds entered by the user into total seconds. This reduces the unit of storage to seconds. (2) The Array class implements a dynamic array that allocates memory on the heap. It has functions to set/get values by index, resize the array by deallocating and reallocating memory, and a destructor to deallocate memory. (3) The tasks involve creating separate header and cpp files for the Time and Array classes, with the Time class converting user input to seconds for storage and the Array class dynamically resizing memory as needed.

Uploaded by

abdul haseeb
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)
32 views

OOP Lab 4

(1) The Time class stores time in seconds only, and converts hours, minutes, and seconds entered by the user into total seconds. This reduces the unit of storage to seconds. (2) The Array class implements a dynamic array that allocates memory on the heap. It has functions to set/get values by index, resize the array by deallocating and reallocating memory, and a destructor to deallocate memory. (3) The tasks involve creating separate header and cpp files for the Time and Array classes, with the Time class converting user input to seconds for storage and the Array class dynamically resizing memory as needed.

Uploaded by

abdul haseeb
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/ 2

Object Oriented Programming (OOP)

By: Miss Sanam Ahmad

Lab No. 4
Instructions:
 Make separate cpp files and header files for each class.

Task 1: (10)
The Time can be stored only in seconds. And we can calculate hours, minutes and seconds from
total seconds in a day. In this Time class you have a total number of seconds in a day that has
passed. And user does not know that you have only seconds information. You have to code in
such a way that user assumes that it is a normal Time class that takes complete time
information as hours, minutes and seconds that converts that hours, minutes and seconds into
total number of seconds. In short you will reduce the unit of storage.

Example : let say the time is hours = 1: minutes = 10:seconds =10

So total number of seconds =( hours * 3600 ) + ( minutes * 60 ) + seconds.


Task 2: (10)
You have to implement an Array class that works like normal array of integer. That dynamically
allocates memory and stores on heap and that has the functionality to resize himself whenever
resize function is called.

Array():Set default values .

Array(int cap) : initialize the memory on heap.

setIndex : sets the index with the value provided.

getIndex : gets the index value

resize: deallocates the current allocated memory and allocates the new capacity and copy the
previous values.

~Array : Deallocated the dynamically allocated memory .

You might also like