Selection Exercises: Exercise 1 Room Thermostat Problems

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 1

SELECTION EXERCISES

Exercise 1 Room thermostat problems


The following problems give you opportunities to practice using constants (that is, minimum and
maximum desirable temperatures) and relational operators using integers, and to make simple
decisions using if and if/else statements. You will also need to consider the checking of boundary
values and appropriate test data for each problem.

Sam runs a restaurant He notices that the room temperature in his restaurant is sometimes too
cold and sometimes too hot. He would like to use his personal computer to alert him when to
switch on the heating or air-conditioning. Sam thinks 19 oC is about the right minimum room
temperature for his restaurant.

 You have been given the task of developing a program that displays a message alerting Sam
when to switch on the heating or air-conditioning.

You are asked to develop the program design in stages in activities 1.1 and 1.2 that will alert
Sam when to switch on the heating.

In one of the forum exercises for Selection part 2, you will be asked to further extend the
functionality of your design to alert Sam when to switch on the air-conditioning.

Activity 1.1 Room thermostat control using a single if statement


Design an algorithm in structured English that prompts a user to type in the room temperature. It
should check if the room temperature is less than ‘minimum’ temperature set, then display an
appropriate message such as ‘Too cold – switch on the heating!’. Otherwise no further action is
needed.

Create the program.

You should post your solutions as a reply to a thread created for the purpose.

Activity 1.2 Room thermostat using an if/else statement


Design a solution in structured English that prompts a user to type in the room temperature. It
should check if the room temperature is less than ‘minimum’ temperature set, then display an
appropriate message about it being cold, or display an appropriate message about it being warm.

Create the program.

You should post your solutions as a reply to a thread created for the purpose.

 Challenges:

1. A problem exists with the final program design after you have completed Activity 1.2, if
we follow the given specification exactly. Can you find the problem and discuss this in the
forum?
2. Think about how you might redesign your solution in structured English to check for an
invalid value entered by a user (for example, a number followed by a character such as
1#) using a simple if statement. Hint: If the room temperature is not an integer, then
display a message about the user's input being an invalid integer. You should post your
solutions as a reply to a thread created for the purpose.

You might also like