Print Friendly and PDF
(Celsius and Fahrenheit Temperatures) Implement the following integer functions: a) Function celsius returns the Celsius equivalent of a Fahrenheit temperature. b) Function fahrenheit returns the Fahrenheit equivalent of a Celsius temperature. c) Use these functions to write a program that prints charts showing the Fahrenheit equivalents of all Celsius temperatures from 0 to 100 degrees, and the Celsius equivalents of all Fahrenheit temperatures from 32 to 212 degrees. Print the outputs in a neat tabular format that minimizes the number of lines of output while remaining readable.
(Celsius and Fahrenheit Temperatures) Implement the following integer functions:

a) Function celsius returns the Celsius equivalent of a Fahrenheit temperature.

b) Function Fahrenheit returns the Fahrenheit equivalent of a Celsius temperature.

c) Use these functions to write a program that prints charts showing the Fahrenheit equivalents of all Celsius temperatures from 0 to 100 degrees, and the Celsius equivalents of all Fahrenheit temperatures from 32 to 212 degrees. Print the outputs in a neat tabular format that minimizes the number of lines of output while remaining readable.

Solution:

 #include <iostream>
using std::cout;
using std::cin;
 
#include <iomanip>
using std::setprecision;
using std::fixed;
 
double celsius(double);
double fahrenheit(double);
 
int main()
{
   double fahr, cel;
 
   cout << "Calculation formulas:\nC  x  9/5 + 32 = F\n(F  -  32)  x  5/9 = C";
   cout << "\nEnter temperature in fahrenheit: ";
   cin >> fahr;
   cout << "\nIn celsius: " << fixed << setprecision(2) << celsius(fahr);
 
   cout << "\nEnter temperature in celsius: ";
   cin >> cel;
   cout << "\nIn celsius: " << fahrenheit(cel);
   return 0;
}
 
//conversion to celsius
double celsius(double fahr)
{
   return (fahr - 32 ) * 5 / 9;
}
 
//conversion to fahrenheit
double fahrenheit(double cel)
{
   return cel * 9 / 5 + 32;
}
 
 
#include <iostream>
using std::cout;
 
#include <iomanip>
using std::setprecision;
using std::fixed;
 
double fahrenheit(double);
 
int main()
{
   double fahr, cel;
 
   cout << "Celsius\tFahrenheit" << fixed << setprecision(2);
 
   for( cel = 0; cel <= 100; cel++)
   {
      cout << "\n" << cel << "\t" << fahrenheit(cel);
   }
 
   return 0;
}
 
//conversion to fahrenheit
double fahrenheit(double cel)
{
   return cel * 9 / 5 + 32;
}
 
 
zubairsaif

Zubair saif

A passionate writer who loves to write on new technology and programming

Post A Comment:

0 comments: