Goal: Write a program that provides practice in class development and implementa
ID: 3864542 • Letter: G
Question
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
Explanation / Answer
#include "StackInterface.hpp" #include "Node.hpp" #include #include using namespace std; template class DLinkedStack : public StackInterface { private: Node *headPtr; // Pointer to first node in the chain; Node *topPtr; // Pointer to (last) node in the chain that contains the stack's top public: DLinkedStack(); DLinkedStack(const DLinkedStack &aStack); // Copy constructor virtual ~ DLinkedStack(); // Destructor Node *getPointerTo(const T &target) const; bool isEmpty() const; bool push(const T &newItem); bool pop(); T peek() const; vector toVector() const; Node *getHeadPTR() const; Node *getTopPTR() const; }; template DLinkedStack::DLinkedStack() : headPtr(nullptr), topPtr(nullptr) { } template DLinkedStack::DLinkedStack(const DLinkedStack &aStack) { //TODO - Implement the copy constructor } template DLinkedStack::~DLinkedStack() { //TODO - Implement the destructor } template Node *DLinkedStack::getPointerTo(const T &target) const { //TODO - Return the Node pointer that contains the target(return nullptr if not found) //when there is more than one target exists, return the first target from top. } template bool DLinkedStack::isEmpty() const { //TODO - Return True if the list is empty } template bool DLinkedStack::push(const T &newItem) { //TODO - Push an item on the Doubly Linked Stack } template bool DLinkedStack::pop() { //TODO - Pop an item from the stack - Return true if successful } template T DLinkedStack::peek() const { //Assume this never fails. //TODO - return the element stored at the top of the stack (topPtr) } template vector DLinkedStack::toVector() const { // DO NOT MODIFY THIS FUNCTION vector returnVector; // Put stack items into a vector in top to bottom order Node *curPtr = topPtr; while (curPtr != nullptr) { returnVector.push_back(curPtr->getItem()); curPtr = curPtr->getPrev(); } return returnVector; } template Node *DLinkedStack::getHeadPTR() const { // DO NOT MODIFY THIS FUNCTION return headPtr; } template Node *DLinkedStack::getTopPTR() const { // DO NOT MODIFY THIS FUNCTION return topPtr; }Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.