FISCAL MIXTO “EL EMPALME”
4.1.3. Análisis FODA
1. Write pseudocode that reads two numbers and multiplies them together and print out their product.
2. Write pseudocode that tells a user that the number they entered is not a 5 or a 6.
3. Write pseudocode to print all multiples of 5 between 1 and 100 (including both 1 and 100).
READ 𝑛𝑢𝑚1, 𝑛𝑢𝑚2
SET product to 𝑛𝑢𝑚1* 𝑛𝑢𝑚2 Write product
READ isfive IF (isfive = 5)
WRITE "your number is 5"
ELSE IF (isfive = 6)
WRITE "your number is 6"
ELSE
WRITE "your number is not 5 or 6"
END IF
SET x to 1 WHILE (x < 20)
WRITE x
WRITE x = x*5 ADD 1 to x END WHILE
74
4. Write pseudocode that will count all the even numbers up to a user defined stopping point.
5. Write pseudocode that performs the following: Ask a user to enter a number. If the number is between 0 and 10, write the word blue. If the number is between 10 and 20, write the word red. if the number is between 20 and 30, write the word green. If it is any other number, write that it is not a correct colour option.
6. Write pseudocode that will perform the following.
a) Read in 5 separate numbers.
b) Calculate the average of the five numbers.
c) Find the smallest (minimum) and largest (maximum) of the five entered numbers.
d) Write out the results found from steps b and c with a message describing what they are
WRITE "Please enter a number"
READ color_num
IF (color_num >0 and color_num <= 10) WRITE blue
ELSE IF (color_num >0 and color_num <=
10)
WRITE blue
ELSE IF (color_num >0 and color_num <=
10)
WRITE blue Else
WRITE "not a correct color option"
END IF GET count SET x to 0;
WHILE (x < count)
SET even to even + 2 ADD 1 to x
WRITE even END WHILE
75 WRITE "please enter 5 numbers"
READ n1,n2,n3,n4,n5 WRITE "The average is"
SET avg to (n1+n2+n3+n4+n5)/5 WRITE avg
IF (n1 < n2) SET max to n2 ELSE
SET max to n1 END IF
IF (n3 > max) SET max to n3 END IF
IF(n4 > max) SET max to n4 END IF
IF(n5 > max) SET max to n5 WRITE "The max is"
Write max END IF
IF (n1 > n2) SET min to n2 ELSE
SET min to n1 END IF
IF (n3 < min) SET min to n3 END IF
IF (n4 < min) SET min to n4 END IF
IF (n5 < min) SET min to n5 WRITE "The min is"
WRITE min END IF
76
7. The HappyPetBox Company needs a program to validate customer identifiers. Valid customer identifiers are nine characters long, ending with three uppercase letters.
Here are four examples of valid customer identifiers.
• 836154JSA
• 579317NOY
• 958375MEB
• 294713PUC
Write a pseudocode that will:
• take a potential customer identifier from the user
• if input is “Q”, allow the user to quit the program
• if the potential customer identifier is too short, then tell the user
• if the last three characters do not follow the rules, then tell the user
• allow the user to keep entering customer identifiers Solution:
SET looping TO TRUE #used to keep the loop running until user quits WHILE looping = TRUE DO #loop to keep asking for identifiers
RECEIVE identifier FROM (STRING) KEYBOARD IF identifier = ‘Q’ THEN #user wants to quit
SET looping TO FALSE #loop won’t run again once condition is false SEND ‘Bye’ TO DISPLAY
ELSE IF LENGTH (identifier) <> 9 THEN
SEND ‘The customer identifier is not nine characters long’ TO DISPLAY
ELSE` #check last 3 characters
SET badAlpha TO FALSE #change to TRUE if non-uppercase letter found FOR count FROM 6 TO 8 DO
IF (NOT (identifier[count] >= ‘A’ AND identifier[count] <= ‘Z’)) THEN
SEND ‘Bad character in last 3 characters found’ TO DISPLAY SET badAlpha TO TRUE
END IF END FOR
IF badAlpha = FALSE THEN
SEND ‘Final three characters are valid’ TO DISPLAY END IF
END IF
77 4.0 CONCLUSION
As the complexity and size of a problem increase, the need for generating pseudocode to make writing the actual code much easier becomes more apparent. It helps the problem solver realise possible problems or design flaws in the algorithm earlier in the development stage. Hence, saving more time and effort on fixing bugs and avoiding errors. Moreover, pseudocode allowed programmers to communicate more efficiently with others from different backgrounds, as it delivers the algorithm's idea without the complexity of syntax restrictions.
A clear, concise, straightforward pseudocode can make a big difference in the road from idea to implementation, a smooth ride for the programmer. It’s one of the overall tools underestimated by the programming community but defiantly, needs to be utilised more.
5.0 SUMMARY
This Unit discussed Pseudocode as a methodology that allows the programmer to represent the implementation of an algorithm. The reasons for using Pseudocode are highlighted as for better readability, ease up code construction, a good middle point between flowchart and code, acting as a start point for documentation, easier bug detection and fixing. Other areas covered also includes the main constructs of pseudocode, the rules for writing pseudocode, advantages of pseudocode and lastly worked examples were discussed
6.0 TUTOR MARKED ASSIGNMENTS