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...
Which of the following would be the best choice for a primary key?
A) Social Security Number B) Last Name C) Street Address D) First Name
How does configuration of wireless clients for wireless access in an enterprise environment differ from normal setup?
What will be an ideal response?
The do...while loop is a pretest loop.
Answer the following statement true (T) or false (F)
?Isolated single-bit errors occur ____ percent of the time.
A. ?30 to 40 B. ?40 to 50 C. ?50 to 60 D. ?60 to 70