Vous êtes sur la page 1sur 6

LAB 1 WEEK 3

Objective
To solve a given problem by applying the following steps:
1. Specify the problem requirements.
2. Analyze the problem.
3. Design the algorithm to solve the problem.
Deliverable items
For each of the following activities, you are required to:
1. Determine input, output and process. Provide your assumptions, if any,
2. develop a complete algorithm,
a. pseudo-code, OR
b. flowchart, and
3. Desk checking with some sample data.

Activity #1

Obtain three numbers from the keyboard, compute the average of the
numbers and display the result.
Obtain two numbers from the keyboard, and determine and display which (if
either) is the smaller of the two numbers.
Obtain a series of positive numbers from the keyboard, and determine and
display the sum of the numbers. Assume that the user types the sentinel
value -1 to indicate end of data entry.

Activity #2
You were asked by your project leader to write a simple program that obtains the
lengths of the sides of a rectangle. The program calculates the area and perimeter
then prints lengths, the area and the perimeter. Prepare a pseudo-code and a
flowchart for the program.
Activity #3
Calculate Carpeting Area
Write pseudocode for calcCarpeting, based on the following structure chart.

LAB 1 WEEK 3 [SOLUTION]


Activity #1

Obtain three numbers from the keyboard, compute the average of the
numbers and display the result.
i.
ii.
iii.
iv.
v.
vi.

Start
Declare variables
Get input from user number 1, number 2, and number 3
Calculate average of number 1, number 2, and number 3
Display average
End

Start

Number 1,
Number 2,
Number 3

Average = (Number 1 +
Number 2 + Number 3) / 3

Display
Average

End

Obtain two numbers from the keyboard, and determine and display which (if
either) is the smaller of the two numbers.

i.
ii.
iii.
iv.
v.
vi.

Start
Declare variables
Get input from user number 1 and number 2
Compare number 1 and number 2
Display the smaller number
End

Start

Number 1,
Number 2

Display Number
1 is smaller than
Number 2

Number 1 < Number 2

Display Number
1 is smaller than
Number 2

End

Obtain a series of positive numbers from the keyboard, and determine and
display the sum of the numbers. Assume that the user types the sentinel
value -1 to indicate end of data entry.
i.
ii.
iii.
iv.
v.

Start
Declare variables
Initialize total value = 0
Get a number from user
If number is not equal to -1, go to step 6, otherwise go to step
7
vi. Calculate sum
vii. Display sum of numbers
viii. End

Activity #2
You were asked by your project leader to write a simple program that obtains the
lengths of the sides of a rectangle. The program calculates the area and perimeter
then prints lengths, the area and the perimeter. Prepare a pseudo-code and a
flowchart for the program.
1.
2.
3.
4.
5.
6.

Start
Declare variables
Get input length and width from user
Calculate area and perimeter
Display area and perimeter
End

Activity #3

Calculate Living Area


Write a pseudo-code for calcCarpeting, based on the following structure chart.

Algorithm calcCarpeting
Start
1. Prompt user for famRoom width
2. Read familyRoom width
3. Prompt user for famRoom length
4. Read famRoom length
5. famRoom area = famRoom width * famRoom length
6. Prompt user for dineLive width
7. Read dineLive width
8. Prompt user for dineLive length
9. Read dineLive length
10. dineLive area = dineLive width * dineLive length
11. Living areas = famRoom area + dineLive area
12 Prompt user for bedRoom width
13. Read bedRoom width
14. Prompt user for bedRoom length
15. Read bedRoom length
16. BedRoom area = bedRoom width * bedRoom length
17. Carpeting area = BedRoom area + Living areas
End Algorithm calcCarpeting

Vous aimerez peut-être aussi