// File: inclass16.cpp
// This program allows the user to test the Temperature class
//
// Input:  An arbitrary Temperature
// Output: Its Fahrenheit, Celsius and Kelvin equivalents
// ----------------------------------------------------------------------
// Class: CS 210                     Instructor: Dr. Deborah Hwang
// Assignment: In-class exercise for 3/14/06
// Programmer(s): <fill in your name (s)>

#include <iostream>                       // >>, <<, cin, cout, endl
#include "temperature.h"                  // Temperature
using namespace std;

// Function prototypes
void PrintMenu ();

int main()
{
   Temperature theTemperature,
               secondTemperature;           // default construction
   char choice;                             // Menu choice
   double degrees;                          // Variables for user input
   char scale;

   // Read in a temperature
   cout << "Enter a temperature including scale (e.g., 98.6 F): ";
   cin >> theTemperature;

   // Get first action choice
   PrintMenu();
   cin >> choice;

   // Repeat until user wants to quit
   while ((choice != 'Q') && (choice != 'q'))
   {
      // Process choice
      switch (choice)
      {
         case 'A': case 'a':
            theTemperature = Temperature();
            break;
         case 'B': case 'b':
            cout << "Please enter the new degrees and new scale: ";
            cin >> degrees >> scale;
            theTemperature = Temperature (degrees, scale);
            break;
         case 'C': case 'c':
            cout << "The number of degrees is " << theTemperature.Degrees() 
                 << endl;
            break;
         case 'D': case 'd':
            cout << "The scale is " << theTemperature.Scale() << endl;
            break;
         case 'E': case 'e':
            cout << "The Fahrenheit equivalent is " 
                 << theTemperature.Fahrenheit() << endl;
            break;
         case 'F': case 'f':
            cout << "The Celsius equivalent is " 
                 << theTemperature.Celsius() << endl;
            break;
         case 'G': case 'g':
            cout << "The Kelvin equivalent is " 
                 << theTemperature.Kelvin() << endl;
            break;
         case 'H': case 'h':
            cout << "Please enter a second temperature: ";
            cin >> secondTemperature;
            if (theTemperature == secondTemperature)
               cout << "The temperatures are equal\n";
            else
               cout << "The temperatures are not equal\n";
            break;
         case 'I': case 'i':
            cout << "Please enter a second temperature: ";
            cin >> secondTemperature;
            if (secondTemperature < theTemperature)
               cout << "This temperature is lower than the original\n";
            else
               cout << "This temperature is higher or equal to the original\n";
            break;
         case 'J': case 'j':
            cout << "Please enter the number of degrees to add: ";
            cin >> degrees;
            cout << "This would result in a temperature of "
                 << (theTemperature + degrees) << endl;
            break;
         case 'K': case 'k':
            cout << "This would result in a temperature of " 
                 << (-theTemperature) << endl;
            break;
         case 'L': case 'l':
            cout << "Please enter a new temperature: ";
            cin >> theTemperature;
            if (cin.fail())  // in case there was an error
            {
               cout << "Invalid scale.  Temperature unchanged.\n";
               cin.clear();
            }  // end if
            break;
         case 'M': case 'm':
            cout << "The temperature is " << theTemperature << endl;
            break;
         default:
           cout << "Not a valid choice, please try again\n";
      }  // end switch

      // Get next action choice
      PrintMenu();
      cin >> choice;
   }  // end while
   return 0;
}  // end main


// Function: PrintMenu
// Prints a menu of choices
void PrintMenu ()
{
   cout << "\n\nChoose a Temperature operation:\n\n"
        << "   A. Default construction\n"
        << "   B. Explicit construction\n"
        << "   C. Get the number of degrees\n"
        << "   D. Get the scale\n"
        << "   E. Get the Fahrenheit equivalent\n"
        << "   F. Get the Celsius equivalent\n"
        << "   G. Get the Kelvin equivalent\n"
        << "   H. Compare using equality\n"
        << "   I. Compare using less than\n"
        << "   J. Add degrees\n"
        << "   K. Negate temperature\n"
        << "   L. Read a temperature using >>\n"
        << "   M. Print a temperature using <<\n\n"
        << "   Q. Quit program\n\n"
        << "Please enter your choice: ";
}  // end PrintMenu
