Documente Academic
Documente Profesional
Documente Cultură
CASE STUDY
Problem
Many programs need input from users. Based on this input, the
program will display an appropriate message. This message will give
the users an indication about the type or choice of input needed by the
program.
One technique of interaction between a program and its user is using
the menu. The menu is a list of items that can be selected by the user.
Once the menu is displayed, the program will wait for the user to input
his or her choice. After the user has chosen the item, the program will
continue processing based on that item.
In this section, we will develop a program that will do these
conversions:
The program will display a menu to get the type of conversion required.
Once that is done, it will ask the user for the input to be converted, do
the calculation and then display the result. After that, the program will
display the menu again and the process will continue until the user
decides to stop the program.
Analysis
The following formula is used to do the conversions:
1 hour
=
1 feet
=
1 Celsius =
60 minutes
0.3048 metres
(5/9) * (Fahrenheit 32)
Design
The menu to be displayed by the program is based on the selection
listed in Table 2.1:
Table 2.1: Menu
Choice Code
Conversion Type
Minutes to hours
Feet to metres
Fahrenheit to Celsius
Program ends
Explanation
choice
minutes
hours
feet
metres
fahrenheit
celsius
Start_IF
Input fahrenheit from the user
Calculate celsius
Display fahrenheit and celsius
End_IF
3.0
Until (choice NOT 0)
4.0 End
The flow chart for the above pseudo-code is given below in Figure
2.6:
Start
Display menu
Input choice
choice
==1
Yes
Input
minutes
Calculate hours
Display minutes
& hours
No
choice
==2
Yes
Input feet
Calculate metres
Calculate celsius
Display fheit
& celsius
No
choice
==3
Yes
Input
fheit
No
choice
==0
No
Yes
End