Sei sulla pagina 1di 2

NUST School of Electrical Engineering and Computer Science

Object Oriented Programming using C++


Assignment - 1
(BEE-1 ABC)
1) Exercise-11, chapter-4 [10]
Create a Time structure and write a program that obtains two Time values
from the user, stores them in Time variables, converts each one to seconds
(type int), adds these quantities, converts the result back to
hours:minutes:seconds, stores the result in a Time variable and finally
displays the result in 12:59:59 format.

Marking criteria:
Time structure -------------–------------------------------------------------------- 1
Obtain & Store values in Time variables ------------------------------------ 1
Convert to seconds -------------------------------------------------------------- 3
Add and convert result in time format ------------------------------------- 4
Display Time ----------------------------------------------------------------------- 1

2) Exercise-5, chapter-5 [5]


Write a function called hms_to_secs() that takes three int values – for hours,
minutes and seconds – as argument and returns the equivalent time in
seconds (type long). Create a program that exercises this function by
repeatedly obtaining a time value in hours, minutes and seconds from the
user (format 12:59:59), calling the function and displaying the value of
function it returns.

Marking criteria:
hms_to_secs() ---------------------------------------------------------------------- 3.5
Obtain & convert repeatedly -------------------------------------------------- 1.5

3) Exercise-6, Chapter-5 [10]


Start with program in Q-1; keep the same functionality, but modify the
program so that it uses two functions. The first, time_to_secs(Time ), takes as
its only argument a structure of type Time and returns the equivalent in
seconds (type long). The second function, secs_to_time(long ), takes as its
only argument a time in seconds (type long), and returns an equivalent
structure of type Time.

Marking criteria:
time_to_secs() ----------------------------------------------------------------------- 4
secs_to_time() ---------------------------------------------------------------------- 6
4) Exercise [15]

A matrix is a two-dimensional array. Create a structure matrix having member data


rowSize, colSize and an int type pointer-to-pointer. Now write the following functions
for this structure:

i) putElement(matrix m, int row, int col, int element) which checks if the
specified location (i.e. row and col) is within bounds of 2D array in m and
stores element at specified location, otherwise displays an error message.

ii) getElement(matrix m, int row, int col) which checks if the specified location
is within bounds of 2D array in m and returns element at specified location,
otherwise displays an error message.

Test your program by creating a variable of matrix and dynamically allocating


2D array, whose address is stored in pointer-to-pointer member of matrix and
size is stored in rowSize and colSize. Call the two functions with appropriate
arguments.

Use pointer notation throughout the program to access array elements.

Marking criteria:
matrix structure --------------------------------------------------------------------- 3
putElement() ------------------------------------------------------------------------- 3
getElement() ------------------------------------------------------------------------- 3
matrix variable and dynamic allocation ------------------------------------- 3
function calling --------------------------------------------------------------------- 1
Pointer notation throughout program --------------------------------------- 2

Potrebbero piacerti anche