This section gives you some suggested answers to the questions in Lab 1.2, with discussion related to how those answers resulted. The most important thing to realize is whether your answer works. You should figure out the implications of the answers here and what the effects are from any different answers you may come up with. 1.2.1 Answers
The test conditions of this selection structure use the operator IN. This operator allows you to construct the list of valid months for every season. It is important to understand the use of the parentheses. In this case, it is not done for the sake of a syntax rule. This use of parentheses allows us to define clearly the list of values for a specific month, hence helping us to outline the logic of the structure. Now, consider the following fragment of the selection structure: IF MONTH IS 'DECEMBER' IT IS WINTER IF MONTH IS 'JANUARY' IT IS WINTER IF MONTH IS 'FEBRUARY' IT IS WINTER This selection structure results in the same outcome, yet it is much longer. As a result it does not look well structured, even though it has been formatted properly.
Assume that you are starting your week on Monday ”there are six days left. Next, you will display the name of the current day of the week, which is Monday for the first iteration. Then, you move to the next day. The next day is Tuesday, and there are five more days in the week. So, you will display the name of the current day ”Tuesday ”and move to the next day, and so forth. Once the name of the seventh day (Sunday) has been displayed, the iteration structure has completed.
This structure is a combination of two structures: iteration and selection. The iteration structure will repeat its steps for each day of the week. The selection structure will display the name of the current day or the message "The weekend is...." Assume that you are starting your week on Monday again. There are six days left. Next, control of the flow is passed to the selection structure. Because the current day happens to be Monday, and it falls within the business week, its name is displayed. Then, control of the flow is passed back to the iteration structure, and you are ready to move to the next day. The next day is Tuesday, and there are five more days in the week. So, control is passed to the iteration structure again. Tuesday also falls within the business week, so its name is displayed as well. Next, control is passed back to the iteration structure, and you go to the next day, and so forth. Once the day falls on the weekend, the message "The weekend is . . ." is displayed. 1.2.2 Answers
|