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.
```
// Fahrenheit and Celsius equivalents.
#include
#include
using namespace std;
int celsius( int ); // function prototype
int fahrenheit( int ); // function prototype
int main()
{
// display table of Fahrenheit equivalents of Celsius temperatures
cout << "Fahrenheit equivalents of Celsius temperatures:" << endl;
// create 4 sets of table headers
for ( int t = 0; t < 4; t++ )
cout << setw( 7 ) << "Celsius" << setw( 12 ) << "Fahrenheit ";
cout << endl;
// display temperatures in blocks of 25
for ( int i = 0; i < 25; i++ )
{
for ( int j = 0; j <= 75; j += 25 )
cout << setw( 7 ) << i + j
<< setw( 11 ) << fahrenheit( i + j ) << ' ';
cout << endl;
} // end for
// display equivalent for 100
cout << setw( 64 ) << 100 << setw( 11 ) << fahrenheit( 100 ) << endl;
// display table of Celsius equivalents of Fahrenheit temperatures
cout << "\nCelsius equivalents of Fahrenheit temperatures:" << endl;
// create 4 sets of table headers
for ( int t = 0; t < 4; t++ )
cout << setw( 10 ) << "Fahrenheit" << setw( 9 ) << "Celsius ";
cout << endl;
// display temperatures in blocks of 45
for ( int i = 32; i < 77; i++ )
{
for ( int j = 0; j <= 135; j += 45 )
cout << setw( 10 ) << i + j
<< setw( 8 ) << celsius( i + j ) << ' ';
cout << endl;
} // end for
// display equivalent for 212
cout << setw( 67 ) << 212 << setw( 8 ) << celsius( 212 ) << endl;
} // end main
// celsius returns Celsius equivalent of fTemp,
// given in Fahrenheit
int celsius( int fTemp )
{
return static_cast< int > ( 5.0 / 9.0 * ( fTemp - 32 ) );
} // end function celsius
// fahrenheit returns Fahrenheit equivalent of cTemp,
// given in Celsius
int fahrenheit( int cTemp )
{
return static_cast< int > ( 9.0 / 5.0 * cTemp + 32 );
} // end function fahrenheit
```
You might also like to view...
To format data, use the Property Sheet window pane
Indicate whether the statement is true or false
The stream that is used for input from the keyboard is called ___________.
Fill in the blank(s) with the appropriate word(s).