Reference no: EM132792952
Introduction To Structured Programming
Assignment - Input, Process, Output
1. Give short answers to the following questions:
a. What does a professional programmer usually do first to gain an understanding of a problem?
b. What is pseudocode?
c. Computer programs typically perform what three steps?
d. What does the term user-friendly mean?
e. What two things must you normally specify in a variable declaration?
f. What value is stored in uninitialized variables?
2. Design an algorithm that prompts the user to enter his or her height and stores the user's input in a variable named height.
3. Design an algorithm that prompts the user to enter his or her favourite colour and stores the user's input in a variable named colour.
4. Write assignment statements that perform the following operations with the variables a and b.
a. Adds 2 to a and stores the result in b
b. Multiplies b times 4 and stores the result in a
c. Divides a by 3.14 and stores the result in b
d. Subtracts 8 from b and stores the result in a
5. Assume the variables 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
b. Set result = z * 2
c. Set result = y / x
d. Set result = y - z
6. Write a pseudocode statement that declares the variable cost so it can hold real numbers.
7. Write a pseudocode statement that declares the variable total so it can hold integers.
8. Initialize the variable with the value 0.
9. Write a pseudocode statement that assigns the sum of 10 and 14 to the variable total.
10. Write a pseudocode statement that subtracts the variable downPayment from the variabletotal and assigns the result to the variable due.
11. Debug the following code:
a. If the following pseudocode were an actual program, why would it not display the output that the programmer expects?
Declare String favoriteFood
Display "What is the name of your favourite food?" Input favoriteFood
Display "Your favourite food is " Display "favoriteFood"
b. If the programmer translates the following pseudocode to an actual programming language, a syntax error is likely to occur. Can you find the error?
Declare String 1stPrize
Display "Enter the award for first prize." Input 1stPrize
Display "The first prize winner will receive ", 1stPrize
c. The following code will not display the results expected by the programmer. Can you find the error?
Declare Real lowest, highest, average Display "Enter the lowest score." Input lowest
Display "Enter the highest score." Input highest
Set average = low + high / 2
Display "The average is ", average, "."
d. Find the error in the following pseudocode.
Display "Enter the length of the room." Input length
Declare Integer length