sampleLabQuiz_D201_D..

advertisement
SAMPLE LAB QUIZ, CMPT128 D201 and D202
Oct. 8, 2015 (8:30)
Write a program to calculate the outdoor temperature including wind-chill. Your program should read
the outdoor temperature (temperature) and the wind velocity (windVel). Your program should then
print a message indicating the outdoor temperature including wind-chill. Be sure to write the code so
that it conforms to the course coding standard. Coding Standards are available through a shortcut to a
folder on the upper left corner of your exam account desktop.
You do not need to check if inputs are of the correct data type. You do need to check the inputs have
reasonable values (are within specified ranges). You should comment your code.
To calculate the temperature including wind-chill
1) Include the math library <cmath>, windVel 0.16 can then be coded as pow( windVel, 0.16 )
2) If the wind velocity is 4.8 km/hr or less the temperature with wind-chill is the same as the
temperature without wind chill
3) If the wind velocity is larger than 4.8 km/hr then the temperature with wind-chill
(withWindChill) is calculated according to the following equation
饾懁饾憱饾憽鈩庰潙婐潙栶潙涴潙戰潗垛剮饾憱饾憴饾憴 = 13.12 + 0.6215 ∗ 饾憽饾憭饾憵饾憹饾憭饾憻饾憥饾憽饾憿饾憻饾憭 + (0.3965 ∗ 饾憽饾憭饾憵饾憹饾憭饾憻饾憥饾憽饾憿饾憻饾憭 − 11.37) ∗
饾懁饾憱饾憶饾憫饾憠饾憭饾憴0. 16
First, you must prompt for the temperature in degrees Celsius, temperature. The variable holding the
temperature must be an integer (-40 <= temperature <= 10). Next, you must prompt for and read the
wind velocity in km/hr (0.0 to 200.0 inclusive). Next, you should calculate temperature including windchill. Finally you should print the temperature including wind-chill.
The following examples provide a test plan and examples of the format of the desired output. The
information about the wind-chill illustrated below is correct; you can use the examples below to test
your program. Text files containing these results are available to you through a shortcut to a folder on
the upper left corner of your exam account desktop.
Your program must print out the information using the EXACT formats and messages illustrated in the
examples below. In each of the examples the temperature and wind velocity you type into your
program are shown is bold type. You do not need to display these numbers in bold type in your
outputs.
Remember that you can check if your output matches EXACTLY using diffMerge
When printing the values of the minimum and maximum temperature and wind velocity please assure
that if the value of any constant is changed the output limits printed below would also change.
1) Invalid temperature (too large )
Enter the temperature (integer) without windchill: 31
The temperature entered was not valid -40 <= temperature <= 10
2) Invalid temperature (too small)
Enter the temperature (integer) without windchill: -56
The temperature entered was not valid -40 <= temperature <= 10
3) Negative wind speed
Enter the temperature (integer) without windchill: -17
Enter the wind velocity in km/hr:
-4.2
Wind speed cannot be negative
4) Wind speed to high (too large)
Enter the temperature (integer) without windchill: 5
Enter the wind velocity in km/hr:
225.5
Wind speed cannot exceed 200.00 km/hr
5) For wind speed < 4.8 km/s
Enter the temperature (integer) without windchill: 2
Enter the wind velocity in km/hr:
2.4
The temperature is 2
The wind speed is 2.4 km/hr
There is no windchill because wind velocity is too low
The total temperature with windchill is 2.00
6) For wind speed >= 4.8 km/s
Enter the temperature (integer) without windchill: -23
Enter the wind velocity in km/hr:
48.6
The temperature is -23
The wind speed is 48.6 km/hr
The total temperature with windchill is -39.32
Download