You are on page 1of 4

ENGN 1310

Computer Programming
Prof.: Amr El Mougy
TA: Rana Eisa

Quiz 2
November 27th, 2018

Name: ……………………………………………………………………………….

UPEI ID: ……………………………………………………………………………

 The quiz time is 60 mins.


 The quiz has 4 pages, including the cover page.
 The quiz is open book. All materials are allowed.
 When you are told that the time is up, please stop working on the test.
 Please follow the instructions of your proctors at all times.

Do not write on this page below this line.

Question Q1 Q2 Q3 (bonus) Total

Max grade 15 15 15 30

Grade

1
ENGN 1310
Computer Programming
Prof.: Amr El Mougy
TA: Rana Eisa

For all questions in this quiz, you are required to write a working algorithm using Matlab.
You may use ANY command in Matlab that you like. Please note that syntax errors will
cost a lot of marks.

Question 1

Write an algorithm that can convert from mile to kilometer or from kilometer to mile, based on
input from the user.

The algorithm should first display a funky greeting message of your choice then ask the user
about the required type of conversion as well as the quantity to be converted. The output of the
algorithm is the converted quantity as well as its unit (mile or kilometer, depending on the
conversion type).

You can use the conversion rule: 1 mile = 1.6 Km.

2
ENGN 1310
Computer Programming
Prof.: Amr El Mougy
TA: Rana Eisa

Question 2

The body mass index (BMI) is the ratio of the weight of a person (in kilograms) to the square of
the height (in meters). Write an algorithm that given the weight and height, computes the BMI,
and prints out the corresponding BMI category:
 Starvation: less than 15
 Anorexic: less than 17.5
 Underweight: less than 18.5
 Ideal: greater than or equal to 18.5 but less than 25
 Overweight: greater than or equal to 25 but less than 30
 Obese: greater than or equal to 30 but less than 40

 Morbidly Obese: greater than or equal to 40

3
ENGN 1310
Computer Programming
Prof.: Amr El Mougy
TA: Rana Eisa

Question 3 (bonus)

Chinese tradition assigns one of twelve zodiac signs to each year. After a twelve year circle, the
signs are repeated in the same order. The order is: Rat—Ox—Tiger—Rabbit—Dragon—
Snake—Horse—Sheep—Monkey—Rooster—Dog—Pig. Chinese New Year is usually in the
beginning of February, so a Chinese year can be approximately identified with a Western
calendar year. The last year of the Rat coincided with 2008.
Write a program that, given a year after 2013, gives the zodiac sign of the coinciding Chinese
year.

You might also like