Uploaded by Kwadwo Humble

assignment 2

advertisement
INTRODUCTION TO STRUCTURED PROGRAMMING
ASSIGNMENT 2- Input, Process, Output
1a. A professional programmer usually needs to analysis the problem first.
b. Pseudocode is an informal language which that has no syntax rules and is not
meant to compiled or executed.
c. Input , Processing and output
d. The term user friendly means easy to understand, operate or use
e. 1. Variable name
2. Data type
f. The value stored in uninitialized variable is zero.
2. Declare real height
Display “Enter your height”
Input height
3. Declare string colour
Display “Enter your favourite colour”
Input colour
4a. b = 2+a
b. a = b*4
c. b = 3.14/a
d. a = b-8
5. Assuming the variable result ,x, y and z are all integers, and that x = 4 , y = 8,
and z = 2. What value will be stored in result in each of the following statements?
a. Set result = x + y
Answer = 4+8 = 12
b. Set result = z*2
Answer = 2*2 = 4
c. Set result = y/x
Answer = 8/4 = 2
d. Set result = y-2
Answer = 8-2 =6
6. Declare real cost
7. Declare integer total
8. Declare a
a=0
9. Set total = 10+14
10. Declare real down Payment
Declare real due
Set due = total – downPayment
11. If the following pseudocode was an actual program, why would it not display
the output that the programmer expects?
Declare string favouriteFood
Display “ What is the name of your favourite food?”
Input favouriteFood
Display “ Your favourite food is”
Display “favouriteFood”
Answer: The programmer has to attach the variable name favouriteFood to
display with the 4 th line.
Declare string favouriteFood
Display “ What is the name of your favourite food?”
Input favourite food
Display “ Favourite food is “,favouriteFood
Download