Programming Assignment #2

Due: Mon, Sept 30 (revised)

Objective:  This assignment will provide further practice with implementing classes.

Task:  For this homework, you will write a class called Temperature, in the files temperature.h and temperature.cpp, for creating and using objects that will store temperatures (like for weather forecasting programs).

This class should be portable, so it should work with any up-to-date C++ compiler. Make sure that it works with g++ on linprog.cs.fsu.edu before you hand it in. You should write some test programs of your own to test the functionality of the class.

Program Details and Requirements:

1) An object of type Temperature should represent a temperature in terms of degrees and scale. Degrees should allow decimal precision (so use type double). The three scales possible are Celsius, Fahrenheit, and Kelvin. You may store the scale however you like inside the object, but for any keyboard input or function parameters, scales will come in as type char, where 'C', 'F', 'K' (as well as the lower case versions) are valid options. Your object must always represent a valid temperature -- remember that 0 Kelvin represents the lowest possible temperature in existence (the complete absence of heat). Your object should also store a format setting, to be used for display of temperatures to the screen.  There will be more than one possible format.  The class features (public interface) should work exactly as specified, regardless of what program might be using Temperature objects.

Note: For purposes of conversions between scales, please remember the following conversion relationships betweeen temperatures:

2) Your Temperature class must provide the following services (i.e. member functions) in its public section.  These functions will make up the interface of the Temperature class.  Make sure you use function prototypes as specified here.  (You may write any other private functions you feel necessary, but the public interface must include all the functionality described here).

3) General Requirements:

Extra Credit:

Add the following member function to your class:

void Increment(int deg, char sc)
This function should move the temperature forward by the number of degrees given IN the scale given. However, the resulting object should remain in the original scale representation.
Examples:

  Temperature t1(20.5, 'C');		// 20.5 Celsius

  t1.Increment(3, 'C');		// add 3 degrees Celsius to the current 
				//   temperature. t1 is still in celsius.
  t1.Increment(6, 'F');		// add 6 degrees Fahrenheit to the 
				//   current temperature.  t1 is still 
      				//   represented in Celsius.


Testing Your Class:

You will need to test your class, which means you will need to write one or more main programs that will call upon the functionality (i.e. the public member functions) of the class and exercise all of the different cases for each function.  You do not need to turn any test programs in, but you should write them to verify your class' features.  Here is the beginning of a sample test program to get you started.  Note - this one does not exercise every possible test case -- it is your job to test your class thoroughly.
 

Submitting:

Submit the following files (using the usual web submission procedure):
  temperature.h
  temperature.cpp