Sei sulla pagina 1di 2

Week#11

Structure Practice:
Program#1:
Creates a user defined structure type Time with three integer members hours, minutes and seconds.
The program defines a single Time structure type variable dinner_time. It uses the dot operator to
initialize the structures members with values given by user. Also write the print function which
takes a time type variable. It prints its time in hh:mm:ss format. Also and call a function next40
which changes the given time type variable by adding 40 minutes to it and then print it.

Program#2:
Create a user defined structure type Rectangle with these integer members, length and width. The
program defines a rectangle r1 and initializes the members according to user input. Then write a
function area which will take a rectangle type variableand calculate the area of that rectangle call
a function print in main which prints the given rectangle and also prints the area by calling area
function.

Program#3:
Write a function called increment that accepts a date structure with three fields each field is an
integer, one for the month, one for the day in the month, and one for the year. The function
increments the date by one day and returns the new date. If the date is the last day in the month,
the month field must also be changed. If the month is December, the value of the year field must
also be changed when the day is 31. A year is a leap year if it is evenly divisible by 4 but not by
100 or it is divisible by 400.

Program#4:
Write a function called futureDate. The function is to use two parameters. The first parameter is a
structure containing today’s date. The second parameter is an integer showing the number of days
after today. The function returns a structure showing the next date, which may be in a future year.

Program#5:
A point in a plane can be represented by its two coordinates, x and y. therefore, we can represent
a point in a plane by a structure having two fields, as shown below.
struct POINT
{
int x;
int y;
};
Write a function that accepts the structure representing a point and returns an integer(1, 2, 3, or 4)
that indicates in which quadrant the point is located, as shown below.
x Y
I positive positive
2 1
II negative positive
3 4
III negative negative
IV positive negative

Quartile coordinates

Program#6:
A straight line is an object connecting two points. Therefore, a line can be represented by a
nested structure having two structures of type POINT, as defined in the above problem.
struct LINE
{
POINT beg;
POINT end;
};

Program#7:
Write a function that accepts two parameters of type POINT and returns a structure of type LINE
representing the line connecting the two points.

Program#8:
Write a function that accepts a structure of type LINE and returns an integer (1, 2, 3), where 1
means vertical, 2 means horizontal, and 3 means oblique. A vertical line is a linewhose x
coordinates are the same. A horizontal line is the line whose y coordinates are the same. An oblique
line is a line that is not vertical or horizontal.

Potrebbero piacerti anche