sources:
M07_2.cpp (4.8k)
MDate.cpp (1.8k)
MDate.h (956 bytes)
MHouse.cpp (4.9k)
MHouse.h (1.9k)
MRoom.cpp (1.5k)
MRoom.h (1.1k)
PrimitiveTypes.h (421 bytes)


website:
more info here
studies/bauelemente/Softwarebauelemente-CodeM7-2/M07_2.cpp
download file

  1 ///////////////////////////////////////////////////////////
  2 // Softwarebauelemente I, Aufgabe M7.2.
  3 //
  4 // author: Stephan Brumme
  5 // last changes: January 13, 2001
  6
  7
  8 // import cout to display some data
  9 #include <iostream>
 10 #include "PrimitiveTypes.h"
 11 #include "MDate.h"
 12 #include "MRoom.h"
 13 #include "MHouse.h"
 14
 15 // open std namespace
 16 using namespace std;
 17
 18
 19 void main()
 20 {
 21     // declare our variables
 22     MHouse::THouse hou, hou1, hou2;
 23     MRoom::TRoom   roo, roo1, roo2;
 24     Boolean t1,t2,t3;
 25     Ordinal n1,n2;
 26
 27     // initialize them
 28     MHouse::Init(hou);
 29     MHouse::Init(hou1);
 30     MHouse::Init(hou2);
 31
 32     MRoom::Init(roo,  2, 3);
 33     MRoom::Init(roo1, 4, 5);
 34     MRoom::Init(roo2, 10, 10);
 35
 36     t1 = t2 = t3 = false;
 37     n1 = n2 = 0;
 38
 39
 40     // Case 1
 41     // require: the sets hou1 and hou2 are exemplars of MHouse::THouse
 42     // sequence: MHouse::Copy(hou1, hou2, t1);
 43     // MHouse::EqualValue(hou1, hou2, t2);
 44     // ensure: if the value of t1 is TRUE then t2 is TRUE, too
 45
 46     cout<<"Case 1"<<endl;
 47
 48     // ensure that hou1 differs from hou2, otherwise Copy will fail
 49     if (!MHouse::Insert(hou1, roo1))
 50     {
 51         cout<<"preparation for case 1 failed !!!"<<endl;
 52         exit(1);
 53     }
 54
 55     // first step of Case 1
 56     t1 = MHouse::Copy(hou1, hou2);
 57     cout<<"t1: "<<t1<<endl;
 58
 59     // second step only neccessary when first succeeded
 60     if (t1)
 61     {
 62         t2 = MHouse::EqualValue(hou1, hou2);
 63
 64         cout<<"t2: "<<t2<<endl<<endl;
 65     }
 66
 67     if (!(t1&&t2))
 68     {
 69         cout<<"Case 1 failed !!!"<<endl<<"test aborted."<<endl;
 70         exit(1);
 71     }
 72
 73
 74     // Case 2
 75     // require: the set hou as an exemplar of MHouse::THouse is not full
 76     // and roo1, roo2 are exemplars of MRoom::TRoom
 77     // sequence: MHouse::Insert(hou, roo1, t1);
 78     // MHouse::Find(hou, roo1, t2);
 79     // MHouse::GetCurrent(hou, roo2, t3);
 80     // ensure: the elements roo1 and roo2 have the same value
 81     // (MRoom::EqualValue); the values of t2 and t3 are TRUE
 82
 83     cout<<"Case 2"<<endl;
 84
 85     // try first command
 86     t1 = MHouse::Insert(hou, roo1);
 87     cout<<"t1: "<<t1<<endl;
 88
 89     if (t1)
 90     {
 91         // only if first command was successful
 92         t2 = MHouse::Find(hou, roo1);
 93         cout<<"t2: "<<t2<<endl;
 94
 95         if (t2)
 96         {
 97             // only if second command was successful
 98             t3 = MHouse::GetCurrent(hou, roo2);
 99             cout<<"t3: "<<t3<<endl;
100         }
101     }
102
103     cout<<"roo1==roo2: "<<MRoom::EqualValue(roo1, roo2)<<endl<<endl;
104
105     if (!(t2 && t3 && MRoom::EqualValue(roo1, roo2)))
106     {
107         cout<<"Case 2 failed !!!"<<endl<<"test aborted."<<endl;
108         exit(2);
109     }
110
111
112     // Case 3
113     // require: the set hou as an exemplar of MHouse::THouse contains roo
114     // (MHouse::Find)
115     // sequence: MHouse::Find(hou, roo, t1);
116     // MHouse::Scratch(hou, t2);
117     // MHouse::Find(hou, roo, t3);
118     // ensure: t2 is TRUE, t3 is FALSE
119
120     cout<<"Case 3"<<endl;
121
122     // we already inserted roo1 into hou in Case 2
123     // so our roo is roo1 in this Case !
124     t1 = MHouse::Find(hou, roo1);
125     cout<<"t1: "<<t1<<endl;
126
127     if (t1)
128     {
129         t2 = MHouse::Scratch(hou);
130         cout<<"t2: "<<t2<<endl;
131
132         if (t2)
133         {
134             t3 = MHouse::Find(hou, roo1);
135             cout<<"t3: "<<t3<<endl<<endl;
136         }
137     }
138
139     if (!(t1 && t2 && !t3))
140     {
141         cout<<"Case 3 failed !!!"<<endl<<"test aborted."<<endl;
142         exit(3);
143     }
144
145
146     // Case 4
147     // require: the set hou as an exemplar of MHouse::THouse is not full
148     // it does not contain roo (MHouse::Find)
149     // the set has the cardinality (MHouse::Card) of n1
150     // sequence: MHouse::Insert(hou, roo, t1);
151     // MHouse::Card(hou, n2);
152     // ensure: t2 is equal to n1+1
153
154     cout<<"Case 4"<<endl;
155
156     // prepare Case 4
157     if (MHouse::Find(hou, roo))
158     {
159         cout<<"preparation for case 1 failed, hou DOES contain roo !!!"<<endl;
160         exit(4);
161     }
162
163     n1 = MHouse::Card(hou);
164     cout<<"n1: "<<n1<<endl;
165     // preparation done right now
166
167     // Case 4 starts here
168     t1 = MHouse::Insert(hou, roo);
169     cout<<"t1: "<<t1<<endl;
170
171     if (t1)
172     {
173         // get cardinality
174         n2 = MHouse::Card(hou);
175         cout<<"n2: "<<n2<<endl<<endl;
176     }
177
178     // success ?
179     if (!(t1 && (n2 == n1+1)))
180     {
181         cout<<"Case 4 failed !!!"<<endl<<"test aborted."<<endl;
182         exit(4);
183     }
184
185
186     // Case 5
187     // require: the set hou as an exemplar of MHouse::THouse contains roo
188     // (MHouse::Find) and has the cardinality (MHouse::Card) of n1
189     // sequence: MHouse::Find(hou, roo, t1);
190     // MHouse::Scratch(hou, t2);
191     // MHouse::Card(hou, n2);
192     // ensure: n2 is equal to n1-1
193
194     cout<<"Case 5"<<endl;
195
196     // roo was inserted in Case 4 into hou, we re-use it
197     // n1 was sets properly in Case 4, too
198
199     t1 = MHouse::Find(hou, roo1);
200     cout<<"t1: "<<t1<<endl;
201
202     if (t1)
203     {
204         t2 = MHouse::Scratch(hou);
205         cout<<"t2: "<<t2<<endl;
206
207         if (t2)
208         {
209             n2 = MHouse::Card(hou);
210             cout<<"n2: "<<n2<<endl<<endl;
211         }
212     }
213
214     // success ?
215     if (!(n2==n1-1))
216     {
217         cout<<"Case 5 failed !!!"<<endl<<"test aborted."<<endl;
218         exit(5);
219     }
220
221
222     // done
223     cout<<"test frame succesfully executed."<<endl;
224 }
225