Assignment 1
Assignment 1
Question #1:
Write a program that converts Military Time into Standard Time, and vice versa. Take input from
the user and do the conversion according to the selected option.
Options:
1. Military Time into Standard Time, enter 1
2. Standard Time into Military Time, enter 2
Time Representation
12-hour Time 24-hour Time
12:00 am 00:00
1:00 am 01:00
2:00 am 02:00
3:00 am 03:00
4:00 am 04:00
5:00 am 05:00
6:00 am 06:00
7:00 am 07:00
8:00 am 08:00
9:00 am 09:00
ti
ti
ti
12-hour Time 24-hour Time
10:00 am 10:00
11:00 am 11:00
12:00 pm 12:00
1:00 pm 13:00
2:00 pm 14:00
Question #2:
1. Write a structure called triangularPrism having four oat members variables: hypotenuse,
base, perpendicular, and height.
2. Write se er func ons to set the base, height, and perpendicular separately. The value for
hypotenuse should be calculated and set using Pythagoras’ Theorem.
Note: height, base and perpendicular are non-nega ve oat values, you will have to make sure
of that during input
3. Write ge er func ons for all member variables (func ons that return values of the objects).
4. Write constructors. These should include:
• Default constructor. Use default values of zero for hypotenuse, height, base and
perpendicular.
ti
Question # 4: (70 Marks)
Part B isn’t necessarily an extension of Part A; you’re meant to do both of them separately, so
just write the exact same angle class for Part B (in step 4).
Part A:
1. Suppose you are sailing towards Island XYZ, your exact loca on facing towards XYZ is
158° 45.9’ W, 28°42.6’ S [1]. The marine naviga on system is measured in degrees and
minutes of longitude and la tude.
2. Write a class name angle, that have three data members named degrees, minutes and
direc on. The data type for each member is int, oat and char respec vely.
3. angle can have either la tude or longitude variable, since only one of these is su cient
to describe a loca on in the marine naviga on system.
4. Write a parametrized constructor of class angle for all data members.
5. angle should have a member func on called inputLoca on that takes angle value (in
degrees and minutes) and direc on from user.
• Make sure of the following input constraints:
i. Direc on we have these four char N, W, E and S.
ii. In a degree we have 60 minutes.
iii. To measure la tude we have 0 to 90 degrees.
iv. To measure longitude we have 0 to 180 degrees.
6. Write a member func on called printLoca on to display the input values in the following
format: degrees ° minutes’ direc on
Example: 124° 12.7’ E
7. Write a main() that display the values of an angle object ini alized using inputLoca on.
8. Use a sen nel control loop, that stops when the user enters 9999, otherwise it will
con nue to take in angle values and display them as aforemen oned.
[1] ° for degrees, ’ for minutes, W for west longitude, and S for south la tude
Part B:
1. Write a class named ship.
2. ship should have ship_ID and loca on as its data members.
3. Use the serial number approach (explained below) to assign the ship_ID when a new
ship object is created.
ti
ti
ti
ti
ti
ti
ti
ti
ti
ti
ti
ti
ti
ti
ti
ti
fl
ti
ti
ti
ti
ti
ti
ffi
ti
4. For loca on you can use the representa on of the angle class (made in Part A).
5. Write a member func on called inputShipLoca on for ship that takes the loca on of the
ship from the user and store it in ship’s member variable.
6. Write a member func on called printShipDetails to display the ship_ID and loca on.
7. In main(), create three objects of ship class, asks the user to input the loca on of each
ship using inputShipLoca on, and then display each ship’s ID and its current loca on
using printShipDetails.
Good Luck!
fi
ti
ti
ti
ti
fi
ti
tt
ff
ti