/* enum1.cpp -- Starting to use enumerated types: Printing for each 
 *              day of the week, today, yesterday, and tomorrow, both
 *              as a string and as a number. You cannot read or write
 *              directly enumerated values. You have to read/write
 *		integers and convert them to/from the enum. Or you
 *		read/write strings doing conversions to enum yourself.
 */

#include <iostream>

// Introducing an enumerated data type
enum days {monday,tuesday,wednesday,thursday,friday,saturday,sunday};

/* Two useful functions */
days yesterday(days today){
  return days((int(today)+6)%7);
}
days tomorrow(days today){
  return days((int(today)+1)%7);
}

// A useful array: thedays is an array of constant (i.e you cannot
// modify them) pointers to constant (i.e. you cannot modify them) strings
const char * const thedays[] = 
                      {"monday", "tuesday", "wednesday", "thursday",
		       "friday", "saturday", "sunday"};

void main(void){

  // In C++, two consecutive string literals are concatenated into a
  // single string literal.
  cout << "today    \tyesterday  \ttomorrow\n"
          "============================================" << endl;

  for (days today=monday;today<=sunday;today = days(int(today) + 1))
    cout << thedays[today] << " = " << today << '\t'
	 << thedays[yesterday(today)] << " = " << yesterday(today) << '\t'
	 << thedays[tomorrow(today)] << " = " << tomorrow(today) << endl;
}

/*
 The output is:

today    	yesterday  	tomorrow
============================================
monday = 0 	 sunday = 6 	 tuesday = 1
tuesday = 1 	 monday = 0 	 wednesday = 2
wednesday = 2 	 tuesday = 1 	 thursday = 3
thursday = 3 	 wednesday = 2 	 friday = 4
friday = 4 	 thursday = 3 	 saturday = 5
saturday = 5 	 friday = 4 	 sunday = 6
sunday = 6 	 saturday = 5 	 monday = 0

*/
