Thư viện tri thức trực tuyến
Kho tài liệu với 50,000+ tài liệu học thuật
© 2023 Siêu thị PDF - Kho tài liệu học thuật hàng đầu Việt Nam

Supplementary tasks selection statements
Nội dung xem thử
Mô tả chi tiết
1
Chapter 4: Selection Statements
A. Review
A.1. What do we mean “selection” in selection statements? Introduce at least three use contexts of each
kind of selection statements.
A.2. When should we use if..else.. statements instead of conditional expressions? Give an example for
an illustration.
A.3. What is a multi-way decision? Give an example with if..else.. statements and another one with
switch..case.. statements.
A.4. When should we use if..else.. statements instead of switch..case.. statements? Give an example for
an illustration.
A.5. What is the “fall-through” property of switch..case.. statements? Give an example to illustrate this
property.
B. Practice
B.1. Write selection statements that might be used in the solutions of the problems B.1.1 to B.1.15 in
Chapter 1. Remember to write variable declaration statements before the selection statements if there
is any variable in these selection statements.
B.2. For each following description, write a corresponding selection statement.
B.2.1. If the norm of any vector is zero, let the user know that it is unable to find an angle between that
vector with the other.
B.2.2. Increase the unit price by 10 if the stock level goes below 5.
B.2.3. Double the unit price if the stock level is 1. Otherwise, decrease the stock level by 1 and increase
the unit price by its half.
B.2.4. If a date is 13 and its day is Friday, inform that the day is an unlucky day. Otherwise, it is informed
as a normal day.
B.2.5. If time is morning, introduce “orange, lemon, apple, pineapple”. If time is noon, introduce
“watermelon, apple, grape, coconut, banana”. If time is evening, introduce “plum, durian, melon,
mango”. If time is night, introduce “peach, pear, avocado”.
B.2.6. If the user chooses “open a file”, the user is given a form to enter a file name. If the user chooses
“exit the program”, a prompt about saving the current status of the user is given to the user. If the user
chooses “save”, the current status of the user is saved and the program is closed. Otherwise, the current
status of the user is deleted and the program is closed.