You are on page 1of 2

MKS1013 : PROBLEM SOLVING TECHNIQUE

SEMESTER 1 SESI 2014/2015


LAB EXERCISE 2 - CONTROL STRUCTURE

1. Write a program to determine how much to tip the waiter in a fine restaurant. The tip should
be 13 percent of the bill, with a minimum of $5.
2. A computer store sells compact discs at 50 cents each for small orders or at 30 cents for
orders of 25 compact disks or more. Write a program that requests the number of compact
discs ordered and displays the total cost.
3. A copying center charges 3 cents per copy for the first 100 copies, 5 cents per copy for the
next 200 copies and 7 cents per copy for next additional copy. Write a program that requests
the number of copies as input and displays the total cost.
4. Write a program to determine the cost of an automobile insurance premium, based on
driver's age and the number of accidents that the driver has had.
The basic insurance charge is $500. There is a surcharge of $100 if the driver is under 25
and an additional surcharge for accidents:
No. of accidents
1
2
3
4
5
6 or more
5.

6.

Accidents
surcharge
50
125
225
375
575
No insurance

Seaview Chalet provides three types of room for accommodation. The table below shows room rate for
each type of room. Write a program to calculate and print a bill that a guest has to pay if he/she rent a
room for a number of days. If the guest check in during the weekdays, 10% discount will be given.
(Notes: Assumed Friday and Saturday are the weekends)
Room Type

Room Rate (1 night)

Super Deluxe

RM300

Deluxe

RM220

Standard

RM180

Write a switch statement that assigns to the variable lumens the expected brightness of a standard
light bulb whose wattage has been stored in watts. Use the table below :

Watts

Brightness (in Lumens)

15

125

25

215

40

500

60

880

75

1000

100

1675

Assign -1 to lumens if the value of watts is not in the table.

7. The local t-shirt shop


as follow:

sells

shirts

that retail

for $12.

Quantity discounts are

given

Number of Shirts Discount


510
10%
1120
15%
2130
20%
31 or more
25%
Write a program that prompts the user for the number of shirts required and then
computes the total price. Make sure the program accepts only nonnegative input. Use
the following sample runs to guide you:
Sample Run 1:
How many shirts would you like ? 4
The cost per shirt is $12 and the total cost is $48
Sample Run 2:
How many shirts would you like ? 0
The cost per shirt is $12 and the total cost is $0
Sample Run 3:
How many shirts would you like ? 8
The cost per shirt is $10.80 and the total cost is $86.40
Sample Run 4:
How many shirts would you like ? -2
Invalid Input: Please enter a nonnegative integer
8. The University of Guiness charges $3000 per semester for in-state tuition and $4500
per semester for out-of-state tuition. In addition, room and board is $2500 per
semester for in-state students and $3500 per semester for out-of-state students. Write
a program that prompts the user for their residential status (i.e., in-state or out-ofstate) and whether they require room and board (Y or N). The program should then
compute and output their bill for that semester. Use the sample output below:
Sample Run 1:
Please input "I" if you are in-state or "O" if you are out-of-state: I
Please input "Y" if you require room and board and "N" if you do not: N
Your total bill for this semester is $3000
Sample Run 2:
Please input "I" if you are in-state or "O" if you are out-of-state: O
Please input "Y" if you require room and board and "N" if you do not: Y
Your total bill for this semester is $8000