Sams Teach Yourself C++ in 21 Days

(singke) #1
What’s Next 777

21


33: return FullTime;
34: else
35: return PartTime;
36: }
37:
38: void student::SetStatus(STATUS theStatus)
39: {
40: myStatus = theStatus;
41: }
42:
43: int main()
44: {
45: student Jim;
46:
47: if (Jim.GetStatus()== PartTime)
48: cout << “Jim is part-time” << endl;
49: else
50: cout << “Jim is full-time” << endl;
51:
52: Jim.SetStatus(PartTime);
53:
54: if (Jim.GetStatus())
55: cout << “Jim is part-time” << endl;
56: else
57: cout << “Jim is full-time” << endl;
58:
59: cout << “Jim is on the “ ;
60:
61: char Plan[80];
62: switch (Jim.GetPlan())
63: {
64: case OneMeal: strcpy(Plan,”One meal”); break;
65: case AllMeals: strcpy(Plan,”All meals”); break;
66: case WeekEnds: strcpy(Plan,”Weekend meals”); break;
67: case NoMeals: strcpy(Plan,”No Meals”);break;
68: default : cout << “Something bad went wrong! “<< endl;
69: break;
70: }
71: cout << Plan << “ food plan.” << endl;
72: return 0;
73: }

Jim is part-time
Jim is full-time
Jim is on the No Meals food plan.
On lines 4–7, several enumerated types are defined. These serve to define the
possible values for the bit fields within the student class.

OUTPUT


LISTING21.7 continued


ANALYSIS
Free download pdf