General overview
This program will convert a set of temperatures from Fahrenheit to Celsius and Kelvin.
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 and Kelvin. You need to output the temperatures as Fahrenheit, Celsius, and Kelvin. The numbers should be 18 characters wide with 4 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 two functions with the following signatures:
double toCelsius(double fahrenheit) double toKelvin(double celsius)
Note that the toCelsius function take a parameter that is in fahrenheit. The toKelvin function takes a parameter that is in celsius.
Other functions that you may want to have are:
The headings are also required (see the sample output below).
The conversion from Fahrenheit to Celsius is:
celsius = (fahrenheit - 32) / 1.8
The conversion from Celsius to Kelvin is:
kelvin = celsius + 273.15
Here is a sample run with valid input:
-30 100 20
The output would be:
Fahrenheit Celsius Kelvin -30.0000 -34.4444 238.7056 -10.0000 -23.3333 249.8167 10.0000 -12.2222 260.9278 30.0000 -1.1111 272.0389 50.0000 10.0000 283.1500 70.0000 21.1111 294.2611 90.0000 32.2222 305.3722
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 Kelvin 30.0000 -1.1111 272.0389 35.0000 1.6667 274.8167 40.0000 4.4444 277.5944
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 Kelvin 100.5000 38.0556 311.2056 105.5000 40.8333 313.9833
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?
Expected output
There are eight tests. Each test will have a new set of input data. You must match, exactly, the expected output.
You will get yellow highlighted text when you run the tests if your output is not what is expected. This can be because you are not getting the correct result. It could also be because your formatting does not match what is required. The checking that zyBooks does is very exacting and you must match it exactly. More information about what the yellow highlighting means can be found in course "How to use zyBooks" - especially section "1.4 zyLab basics".
Finally, do not include a system("pause"); statement in your program. This will cause your verification steps to fail.
Note: that the system("pause"); command runs the pause command on the computer where the program is running. The pause command is a Windows command. Your program will be run on a server in the cloud. The cloud server may be running a different operating system (such as Linux).
#include <iostream>
#include<iomanip>
using namespace std;
double toCelsius(double fahrenheit);
double toKelvin(double celsius);
void input_values(double &lower, double &upper, double
&increment);
void print_header();
void display(double fahrenheit, double celsius, double kelvin);
int main()
{
double lower, upper, increment;
// Call function to take input values
input_values(lower, upper, increment);
double fahrenheit = lower;
double celsius, kelvin;
// Print header
print_header();
// Iterate loop till Fahrenheit <= upper
while(fahrenheit<=upper)
{
// Calculate Celsius and Kelvin by calling function
celsius = toCelsius(fahrenheit);
kelvin = toKelvin(celsius);
// Print display function
display(fahrenheit,celsius,kelvin);
// Increment Fahrenheit
fahrenheit+=increment;
}
return 0;
}
// Convert Fahrenheit to Celsius and return
double toCelsius(double fahrenheit)
{
double celsius = (fahrenheit - 32) / 1.8;
return celsius;
}
// Convert Celsius to Kelvin and return
double toKelvin(double celsius)
{
double kelvin = celsius + 273.15;
return kelvin;
}
// Read input values
void input_values(double &lower, double &upper, double
&increment)
{
cin>>lower;
cin>>upper;
cin>>increment;
// Validate input values
// If lower>upper or increment<=0, ask user to enter input
values again
while(lower>upper || increment<=0)
{
cout<<"Starting temperature must be <= ending temperature
and increment must be > 0.0"<<endl;
cin>>lower;
cin>>upper;
cin>>increment;
}
}
void print_header()
{
// Print header
cout<<left<<setw(18)<<"Fahrenheit"<<left<<setw(18)<<"Celsius"<<left<<setw(18)<<"Kelvin"<<endl;
}
void display(double fahrenheit, double celsius, double
kelvin)
{
// Print Fahrenheit, Celsius and Kelvin
// with width 18 and fixed 4 precision
cout<<left<<setw(18)<<fixed<<setprecision(4)<<fahrenheit<<left<<setw(18)<<fixed<<setprecision(4)<<celsius<<left<<setw(18)<<fixed<<setprecision(4)<<kelvin<<endl;
}
OUTPUT
General overview This program will convert a set of temperatures from Fahrenheit to Celsius and Kelvin....
C++ requirements All values must be read in as type double and all calculations need to be done using type double. 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. Failure to follow the C++ requirements could reduce the points received from passing the tests. General overview This program will convert a set...
Temperature Converter Create a temperature conversion program that will convert the following to Fahrenheit: Celsius Kelvin Newton Your program should take a character which represents the temperature to convert from and a value to be converted to using the following specification: C - Celsius K - Kelvin N - Newton In addition your program should take in the following character to exit the program: X - eXit the program The numeric input for your program should be of type double....
You can vary it as long as the fahr and cels temperatures line up vertically and everything is clearly labeled. This program involves inputting a set of Fahrenheit temperatures and performing a set of operations on them: The number of temperatures to input is determined by the user at the beginning of the program. You must ask them to enter the number of temperatures that they will be typing in. This number must be between 1 and 30 (inclusive.) If...
Convert the following temperatures from the Fahrenheit scale to the Celsius and Kelvin scales. (a) The seawater temperature near Hawaii is about 76°F. in Celsius °C in Kelvin К (b) McDonald's was sued for serving dangerously hot coffee. Their coffee was served between 180°F and 190°F. (Give your answers in this part to at least three significant figures.) 180 F in Celsius °C in Kelvin К 190°F: in Celsius °C in Kelvin К (c) The coldest day recorded on Earth...
In Python, write a program that converts Celsius temperatures to Fahrenheit temperatures. The formula is as follows: F=(9/5)C+32 The program should ask the user to enter a temperature in Celsius, then display the temperature converted to Fahrenheit.
Write a program that converts Celsius temperatures to Fahrenheit temperatures. The formula is as follows: F=95C+32 The program should ask the user to enter a temperature in Celsius, and then display the temperature converted to Fahrenheit. I'm doing this on Python.
Convert the following temperatures from the Fahrenheit scale to the Celsius and Kelvin scales. (a) The seawater temperature near Hawaii is about 76°F.(b) McDonald's was sued for serving dangerously hot coffee. Their coffee was served between 180°F and 190°F. (Give your answers in this part to at least three significant figures.) 180°F.(c) The coldest day recorded on Earth was - 129°F in Vostok, Antarctica.
Write a Python program that can convert a Fahrenheit temperature to Celsius, or vice versa. The program should use two custom functions, f_to_c and c_to_f, to perform the conversions. Both of these functions should be defined in a custom module named temps. Custom function c_to_f should be a void function defined to take a Celsius temperature as a parameter. It should calculate and print the equivalent Fahrenheit temperature accurate to three decimal places. Custom function f_to_c should be a value-returning...
FOR PYTHON Write a Python program that can convert a Fahrenheit temperature to Celsius, or vice versa. The program should use two custom functions, f_to_c and c_to_f, to perform the conversions. Both of these functions should be defined in a custom module named temps. Custom functionc_to_f should be a void function defined to take a Celsius temperature as a parameter. It should calculate and print the equivalent Fahrenheit temperature accurate to three decimal places. Custom function f_to_c should be a...
8.) Write a C++ program to convert temperature in degrees Fahrenheit to degrees Celsius. This is the equation for this conversion: Celsius = 5.0/9.0 (Fahrenheit-32.0) Have your program convert and display the Celsius temperature corresponding to 98.6 degrees Fahrenheit. Your program should produce the following display (replacing the underlines with the correct values): For a Fahrenheit temperature of-_ degrees, the equivalent Celsius temperature is degrees