Question

In: Computer Science

Goal: Write a program that provides practice in class development and implementation of programs in multiple...

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

Solutions

Expert Solution

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:


Related Solutions

The goal of this project is to practice (Write a C Program) with a function that...
The goal of this project is to practice (Write a C Program) with a function that one of its parameter is a function.The prototype of this function is: void func ( float (*f)(float*, int), float* a, int length); This means the function: func has three parameters: float (*f)(float*, int): This parameter itself is a function: f that has two parameters and returns a floating-point number. In the body of the function: func we call the function: f with its arguments...
The goal of this assignment is to write five short Java/Pyhton programs to gain practice with...
The goal of this assignment is to write five short Java/Pyhton programs to gain practice with expressions, loops and conditionals. Boolean and integer variables and Conditionals. Write a program Ordered.java that reads in three integer command-line arguments, x, y, and z.   Define a boolean variable isOrdered whose value is true if the three values are either in strictly ascending order  (x < y < z) or in strictly descending order  (x > y > z), and false otherwise. Print out the variable isOrdered...
JAVA Write a class for a Stack of characters using a linked list implementation. Write a...
JAVA Write a class for a Stack of characters using a linked list implementation. Write a class for a Queue of characters using a linked list implementation. Write a class for a Queue of integers using a circular array implementation.
Write the programs in JavaScript: Write a program that reads a text file and outputs the...
Write the programs in JavaScript: Write a program that reads a text file and outputs the text file with line numbers at the beginning of each line.
Write in Python and as 2 seperate programs Write a program that allows the user to...
Write in Python and as 2 seperate programs Write a program that allows the user to enter the total rainfall for each of 12 months into a LIST. The program should calculate and display the total rainfall for the year, the average monthly rainfall, and the months with the highest and lowest rainfall amounts. Data: January 7.9 inches February 10.1 inches March 3.4 inches April 6.7 inches May 8.9 inches June 9.4 inches July 5.9 inches August 4.1 inches September...
This assignment is 2 programs demonstrating IF statements and Decisions. Program 1 Write a program that...
This assignment is 2 programs demonstrating IF statements and Decisions. Program 1 Write a program that asks a user for a temperature for two storage containers for a spaceship filled with water and oxygen. The program should tell if either is ice and if either is boiling. Numbers to use for your tests The Freezing point of water is 32 and the boiling point is 212. The Freezing point of oxygen is -362 and the boiling point is -306. Program...
Focuses on the design, development, implementation, and testing of a Python program using Jupyter Notebook only...
Focuses on the design, development, implementation, and testing of a Python program using Jupyter Notebook only to solve the problem described below. You will write a program that simulates an Automatic Teller Machine (ATM). For this program, your code can have of user-defined functions only. However, the program must not call on any external functions or modules to handle any of the input, computational, and output requirements. Note, the program can be completed without the use of user-defined functions. Requirements:...
Task You will write a class called Grid, and test it with a couple of programs....
Task You will write a class called Grid, and test it with a couple of programs. A Grid object will be made up of a grid of positions, numbered with rows and columns. Row and column numbering start at 0, at the top left corner of the grid. A grid object also has a "mover", which can move around to different locations on the grid. Obstacles (which block the mover) and other objects (that can be placed or picked up)...
Write a MIPS program that uses an implementation of quick sort to sort an array of...
Write a MIPS program that uses an implementation of quick sort to sort an array of numbers (Translate the following code into (Mars Assembly language). Quicksort Implementation - C int partition(int arr [] , int left , int right) { int i=left, j=right; int tmp; int pivot = arr[(left + right) / 2]; while (i <= j) { while (arr [ i ] < pivot) i ++; while (arr [ j ] > pivot) j −−; if (i <= j)...
Ch 5 Program 1: Sphere.java                Complete the implementation of the Sphere class based on the Diagram...
Ch 5 Program 1: Sphere.java                Complete the implementation of the Sphere class based on the Diagram below. Use the DecimalFormat class in Sphere.java to format your output in the toString method. Then download the tester application SphereTester.java from canvas to test your Sphere class. Do not change SphereTester.java. Sphere private double radius //radius of the sphere object private static int numSpheres //static or class variable. All Sphere objects share it public Sphere() //constructor . Initialize Sphere objects’ instance variable radius...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT