Professional Documents
Culture Documents
Computer Programming
Structures
Name: _________________________________
Enrollment #: _________________________________
Class/Section: _________________________________
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.
struct time
{
int hours;
int minutes;
int seconds;
};
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.
time obj[10];
time* ptrtime;
ptrtime = &obj;
U Computer Programming 1
4. Using pointer variable set the value of hour to 5, minute to 10 and second to 50.
time obj;
time* ptrtime;
ptrtime = &obj;
ptrtime->hours = 5;
ptrtime->minutes = 10;
ptrtime->seconds = 50;
Exercise 1:
Code:
Output:
Exercise 2:
U Computer Programming 2
i. Declare a structure Rectangle with two Points as its members, the top
left and the bottom right.
ii. Declare a variable of type Rectangle and get user input for the two
points.
iii. Defi ne a function computeArea() which accepts a Rectangle and
returns its area.
iv. Display the area of the Rectangle in the main().
Code:
Output:
Exercise 3:
Code:
Output:
U Computer Programming 3