language: c++ Lesson 6 has two parts. Part 2 is worth 50 points (40 points runni
ID: 3598813 • Letter: L
Question
language: c++
Lesson 6 has two parts.
Part 2 is worth 50 points (40 points running the tests and 10 for your program formatting, comments, and variable names). You will be developing and testing with an IDE and them uploading the solution to zyBooks/zyLabs. Failure to meet the requirements could result in loss of points beyond the 10 for the code formatting, variable names, and so on.
You can only run the submit mode tests 20 times (or less). If you find any errors while in submit mode you will have to go back to your IDE and update your program, test to make sure you have fixed the problems and upload a new version to zyBooks/zyLabs.
This program will convert a set of temperatures from Fahrenheit to Celsius.
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 ( ) to output the values.
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:
The output would be:
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:
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 :
We get the output:
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:
The valid output will be:
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?
Explanation / Answer
#include <iostream>
#include <iomanip>
using namespace std;
int main() {
double start_temp,end_temp,incr,fahrenheit,celsius;
//input starting and ending temperatures in Fahrenheit and increment value
cout<<"Enter the starting temperature,ending temperature in Fahrenheit and increment value : ";
cin>>start_temp>>end_temp>>incr;
cout<<fixed<<setprecision(3);// iomanip functions to set precision
cout<<" "<<left<<setw(15)<<"Fahrenheit"<<right<<setw(15)<<"Celsius";
for(fahrenheit = start_temp;fahrenheit <= end_temp; fahrenheit= fahrenheit+incr)
{
celsius = (fahrenheit - 32) / 1.8; //conversion formula
cout<<" "<<left<<setw(15)<<fahrenheit<<right<<setw(15)<<celsius;
}
return 0;
}
Output:
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.