You are on page 1of 2

TAB1013 Structured Programming

Lab Exercises

LAB 1 WEEK 5

Objectives
By the end of this lab session, you will be able to:
1. design a selection structure in solving a problem,
2. apply the concept of selection structure in developing a C++ program, and
3. apply good programming principles, desk checking and debugging.

Activity #1

Enter
pH

True False
pH==7
?

True False
“Neutral” pH<7?

True False True False


pH<2? pH>12
?

“Very “Acidic” “Alkalin


Acidic” e”

“Very
Alkaline”

Figure 1

Write a nested if statement for the above flow chart.

-1
TAB1013 Structured Programming
Lab Exercises

Activity #2

Write an if statement for the table below. Assign -1 to lumens when the value of
watts is not in the table.

Watts Brightness (in lumens)


10 110
20 200
35 450
70 800
80 1000
100 1700
Figure 2

Rewrite the above program by using switch statements

Activity #4

Write a C++ program that contains an if statement that may be used to compute
the area of a circle (area = π* radius* radius), or circumference of a circle
(circumference=2 * π* radius) or a triangle (area = 1/2 x base x height). Display “Invalid
User Input” if the user entered other letters. Note that side, radius, base and height
must be greater than zero.

-2

You might also like