// ***************************************************************** // Author: Zhixiang Chen // Class: CSCI/CMPE 1170, Spring 2008 // Lab 8: Enumerated data types and string comparisons // Date: January 12, 2009 // Comment: The code here is meant to be revised. // //----------------------------------------------------------------- // // This lab exercise is to play with enumerated data types and // string object comparisons and C-string comparisions. // Please pay attention to the fact that one cannot do direct // input/ouput for any enumerated data types. // The main advantage of having enumerate data types is for readability. // // Compile and run your program. When everything is fine, // print your .cpp file and turn it to me or the TA. // ***************************************************************** #include < iostream > #include #include < string > #include < cstring > #include < cmath> #include #include using namespace std; int main( ) { //enumerate type definition enum weekDays={Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday} //variable declarations weekDays myDays; //to deal with week days string day; //C++ string object, to get the day as a C++-string char anotherDay[50]; //C-string var, to get the day as a C-string char choice, //for choice of C++ strings or C-string; option; //a flag to stop the loop //loop foevever to play the program until the user stops while (true) { //play with C++ strings or C-strings cout<<"Wnat to play C++ strings or C-strings (y/n)? => "; cin>>choice; if (choice == 'y' || choice == 'Y') //for C++ strings { //get a day via C++ string object cout<<"Enter a week day => "; cin>>day; //covert string week day to enumerated weekDays value if (day == "Monday") day = Monday; else if (day == "Tuesady") day = Tuesday; //For you: finish the rest of conversion /********** Your part is here *************/ else cout<< "not a valid day. "< "; cin>>anotherDay; //covert string week day to enumerated weekDays value if (strcmp(anotherDay, "Monday") == 0) day = Monday; else if (strcmp(day, "Tuesady") == 0) day = Tuesday; //For you: finish the rest of conversion /********** Your part is here *************/ else cout<< "not a valid day. "<