Docsity

Homework I - Introduction to Programming | CS 1110, Assignments of Computer Science

Toggle sidebar
bg1
CS 101 Homework 1 Unpledged
CS 101 Page 1 of 2 Spring 2000
Assigned in Laboratory 2, Due Start of Laboratory 3
Please perform the following activities. This assignment is unpledged. However, you may not work with
anyone else on this assignment. You are allowed to talk with others, but your work must be your own.
Objective
The object of this assignment is twofold: to practice coding programs that do interactive input and output,
and to make sure that you understand how to write simple programs that compute useful things. Good pro-
grammers often write small programs to do a short, useful computation.
Problem
Produce a program that computes and displays the apparent Fahrenheit temperature accounting for wind
chill given two user-supplied double-precision floating point inputs: a Fahrenheit temperature T and the
wind velocity V. The velocity is given in miles per hour. There are several slightly different formulas for
computing the wind chill temperature. The formula you will use for your calculation comes from the
National Weather Service and is metric-based. Therefore, after extracting the inputs you will first need to
determine the Celsius equivalent Tc of T and the kilometers per hour equivalent Vk of V. The formula for
computing the wind chill temperature Twc using Tc and Vk is
Because Twc is a Celsius temperature, one more conversion is necessary before displaying the answer to
the user. This conversion computes the Fahrenheit equivalent Tf of Twc.
For your convenience, conversion formulas for Fahrenheit to Celsius, Celsius to Fahrenheit, and miles to
kilometers are given below.
For your information, the home page of the National Weather Service is http://www.nws.noaa.gov/. A
small write-up on wind chill is available at the USA Todayโ€™s weather website at http://www.usatoday.com/
weather/wchilfor.htm.
Besides displaying the wind chill value, your program should supply a legend that warns the user that the
calculated value is inaccurate for wind velocities less than 4 miles per hour. Remember to prompt the user
for the inputs and to echo them in a meaningful fashion.
Notes
You must use our formula and do the conversions. We know that there are non-metric wind chill formulas
out there, but we do not want you to use them. Part of the purpose of this assignment is giving you practice
developing expressions.
As you should know from lecture and your reading of the textbook, C++ has neither a โˆš nor an exponenti-
ation operator. However, C++ does have a mathematics library that contains in part a function sqrt() that
computes square root values. Function sqrt() expects a numerical expression as its argument. The function
returns a double-precision floating-point value that is the square root of its argument expression. For exam-
ple, if x has the value 6.25, then sqrt(x) returns the value 2.5 and if y has the value 3.75 then sqrt(x + y)
Twc 0.0455.27 Vk10.450.28Vk
โ€“+()Tc33โ€“()33+=
CELSIUS
5
9
--- FAHRENHEIT 32โ€“()=
FAHRENHEIT
9
5
--- CELSIUS 32+=
KILOMETERS
1.60934
MILES
=
pf2

Partial preview of the text

Download Homework I - Introduction to Programming | CS 1110 and more Assignments Computer Science in PDF only on Docsity!

CS 101 Homework 1 Unpledged

CS 101 Page 1 of 2 Spring 2000

Assigned in Laboratory 2, Due Start of Laboratory 3

Please perform the following activities. This assignment is unpledged. However, you may not work with anyone else on this assignment. You are allowed to talk with others, but your work must be your own.

Objective

The object of this assignment is twofold: to practice coding programs that do interactive input and output, and to make sure that you understand how to write simple programs that compute useful things. Good pro- grammers often write small programs to do a short, useful computation.

Problem

Produce a program that computes and displays the apparent Fahrenheit temperature accounting for wind chill given two user-supplied double-precision floating point inputs: a Fahrenheit temperature T and the wind velocity V. The velocity is given in miles per hour. There are several slightly different formulas for computing the wind chill temperature. The formula you will use for your calculation comes from the National Weather Service and is metric-based. Therefore, after extracting the inputs you will first need to determine the Celsius equivalent Tc of T and the kilometers per hour equivalent Vk of V. The formula for computing the wind chill temperature Twc using Tc and Vk is

Because Twc is a Celsius temperature, one more conversion is necessary before displaying the answer to the user. This conversion computes the Fahrenheit equivalent Tf of Twc.

For your convenience, conversion formulas for Fahrenheit to Celsius, Celsius to Fahrenheit, and miles to kilometers are given below.

For your information, the home page of the National Weather Service is http://www.nws.noaa.gov/. A small write-up on wind chill is available at the USA Today โ€™s weather website at http://www.usatoday.com/ weather/wchilfor.htm.

Besides displaying the wind chill value, your program should supply a legend that warns the user that the calculated value is inaccurate for wind velocities less than 4 miles per hour. Remember to prompt the user for the inputs and to echo them in a meaningful fashion.

Notes

You must use our formula and do the conversions. We know that there are non-metric wind chill formulas out there, but we do not want you to use them. Part of the purpose of this assignment is giving you practice developing expressions.

As you should know from lecture and your reading of the textbook, C++ has neither a โˆš nor an exponenti- ation operator. However, C++ does have a mathematics library that contains in part a function sqrt () that computes square root values. Function sqrt () expects a numerical expression as its argument. The function returns a double-precision floating-point value that is the square root of its argument expression. For exam- ple, if x has the value 6.25, then sqrt ( x ) returns the value 2.5 and if y has the value 3.75 then sqrt ( x + y )

Twc = 0.045 5.27( Vk +10.45 โ€“ 0.28 Vk ) ( Tc โ€“ 33 ) + 33

CELSIUS^5

= --- ( FAHRENHEIT โ€“ 32 )

FAHRENHEIT^9

= --- CELSIUS + 32

KILOMETERS = 1.60934 MILES

CS 101 Homework 1 Unpledged

CS 101 Page 2 of 2 Spring 2000

returns a value close to 3.1623. To use the sqrt () function, you must instruct the compiler to include the mathematics library when translating your program. You can do so by placing the following include state- ment immediately after your inclusion of the iostream library.

#include

Our conversions formulas for Farhrenheit to Celsius and vice-versa are written in mathematical notation. Remember that we want double-precision floating-point calculations to be performed and not integer cal- culations.

Please review the CS101 style sheet before starting on the assignment. Be sure to use the standard header (i.e., your name, section number, etc.) in your program. The standard header for all of our programs (unless instructed otherwise) will contain the following information:

// Programmer: // Student ID: // E-mail: // CS101 Lab Section: // CS 101 Lab time:

You should submit your program electronically before the start of laboratory 3. See the CS101 website ( http://www.cs.virginia.edu/cs101 ) for information on how to do this. Your program must be called hw01.cpp. All letters in the filename must be lowercase! Do not submit any other files.

You should also turn in a hardcopy (printed copy) at the beginning of your laboratory when the program is due. This hardcopy is due at the beginning of laboratory 3.

The grading criteria for this assignment can also be found at our class website. It will be posted there by the Monday before the assignment is due.

A sample run of the type of output that your program should produce is given below. Observe the legend, nice prompts, and labeled output. The phrasing that you use does not need to exactly mimic this sample, but it does need to be of similar or better quality. In doing your input and output, you must use the standard iostream library. Do not use any console or graphical libraries.