/* C++ Programming, Example answer, Exercise 4, Sheet 5  */

/* Author: Rob Miller and William Knottenbelt
   Program last changed: 3 October 2011  */
   
/* This program prints a table of shop closing times */

#include <iostream>
using namespace std;

enum Day {Sun, Mon, Tue, Wed, Thu, Fri, Sat};

/* DECLARATION OF FUNCTION TO GENERATE SHOP CLOSING TIMES FROM DAY OF THE WEEK */
int closing_time(Day day_of_the_week);

/* DECLARATION OF FUNCTION TO PRINT DAY */
void print_day(Day _day, ostream &out_stream);

/* MAIN PROGRAM */
int main() 
{
  int count; 

  /* Print table heading */
  cout.setf(ios::left);
  cout.width(19);
  cout << "DAY";
  cout << "CLOSING TIME" << endl << endl;

  /* print table from Sunday to Saturday */
  for (count = static_cast<int>(Sun) ; count <= static_cast<int>(Sat) ; count++) {
    cout.width(19);
    print_day(static_cast<Day>(count), cout);
    cout << closing_time(static_cast<Day>(count)) << "pm\n";
  }
	
  return 0;
}
/* END OF MAIN PROGRAM */


/* 
We can't simply replace the "switch" statement in the previous program
by the statement

	 cout << static_cast<Day>(count);
	 
because the library defining "<<" hasn't got any information about
how to display data of type "Day" on the screen (we only just invented
the type "Day").
*/


/* FUNCTION TO PRINT DAY */
void print_day(Day _day, ostream &out_stream)
{
  switch (_day) {
  case Sun:		out_stream << "Sunday"; break;
  case Mon:		out_stream << "Monday"; break;
  case Tue:		out_stream << "Tuesday"; break;
  case Wed:		out_stream << "Wednesday"; break;
  case Thu:		out_stream << "Thursday"; break;
  case Fri:		out_stream << "Friday"; break;
  case Sat:		out_stream << "Saturday"; break;
  default:		out_stream << "ERROR!";
  }
}
/* END OF FUNCTION */

/* FUNCTION TO GENERATE SHOP CLOSING TIMES FROM DAY OF THE WEEK */
int closing_time(Day day_of_the_week)
{	
  switch (day_of_the_week) {
  case Sun:	return 1;
  case Wed:	return 8;
  case Sat:	return 5;
  default:	return 6;
  }
}
/* END OF FUNCTION */


