Question

In: Computer Science

Write a program that prints a custom conversion table from Celsius temperatures to Fahrenheit and Newton...

Write a program that prints a custom conversion table from Celsius temperatures to Fahrenheit and Newton (Links to an external site.) temperatures. The formula for the conversion from Celsius to Fahrenheit is :

F=9/5*C+32

F is the Fahrenheit temperature, and C is the Celsius temperature.

The formula for the conversion from Celsius to Newton is

C = 100/33*N

N is the Newton Temperature and C is the Celsius temperature

Your C++ program should prompt the user for a lower value and upper value for a range of temperatures in Celsius. It should then prompt the user for the amount they want to increment by. Then use a loop to output to a file named conversion_table.txt a table of the Celsius temperatures and their Fahrenheit and Newton equivalents within the range of values using the increment given by the user. Make sure to format your output to 2 decimal places.

INPUT VALIDATION: Ensure the second number is greater than the first number, and make sure the increment is greater than 0.

PLEASE EXPLAIN. USE DOCUMENTATION.

Solutions

Expert Solution

Code:

#include<iostream>
//as we are using files we have to use this library
#include<fstream>
//as we are using fixed<<serprecision
#include<iomanip>
using namespace std;
int main(){
   //declaring variables
   float lower,upper,increment;
   //celsius,fareheit,newton
   float C,F,N;
   //file object
   ofstream file("conversion_table.txt");
   //taking inputs from user
   cout<<"Enter lower boundary: "<<endl;
   cin>>lower;
   cout<<"Enter upper boundary: "<<endl;
   cin>>upper;
   //input validation
   //if upper boundary is lessthan lower we will promt user to enter
   //upper boundary until the user enters it correctly
   while(upper<lower){
       cout<<"Upper boundary is lessthan Lower, Enter upper boundary again: "<<endl;
       cin>>upper;
   }
   cout<<"Enter increment: "<<endl;
   cin>>increment;
   //input validation
   //if the user enters increment as 0 or negative, we will prompt
   //until he enters a positive
   while(increment<0){
       cout<<"Increment shouldnt be negative or zero, enter again: "<<endl;
       cin>>increment;
   }
   //writing upperboundary,lower boundary and increment to file
   file<<"The Upper Boundary is: "<<upper<<endl;
   file<<"The Lower Boundary is: "<<lower<<endl;
   file<<"The Increment is: "<<increment<<endl;
   file<<"|---------------|---------------|---------------|----"<<endl;
   file<<"|Celsius\t|Farenheit\t|Newton\t\t|"<<endl;
   file<<"|---------------|---------------|---------------|----"<<endl;
   for(float i=lower;i<=upper;i=i+increment){
       //calculating farenheit and newton from celsius
       C=i;
       F=(9.0/5.0)*C+32;
       N = (33.0/100.0)*C;
       //printing 2 decimal places
       file<<"|"<<fixed<<setprecision(2)<<C<<"\t\t|"<<F<<"\t\t|"<<N<<"\t\t|"<<endl;
      
      
   }
   //closing file
   file.close();
}

Output:

Code Screenshot:

Code Snippet:

#include<iostream>
//as we are using files we have to use this library
#include<fstream>
//as we are using fixed<<serprecision
#include<iomanip>
using namespace std;
int main(){
        //declaring variables
        float lower,upper,increment;
        //celsius,fareheit,newton
        float C,F,N;
        //file object
        ofstream file("conversion_table.txt");
        //taking inputs from user
        cout<<"Enter lower boundary: "<<endl;
        cin>>lower;
        cout<<"Enter upper boundary: "<<endl;
        cin>>upper;
        //input validation
        //if upper boundary is lessthan lower we will promt user to enter
        //upper boundary until the user enters it correctly
        while(upper<lower){
                cout<<"Upper boundary is lessthan Lower, Enter upper boundary again: "<<endl;
                cin>>upper;
        }
        cout<<"Enter increment: "<<endl;
        cin>>increment;
        //input validation
        //if the user enters increment as 0 or negative, we will prompt
        //until he enters a positive
        while(increment<0){
                cout<<"Increment shouldnt be negative or zero, enter again: "<<endl;
                cin>>increment;
        }
        //writing upperboundary,lower boundary and increment to file
        file<<"The Upper Boundary is: "<<upper<<endl;
        file<<"The Lower Boundary is: "<<lower<<endl;
        file<<"The Increment is: "<<increment<<endl;
        file<<"|---------------|---------------|---------------|----"<<endl;
        file<<"|Celsius\t|Farenheit\t|Newton\t\t|"<<endl;
        file<<"|---------------|---------------|---------------|----"<<endl;
        for(float i=lower;i<=upper;i=i+increment){
                //calculating farenheit and newton from celsius
                C=i;
                F=(9.0/5.0)*C+32;
                N = (33.0/100.0)*C;
                //printing 2 decimal places 
                file<<"|"<<fixed<<setprecision(2)<<C<<"\t\t|"<<F<<"\t\t|"<<N<<"\t\t|"<<endl;
                
                
        }
        //closing file
        file.close();
}

Related Solutions

Write a JAVA program that displays a table of the Celsius temperatures and their Fahrenheit equivalents....
Write a JAVA program that displays a table of the Celsius temperatures and their Fahrenheit equivalents.  The formula for converting a temperature from Celsius to Fahrenheit is F = 9/ 5 C + 32 where F → Fahrenheit temperature C → Celsius temperature.  Allow the user to enter the range of temperatures in Celsius to be converted into Fahrenheit.  Your program must use a loop to display the values of the temperature conversions (see sample output). Sample...
Write a program that displays a temperature conversion table for degrees Celsius and degrees Fahrenheit. The...
Write a program that displays a temperature conversion table for degrees Celsius and degrees Fahrenheit. The table should include rows for all temperatures between 0 and 100 degrees Celsius that are multiples of 10 degrees Celsius. Include appropriate headings on your columns. The formula for converting between degrees Celsius and degrees Fahrenheit can be found on the internet. Python 3
*In C++ language please* Create a table that converts temperatures from Celsius to Fahrenheit Ask the...
*In C++ language please* Create a table that converts temperatures from Celsius to Fahrenheit Ask the user if they would like to know today's temperatures When "yes": Ask or their name -Generate a random number: use the length of their name (nameLngth) to set the seed Use the length of their name (nameLngth) as the starting point, and 99 as the ending point for a range of Celsius temperatures Output the range of Celsius temperatures alongside the Fahrenheit temperature conversions...
Temperature Converter Create a temperature conversion program that will convert the following to Fahrenheit: Celsius Kelvin...
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....
At what temperatures values are the following scales the same? (a) The Fahrenheit and the Celsius   ...
At what temperatures values are the following scales the same? (a) The Fahrenheit and the Celsius    (b) The Celsius and the Kelvin     (c) The Fahrenheit and the Kelvin  
Instructions Write a program in C# that converts a temperature given in Fahrenheit to Celsius. Allow...
Instructions Write a program in C# that converts a temperature given in Fahrenheit to Celsius. Allow the user to enter values for the original Fahrenheit value. Display the original temperature and the formatted converted value. Use appropriate value returning methods for entering (input), calculating, and outputting results.
Write a java program to convert Celsius degrees to Fahrenheit degrees the user enters degrees in...
Write a java program to convert Celsius degrees to Fahrenheit degrees the user enters degrees in Celsius and the program Coverts the input to Fahrenheit using the following formula T(°F) = T(°C) × 1.8 + 32 submit the source code Design output Load: 1. Design (Pseudocode ) 2. Source file (Java file, make sure to include comments) 3. Output file (word or pdf or jpig file)
Write a function in bash that takes an input temperature (Celsius or Fahrenheit) from the user...
Write a function in bash that takes an input temperature (Celsius or Fahrenheit) from the user converts that temperature Celsius to Fahrenheit, Fahrenheit to Celsius, Celsius to Kelvin and Fahrenheit to Kelvin
Create a table in C of conversion from Celsius to Rankin. Allow the user to enter...
Create a table in C of conversion from Celsius to Rankin. Allow the user to enter the starting temperature and increment between lines. Print 25 lines in the table. Rankin = 9/5(Celsius + 273.15)
****USING BASH**** Write a function that takes an input temperature (Celsius or Fahrenheit) from the user...
****USING BASH**** Write a function that takes an input temperature (Celsius or Fahrenheit) from the user converts that temperature Celsius to Fahrenheit, Fahrenheit to Celsius, Celsius to Kelvin and Fahrenheit to Kelvin.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT