In: Computer Science
Goal: Write a program that provides practice in class development and implementation of programs in multiple separate files. Make sure you thoroughly read and understand the directions before you begin PART 1: Write a program that displays a temperature conversion chart. There should be 6 functions defined as part of a class. • print_introduction_message • get_conversion_table_specifications • print_message_echoing_input • fahrenheit_to_celsius • fahrenheit_to_kelvin • print_table A portion of the code is defined below but not using classes. Add the 4 missing function prototypes and the 4 missing function definitions. Add any private or public variables to the class definition that you decide is needed to complete the program Note To convert temperatures values written in Fahrenheit to Celsius, you subtract 32, multiply by 5 and then divide by 9. To convert Celsius to Kelvin, you add 273.15. /* This program prints out a conversion table of temperatures, after prompting the user for upper and lower bounds of the table in Fahrenheit, and the temperature difference between table entries. */ #include using namespace std; int main() { int lower = 0; /* the lowest Fahrenheit entry in the table */ int upper = 0; /* the highest Fahrenheit entry in the table */ int step = 1; /* difference in Fahrenheit between entries */ /* print a message explaining what the program does: */ print_introduction_message(); /* prompt the user for table specifications in Fahrenheit: */ get_conversion_table_specifications(lower, upper, step); /* print appropriate message including an echo of the input: */ print_message_echoing_input(lower, upper, step); /* Print the table (including the column headings): */ print_table(lower, upper, step); return 0; } /* FUNCTION TO CONVERT FAHRENHEIT TO CELSIUS */ double fahrenheit_to_celsius (int fahr) { return (static_cast(5)/9) * (fahr - 32); } /* FUNCTION TO CONVERT FAHRENHEIT TO KELVIN VALUE */ double fahrenheit_to_kelvin (int fahr) { return ((static_cast(5)/9) * (fahr - 32)) + 273.15; } The program should produce output as given below. Test your program with various inputs. Example output: This program prints out a conversion table of temperatures. Enter the minimum (whole number) temperature you want in the table, in Fahrenheit: 0 Enter the maximum temperature you want in the table: 100 Enter the temperature difference you want between table entries: 20 Temperature conversion table from 0 Fahrenheit to 100 Fahrenheit, in steps of 20 Fahrenheit: Fahrenheit Celsius Kelvin 0 -17.78 255.37 20 -6.67 266.48 40 4.44 277.59 ... ...... ...... ... ...... ...... 300 148.89 422.04 PART 2: Split the program solution for Part 1 into three files: • a main program file, conversion_main.cpp • a header file called "conversions.h" for the functions " fahrenheit_to_celsius (...)" and " fahrenheit_to_kelvin (...)" • an implementation file, “conversion.cpp” for the prior two mentioned functions. Again, test your program with various inputs. Program Specifications The program you develop must have the following characteristics: • It must contain functions • It must contain prototypes • It must contain class definitions and include private variables in the class • It must be commented adequately o Label the section of the program where the prototypes are o Label each function call o Before each function, give a brief description of what the function will do • It must contain adequate names for each function • It must be split into the indicated files with appropriate filename convention
Here is the code for Conversion.h:
#include <iostream>
using namespace std;
class Conversion
{
int lower; /* the lowest Fahrenheit entry in the
table */
int upper; /* the highest Fahrenheit entry in the
table */
int step; /* difference in Fahrenheit between entries
*/
public:
void
print_introduction_message();
void
get_conversion_table_specifications();
void print_message_echoing_input();
double
fahrenheit_to_celsius(int);
double fahrenheit_to_kelvin(int);
void print_table();
};
The code for Conversion.cpp is:
#include "Conversions.h"
#include <iomanip>
void Conversion::print_introduction_message()
{
cout << "Welcome to Temperature
Conversions..." << endl;
}
void Conversion::get_conversion_table_specifications()
{
cout << "Enter the lower value of
fahrenheit: ";
cin >> lower;
cout << "Enter the upper value of
fahrenheit: ";
cin >> upper;
cout << "Enter the step values to
increment: ";
cin >> step;
}
void Conversion::print_message_echoing_input()
{
cout << "You chosen to print the values
from " << lower << " to " << upper << "
with a step of " << step << endl;
}
/* FUNCTION TO CONVERT FAHRENHEIT TO CELSIUS */
double Conversion::fahrenheit_to_celsius (int fahr)
{
return (static_cast<double>(5)/9) * (fahr
- 32);
}
/* FUNCTION TO CONVERT FAHRENHEIT TO KELVIN VALUE */
double Conversion::fahrenheit_to_kelvin (int fahr)
{
return ((static_cast<double>(5)/9) * (fahr
- 32)) + 273.15;
}
void Conversion::print_table()
{
cout << "Fahrenheit\tCelsius\tKelvin"
<< endl;
for(double i = lower; i <= upper; i +=
step)
{
cout << i << "\t"
<< fixed << setprecision(2) <<
fahrenheit_to_celsius(i) << "\t";
cout << fixed <<
setprecision(2) << fahrenheit_to_kelvin(i) <<
endl;
}
}
And the code for ConversionDemo.cpp is:
/* This program prints out a conversion table of temperatures,
after prompting the user
for upper and lower bounds of the table in Fahrenheit, and the
temperature difference
between table entries. */
#include "Conversions.cpp"
using namespace std;
int main()
{
Conversion cnv;
/* print a message explaining what the program does:
*/
cnv.print_introduction_message();
/* prompt the user for table specifications in
Fahrenheit: */
cnv.get_conversion_table_specifications();
/* print appropriate message including an echo of the
input: */
cnv.print_message_echoing_input();
/* Print the table (including the column headings):
*/
cnv.print_table();
return 0;
}
And the output screenshot is: