Question

C++ requirements All values must be read in as type double and all calculations need to...

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 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 (\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?

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.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <iostream>
#include <iomanip>

using namespace std;

int main() {
   double start =0;
   double end = 0;
   double inc =0;
   //Getting the inputs from user
   cin>>start;
   cin>>end;
   cin>>inc;
   //Validating the inputs
   while(start>end || inc<0){
   cout<<"Starting temperature must be <= ending temperature and increment must be > 0.0"<<endl;
   cin>>start;
   cin>>end;
   cin>>inc;
   }
   //Printing out the results
   double temp = start;
   cout<<"Fahrenheit\tCelsius"<<endl;
   while (temp<=end){
   double cel = (temp- 32) * 5 / 9;
   cout<<setprecision(4)<<temp<<"\t"<<setprecision(4)<<cel<<endl;
   temp = temp + inc;
   }
   return 0;
}

Output:

40 30 5 Starting temperature must be <= ending temperature and increment must be > 0.0 30 40-5 Starting temperature must be e

Add a comment
Know the answer?
Add Answer to:
C++ requirements All values must be read in as type double and all calculations need to...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • General overview This program will convert a set of temperatures from Fahrenheit to Celsius and Kelvin....

    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...

  • Write a program in C++ that gives the temperature of earth at a depth. It must...

    Write a program in C++ that gives the temperature of earth at a depth. It must be in C++ and follow the information below: Problem description Write a program to take a depth in kilometers inside the earth as input data; calculate and display the temperature at this depth in both degrees Celsius and degree Fahrenheit. The formulas are: Celsius temperature at depth in km: celsius = 10 x depth(km) + 20 Convert celsius to fahrenheit: fahrenheit = 1.8 x...

  • 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...

    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...

  • Write a program in C that will convert all 12 months' average temperature from Celsius to...

    Write a program in C that will convert all 12 months' average temperature from Celsius to Fahrenheit. You need to create an array named aye jump and prompt the user to input average temperature in Celsius for all 12 months. After that, you need to develop a user temperatures from Celsius to Fahrenheit and pass the array as reference and convert all temperatures from Celsius to Fahrenheit. Next, compute the average temperature of the year and assign it to a...

  • In this project you will create a console C++ program that will have the user to...

    In this project you will create a console C++ program that will have the user to enter Celsius temperature readings for anywhere between 1 and 365 days and store them in a dynamically allocated array, then display a report showing both the Celsius and Fahrenheit temperatures for each day entered. This program will require the use of pointers and dynamic memory allocation. Getting and Storing User Input: For this you will ask the user how many days’ worth of temperature...

  • C++ requirements The store number must be of type unsigned int. The sales value must be...

    C++ requirements The store number must be of type unsigned int. The sales value must be of of type long long int. Your program must properly check for end of file. See the section Reading in files below and also see your Gaddis text book for details on reading in file and checking for end of file. Your program must properly open and close all files. Failure to follow the C++ requirements could reduce the points received from passing the...

  • Can you help me to create this program, please? Prompt the user for the user for...

    Can you help me to create this program, please? Prompt the user for the user for a number of degrees in Fahrenheit as an int. That number should be passed to a function named ffocREFO. This function will do the necessary calculation to convert the passed temperature to degrees Celsius as a double. The function MUST have a void return type and have the following prototype: void ffccREF(double& celsius, int Faren); In your main, display both the entered temperature and...

  • Use C++ and must be abke to compile on Visual Studios 9:27 ToDo Final Exam Grade...

    Use C++ and must be abke to compile on Visual Studios 9:27 ToDo Final Exam Grade Detail You need to implement C++ code that will read data from a file and process it as outlined below and write the processed data to an output file. You can refer to the file input.txt for how the data is made available to you and output.txt for how to write out the processed data. Your code will be tested using an input file...

  • The name of the C++ file must be search.cpp Write a program that will read data...

    The name of the C++ file must be search.cpp Write a program that will read data from a file. The program will allow the user to specify the filename. Use a loop that will check if the file is opened correctly, otherwise display an error message and allow the user to re-enter a filename until successful. Read the values from the file and store into an integer array. The program should then prompt the user for an integer which will...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT