Anda di halaman 1dari 3

FAKULTI TEKNOLOGI KEJURUTERAAN

ELEKTRIK DAN ELEKTRONIK


UNIVERSITI TEKNIKAL MALAYSIA MELAKA

COMPUTER PROGRAMMING

BEEA1343 SEMESTER 2 SESI 2018/2019

LAB 2: PROBLEM SOLVING USING SELECTION STATEMENTS

NO. STUDENTS' NAME MATRIC. NO.

1.

2.

3.

PROGRAMME

SECTION /
GROUP

DATE

1.
NAME OF
INSTRUCTOR(S)
2.

EXAMINER’S COMMENT(S) TOTAL MARKS

1
Section 1: Program Design 1

1. Write a C++ program based on the following requirements:

 Write a program that accepts a number between 1 to 12 and display the name of
the corresponding month. For example if the user types '1' the program will display
'January', if the user types '2' the program will display 'February' and so on.
 If user types in numbers other than 1 to 12, program will display an invalid message
to warn the user.
 You are required to use switch for the month selection part.
 Copy+paste your program code and submit it with your lab report.

Example of program output:

What month were you born on?


Answer: 8

You were born in AUGUST.

Press any key to continue...

What month were you born on?


Answer: 12

You were born in DECEMBER.

Press any key to continue...

What month were you born on?


Answer: 45

Invalid input!

Press any key to continue...

What month were you born on?


Answer: 0

Invalid input!

Press any key to continue...

2
Section 2: Program Design 2

You are required to design a program to calculate BMI (Body Mass Index). The formula
for BMI is:
𝑀𝐴𝑆𝑆 (𝑘𝑔)
𝐵𝑀𝐼 =
𝐻𝐸𝐼𝐺𝐻𝑇(𝑚)2

The categories of BMI are shown in Table 1 below.

Table 1

Category BMI Range


Very severely underweight Less than 15
Severely underweight From 15.1 to 16.0
Underweight From 16.1 to 18.5
Normal (Healthy Weight) From 18.6 to 25.0
Overweight From 25.1 to 30.0
Obese Class I (moderate obese) From 30.1 to 35.0
Obese Class II (Severely obese) From 35.1 to 40.0
Obese Class III (Very severely obese) Over 40.1

Your task is to create the program where:


i. The program will ask user to insert their mass in kg and height in m.
ii. Program will calculate BMI of user and their category.
iii. The program also will tell user if they entered a negative value for mass or height.

The output of the program should be as shown in Figure 1.

Figure 1

Anda mungkin juga menyukai