CS 1430: Programming in C++
Enumeration Data Type enum Day {SUN, MON, TUE, WED, THU, FRI, SAT}; Day today; today = MON; if (today == FRI) cout << "We have a quiz or a test!"; else if (today == THU) cout << “We have a Lab!"; else if (today == SAT) cout << “Party!"; else cout << “What to do?”;
Switch Statement enum Day {SUN, MON, TUE, WED, THU, FRI, SAT}; Day today; today = MON; . . . switch (today) { case FRI: cout << "We have a quiz or a test!"; case THU: cout << “We have a Lab!"; case SAT: cout << “Party!"; default: cout << “What to do?”; }
Must BREAK! today = MON; . . . switch (today) { case FRI: cout << "We have a quiz or a test!"; break; case THU: cout << “We have a Lab!"; case SAT: cout << “Party!"; default: cout << “What to do?”; }
Must BREAK! today = MON; . . . switch (today) { case FRI: cout << "We have a quiz or a test!"; break; case THU: cout << “We have a Lab!"; case SAT: case SUN: cout << “Party!"; default: cout << “What to do?”; }
Using enum Type in C++ Classes enum Status {FRESHMAN, SOPHOMORE, JUNIOR, SENIOR}; class StudentType { private: string id; string firstName, lastName; float gpa; Status standing; public: . . . };
C++ String string Standing() const { string s; if (standing == FRESHMAN) s = “FRESHMAN”; else if (standing == SOPHOMORE) s = “SOPHOMORE”; else if (standing == JUNIOR) s = “JUNIOR”; else s = “SENIOR”; return s; }
C++ String and Switch string Standing() const { string s; switch (standing) case FRESHMAN: s = “FRESHMAN”; break; case SOPHOMORE: s = “SOPHOMORE”; case JUNIOR: s = “JUNIOR”; default: s = “SENIOR”; } return s;
C String and Switch void Standing(char s[]) const { switch ( standing ) case FRESHMAN: strcpy(s, “FRESHMAN”); break; case SOPHOMORE: strcpy(s, “SOPHOMORE”); case JUNIOR: strcpy(s, “JUNIOR”); default: strcpy(s, “SENIOR”); } return;
Method Write of Class StudentType void Write() const { string status; Standing(status); cout << endl << setw(25) << id << endl << setw(25) << firstName << endl << setw(25) << lastName << endl << setw(25) << gpa; << endl << setw(25) << status; return; }
(for a total of 50 points on quizzes) Schedule Quiz8-1 By 10 PM Today! One Bonus Point (for a total of 50 points on quizzes)
Quiz 3 Wednesday, Dec 2 (week 14) Test 3 Wednesday (week 15) Schedule Quiz 3 Wednesday, Dec 2 (week 14) Test 3 Wednesday (week 15)