|
|
 |
|
|
|
|
73: ~Animal(){}
74:
75: int GetAge()
76: {
77: ASSERT(Invariants());
78: return itsAge;
79: }
80:
81: void SetAge(int Age)
82: {
83: ASSERT(Invariants());
84: itsAge = Age;
85: ASSERT(Invariants());
86: }
87: String& GetName()
88: {
89: ASSERT(Invariants());
90: return itsName;
91: }
92:
93: void SetName(const String& name)
94: {
95: ASSERT(Invariants());
96: itsName = name;
97: ASSERT(Invariants());
98: }
99:
100: bool Invariants();
101: private:
102: int itsAge;
103: String itsName;
104: };
105:
106: bool Animal::Invariants()
107: {
108: PRINT((Animal Invariants Checked));
109: return (itsAge > 0 && itsName.GetLen());
110: }
111:
112: int main()
113: {
114: const int AGE = 5;
115: EVAL(AGE);
116: Animal sparky(AGE, Sparky);
117: cout << \n << sparky.GetName().GetString();
118: cout << is ;
119: cout << sparky.GetAge() << years old.;
120: sparky.SetAge(8);
121: cout << \n << sparky.GetName().GetString(); |
|
|
|
 |
|
|
|
|
continues |
|
|
|
|
|