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...
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.
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:...
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...
Using the program below, overload the Multiply operator to the Rectangle class… this will multiple the...
Using the program below, overload the Multiply operator to the Rectangle class… this will multiple the widths for the 2 Rectangles and multiple the lengths of the two rectangles (similar to how the “+” operator added the widths and lengths of the 2 rectangles). Overload this operator using the non-member method. Please copy-paste code into MS Word document and then show some screenshots of you running and testing this method using your IDE. Using the program below, overload the Divide...
Using class, write a program that: Body Mass Index (BMI) calculation - write a program that...
Using class, write a program that: Body Mass Index (BMI) calculation - write a program that takes users' input (weight and Height) and calculates the BMI. If the result is less than 18.5 display "you are underweight", if the result is greater than 18.5 display "you have a normal weight", if the result is greater than 24.9 display "your weight is considered overweight", and the result is greater than 30 display "your weight is considered as obese" (BMI = 703...
c++ Write the implementation (.cpp file) of the Counter class of the previous exercise. The full...
c++ Write the implementation (.cpp file) of the Counter class of the previous exercise. The full specification of the class is: A data member counter of type int. An data member named counterID of type int. A static int data member named nCounters which is initialized to 0. A constructor that takes an int argument and assigns its value to counter. It also adds one to the static variable nCounters and assigns the (new) value of nCounters to counterID. A...
Write the header and the implementation files (.h and .cpp separatelu) for a class called Course,...
Write the header and the implementation files (.h and .cpp separatelu) for a class called Course, and a simple program to test it, according to the following specifications:                    Your class has 3 member data: an integer pointer that will be used to create a dynamic variable to represent the number of students, an integer pointer that will be used to create a dynamic array representing students’ ids, and a double pointer that will be used to create a dynamic array...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT