Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS 1430: Programming in C++.

Similar presentations


Presentation on theme: "CS 1430: Programming in C++."— Presentation transcript:

1 CS 1430: Programming in C++

2 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?”;

3 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?”; }

4 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?”; }

5 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?”; }

6 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: . . . };

7 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; }

8 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;

9 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;

10 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; }

11 (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)

12 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)


Download ppt "CS 1430: Programming in C++."

Similar presentations


Ads by Google