You are on page 1of 2

DEPARTMENT OF INFORMATION TECHNOLOGY & COMMUNICATION

DFC20113 – PROGRAMMING FUNDAMENTALS


LABORATORY TASK 2:
PROGRAM CONTROL STRUCTURES

Learning Outcomes

By the end of this lab, student should be able to:


 Describe the structure of if and switch statement
 Explain the need of break statements
 Write program using selection and repetition control structures

QUESTION 1 (10 Marks)

Write a programme that can receive input 0 to 9 (integer number), then print it in words. Use if..else if
and switch..case structure.

Example :
Input : 5
Output : FIVE

QUESTION 2 (10 MARKS)

Create an easy math training system for children. The program request the input of two integer
number and then ask the addition result from user. If the addition answer from user is correct, the
message “CORECT….” will display. If not, the correct answer will be display.

Contoh Interaksi output:

Masukkan dua nombor integer : 10 20


Cuba teka apakah jawapannya? : 30
CORRECT... Jawapan anda betul

Masukkan dua nombor integer : 10 20


Cuba teka apakah jawapannya? : 50
WRONG ANSWER: Jawpan sebenar ialah 30

QUESTION 3 (10 MARKS)

Based on the following table, build a system to calculate and display the ticket price based on
passenger age, city code and how many passenger input. Bus will depart from Kuala Lumpur to
other cities.

City code Passenger age Ticket price


1 – 12 years old RM 20.50
T = Kuala Terengganu
>12 years old RM 39.50
1 – 12 years old RM 23.70
D= Kota Bharu
>12 years old RM 46.70
1 – 12 years old RM 16.80
C = Kuantan
>12 years old RM 35.80

1|Page
Contoh Interaksi output:

Masukkan kod bandar : T


Masukkan umur penumpang : 25
Masukkan bilangan penumpang : 2

Kuala Lumpur to Kuala Terengganu


Passenger age : 25 tahun
Bilangan Penumpang : 2
Harga Tiket seorang : RM39.50
Jumlah Harga Untuk 2 orang : RM79.00

2|Page

You might also like