Question

In: Computer Science

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.

Solutions

Expert Solution

#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:


Related Solutions

Your solution must include all supporting calculations and these supporting calculations must be performed with appropriate...
Your solution must include all supporting calculations and these supporting calculations must be performed with appropriate Excel formulas. Failure to do so will result in a reduction in points. For each case, you must submit one printed copy of the Excel spreadsheet which contains your case solution and a second printed copy displaying the formulas contained in each cell of the spreadsheet. Be sure to format your spreadsheet so that your work is clearly presented and easy to review. Wright...
Write a C program that asks the user to enter double values (the values can be...
Write a C program that asks the user to enter double values (the values can be positive, zero, or negative). After entering the first double value, the program asks "Would you like to enter another value?", and if the user enters Y or y, the program continues to get additional values and stores these values into a double array (for up to 100 values — use a symbolic #define constant to specify the 100 size limit). The program will need...
. YOU MUST SHOW ALL CALCULATIONS TO EARN CREDIT.                                   &nbsp
. YOU MUST SHOW ALL CALCULATIONS TO EARN CREDIT.                                                                         2016                            2017 BALANCE SHEETS: Assets:                         Cash                                        120,000                       160,000                         Accounts Receivable               520,000                       620,000                         Inventory                                305,000                       290,000                         Fixed Assets, net                    410,000                       510,000                         Total Assets                           1,355,000                    1,580,000 Liabilities and Equity:                         Accounts Payable                   350,000                       $375,000                         Long-term Debt                      500,000                       625,000                         Common Stock                       50,000                         75,000                         Retained Earnings                   455,000                       505,000                         Total Liabilities and Equity    1,355,000                   ...
I need to write a function the will take in an array (of type double), and...
I need to write a function the will take in an array (of type double), and will return the array with all of the elements doubled while using pass-by-reference and addressing and/or pointers. This is what i have so far, but im messing up in line 31 where i call the function i believe so im not returning the correct array? please help edit. #include <iostream> #include <iomanip> using namespace std; double *doubleArray ( double arr[], int count, int SIZE);...
MUST BE DONE IN C (NOT C++) Using an array and a function, print the values...
MUST BE DONE IN C (NOT C++) Using an array and a function, print the values of an array backwards. Please follow these guidelines: - Setup your array manually (whichever values you want, as many as you want and whichever datatype you prefer). - Call your function. You should send two parameters to such function: the array’s length and the array. - Inside the function, go ahead and print the array backwards. - Your function shouldn’t return anything
Calculate the pH values of the following solutions (you must show the procedure of calculations: a-mole...
Calculate the pH values of the following solutions (you must show the procedure of calculations: a-mole of formic acid and 0.02 mole of NaOH diluted to 1L. (formic acid pK=3.75). b-An aspartic acid solution if the alpha carboxyl is 1/2 dissociated. (aspartic acid pK1= 2.0, pK2=9.9, pKside=3.9)
NO COLLABORATION PERMITTED ON THIS ASSIGNMENT. PLEASE TYPE AND DOUBLE SPACE AND STAPLE. MUST BE HANDED...
NO COLLABORATION PERMITTED ON THIS ASSIGNMENT. PLEASE TYPE AND DOUBLE SPACE AND STAPLE. MUST BE HANDED IN BY YOU AT THE BEGINNING OF CLASS ON THE DUE DATE. NO LATE PAPERS ACCEPTED. Jack leased and operated a barbecue restaurant in Newark, New Jersey (called “Jack’s”). The premises included a bar and dance hall. Bob, a friend of Jack, decided to buy the building from Jack’s landlord Owen. In addition to buying Owen’s building, Bob wanted to purchase Jack’s business, including...
For this question I must see the diagrams and all the calculations. In each case the...
For this question I must see the diagrams and all the calculations. In each case the answer alone will count 2 points. All the % values are based on m/m that means 2% = 2kg/100kg. How much of each of two solutions A and B must be mixed together with 18.5kg of a dry solid to make a final suspension of 2,150 kg containing 8.25% solids. Solution A contains 5.00% solids and solution B contains 11.00% solids.
Programming in C (not C++) ## Requirements Only need to edit the challenge.c You have one...
Programming in C (not C++) ## Requirements Only need to edit the challenge.c You have one function to implement: void fork_exec(char** argv): This takes in an array of strings representing arguments. The first argument is the filename of an executable (which will be given as a relative filepath, such as "./a") The remaining terms would be arguments for said executable. The array is null terminated You need to fork your process. The child needs to call exec (rather, a variant...
The Programming Language is C++ PLEASE, Make sure to read the requirements and grading criteria for...
The Programming Language is C++ PLEASE, Make sure to read the requirements and grading criteria for homework first... Thank you!!! Objective: The purpose of this project is to expose you to: One-dimensional parallel arrays, input/output, Manipulating summation, maintenance of array elements. In addition, defining an array type and passing arrays and array elements to functions. Problem Specification: Using the structured chart below, write a program to keep records and print statistical analysis for a class of students. There are three...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT