FC0-U61 · Question #782
Given the following pseudocode: Which of the following would be the output of the program?
The correct answer is C. foosad. The pseudocode given in the question is a program that assigns different values to the variable NAME based on the values of the variables TIME and DATE. The program starts by initializing the variables NAME, TIME, and DATE with empty strings, "NOON", and "Monday" respectively. Th
Question
Given the following pseudocode:
Which of the following would be the output of the program?
Exhibit
Options
- Afoohappy
- Bbarsad
- Cfoosad
- Dbarhappy
How the community answered
(42 responses)- A2% (1)
- B2% (1)
- C88% (37)
- D7% (3)
Explanation
The pseudocode given in the question is a program that assigns different values to the variable NAME based on the values of the variables TIME and DATE. The program starts by initializing the variables NAME, TIME, and DATE with empty strings, "NOON", and "Monday" respectively. Then, it uses two nested IF-ELSE statements to check the values of TIME and DATE and modify the value of NAME accordingly. The first IF-ELSE statement checks if TIME is equal to "NOON". If it is, it sets NAME to "foo". If it is not, it checks if TIME is equal to "MIDNIGHT". If it is, it sets NAME to "bar". If it is not, it does nothing. The second IF-ELSE statement checks if DATE is equal to "Monday". If it is, it concatenates "sad" to the end of NAME. If it is not, it checks if DATE is equal to "Friday". If it is, it concatenates "happy" to the end of NAME. If it is not, it does nothing. Finally, the program prints the value of NAME. Since the values of TIME and DATE are "NOON" and "Monday" respectively, the program will set NAME to "foo" in the first IF-ELSE statement and then add "sad" to it in the second IF-ELSE statement. Therefore, the output of the program will be
Topics
Community Discussion
No community discussion yet for this question.
