Question: This program will convert a set of temperatures from Fahrenheit to Celsius in C++. Your program will be reading in three double values. The first

This program will convert a set of temperatures from Fahrenheit to Celsius in C++.

Your program will be reading in three double values. The first values are starting and ending temperatures. The third value is the increment value. There is no prompt for the input. There is an error message that can be displayed. This is discussed later.

You need to display output for all of the values between the starting and ending values. First two values are temperatures in Fahrenheit. You need to display all of the values from the first temperature to the last temperature. You increment from one temperature to the next by the increment value (the third value you read in). You need to convert these temperatures to Celsius. You need to output the temperatures as both Fahrenheit and Celsius. The numbers should be 15 characters wide with 3 digits of precision and need to be in fixed format. Do not use tab characters (\t) to output the values.

For part 2 you MUST have at least 4 functions, including main. The main function will be the driver of the program. It needs to either do the processing or delegate the work to other functions.

Obviously the main function will have the same function that you have been using for all of your labs. In addition to need to have a function with the following signature:

double convert(double fahrenheit) 

Other functions that you may want to have are:

A function to read in the values

A display function

A display heading function

The headings are also required (see the sample output below).

The conversion from Fahrenheit to Celsius is:

celsius = (fahrenheit - 32) / 1.8

Here is a sample run with valid input:

-30 100 20 

The output would be:

 Fahrenheit Celsius -30.000 -34.444 -10.000 -23.333 10.000 -12.222 30.000 -1.111 50.000 10.000 70.000 21.111 90.000 32.222 

For data validation you need to make sure the first number read in is less than or equal to the second number. The third number read in must be greater than 0. If this is not the case you need to output the following message and read in three new values:

Starting temperature must be <= ending temperature and increment must be > 0.0 

The above message is all one line of output.

You need to keep reading in values and outputting messages until the values are all valid.

Using the following input :

40 30 5 30 40 -5 30 40 5 

We get the output:

Starting temperature must be <= ending temperature and increment must be > 0.0 Starting temperature must be <= ending temperature and increment must be > 0.0 Fahrenheit Celsius 30.000 -1.111 35.000 1.667 40.000 4.444 

Depending on the value for the increment the ending temperature may not be reached. You need to display the temperatures where the value of the Fahrenheit temperature is less than or equal to the ending temperature.

Consider this input:

100.5 110.4 5 

The valid output will be:

 Fahrenheit Celsius 100.500 38.056 105.500 40.833 

The last Fahrenheit temperature output is 105.5. The next one would have been 110.5, but this is more than the ending temperature of 100.4. This is not an error condition. The output would be as above.

Think about what other tests cases are needed? Do we cover all possible input problems or valid types of input values?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!