sources:
M07_1.cpp (302 bytes)
MCashOffice.cpp (2.0k)
MCashOffice.h (1.4k)
MRoom.cpp (4.9k)
MRoom.h (1.1k)
PrimitiveTypes.h (421 bytes)


website:
more info here
studies/bauelemente/Softwarebauelemente-CodeM7-1/MRoom.cpp
download file

  1 ///////////////////////////////////////////////////////////
  2 // Softwarebauelemente I, Aufgabe M7.1
  3 //
  4 // author: Stephan Brumme
  5 // last changes: January 08, 2001
  6
  7
  8 // import cout to display some data
  9 #include <iostream>
 10 #include "MRoom.h"
 11
 12 // open std namespace
 13 using namespace std;
 14
 15
 16
 17 // define the namespace Room
 18
 19 // Initializes the TRoom structure
 20 void MRoom::Init(TRoom &roo, Ordinal nor, Ordinal ar)
 21 {
 22     // display in-parameters
 23     cout<<"MRoom::Init entered"<<endl;
 24     cout<<" IN: NumberOfRooms: "<<nor<<endl;
 25     cout<<" Area: "<<ar<<endl;
 26
 27     // global counter
 28     static int nCount = 0;
 29     roo = ++nCount;
 30
 31     // display out-parameters
 32     cout<<" OUT: TRoom: "<<roo<<endl;
 33     cout<<"MRoom::Init left"<<endl<<endl;
 34
 35 // replaced code:
 36 // roo.NumberOfRooms = nor;
 37 // roo.Area = ar;
 38 }
 39
 40
 41 // Compares two exemplars
 42 // returns "true" if attributes of both are equal; "false" otherwise
 43 Boolean MRoom::EqualValue(TRoom roo1, TRoom roo2)
 44 {
 45     // display in-parameters
 46     cout<<"MRoom::EqualValue entered"<<endl;
 47     cout<<" IN: Room1: "<<roo1<<endl;
 48     cout<<" Room2: "<<roo2<<endl;
 49
 50     // ask user
 51     cout<<"-----------------------------------------------------------"<<endl;
 52     cout<<"Are those rooms equal (Y=yes, else false) ? ";
 53     char cInput;
 54     cin>>cInput;
 55     // display entered char
 56     cout<<cInput<<endl;
 57     cout<<"-----------------------------------------------------------"<<endl;
 58
 59     // convert to Boolean
 60     Boolean bReturn = (cInput=='Y')||(cInput=='y');
 61
 62     // display out-parameters
 63     cout<<" OUT: return "<<bReturn;
 64     cout<<"MRoom::EqualValue left"<<endl<<endl;
 65
 66     return bReturn;
 67
 68 // replaced code:
 69 // return ((roo1.Area == roo2.Area) &&
 70 // (roo1.NumberOfRooms = roo2.NumberOfRooms));
 71 }
 72
 73
 74 // Copies the attributes of roo2
 75 // returns "true" if successful, "false" if no memory allocated
 76 Boolean MRoom::Copy(TRoom& roo1, TRoom roo2)
 77 {
 78     // display in-parameters
 79     cout<<"MRoom::Copy entered"<<endl;
 80     cout<<" IN: Room1: "<<roo1<<endl;
 81     cout<<" Room2: "<<roo2<<endl;
 82
 83     // ask user
 84     cout<<"-----------------------------------------------------------"<<endl;
 85     cout<<"Should Room2 be copied to Room1 (Y=yes, else false) ? ";
 86     char cInput;
 87     cin>>cInput;
 88     // display entered char
 89     cout<<cInput<<endl;
 90     cout<<"-----------------------------------------------------------"<<endl;
 91
 92     // convert to Boolean
 93     Boolean bReturn = (cInput=='Y')||(cInput=='y');
 94     if (bReturn)
 95         roo1 = roo2;
 96
 97     // display out-parameters
 98     cout<<" OUT: Room1: "<<roo1<<endl;
 99     cout<<" return "<<bReturn;
100     cout<<"MRoom::Copy left"<<endl<<endl;
101
102     return bReturn;
103
104 // replaced code:
105 // if (EqualValue(roo1, roo2))
106 // return false;
107 //
108 // roo1.Area = roo2.Area;
109 // roo1.NumberOfRooms = roo2.NumberOfRooms;
110 // return true;
111 }
112
113
114 // Returns the NumberOfRooms attribute
115 Ordinal MRoom::GetNumberOfRooms(TRoom roo)
116 {
117     // display in-parameters
118     cout<<"MRoom::GetNumberOfRooms entered"<<endl;
119     cout<<" IN: Room: "<<roo<<endl;
120
121     cout<<"-----------------------------------------------------------"<<endl;
122     cout<<"How many rooms ? ";
123     int nReturn;
124     cin>>nReturn;
125     // display entered char
126     cout<<nReturn<<endl;
127     cout<<"-----------------------------------------------------------"<<endl;
128
129     // display out-parameters
130     cout<<" return "<<nReturn;
131     cout<<"MRoom::GetNumberOfRooms left"<<endl<<endl;
132
133     return nReturn;
134
135 // replaced code:
136 // return roo.NumberOfRooms;
137 }
138
139
140 // Sets the NumberOfRooms attribute
141 void MRoom::SetNumberOfRooms(TRoom &roo, Ordinal nor)
142 {
143     // display in-parameters
144     cout<<"MRoom::SetNumberOfRooms entered - not affecting anything !"<<endl;
145     cout<<" IN: Room: "<<roo<<endl;
146     cout<<" NumberOfRooms: "<<nor<<endl;
147
148     // display out-parameters
149     cout<<"MRoom::SetNumberOfRooms left"<<endl<<endl;
150
151 // replaced code:
152 // roo.NumberOfRooms = nor;
153 }
154
155
156 // Returns the Area attribute
157 Ordinal MRoom::GetArea(TRoom roo)
158 {
159     // display in-parameters
160     cout<<"MRoom::GetArea entered"<<endl;
161     cout<<" IN: Room: "<<roo<<endl;
162
163     cout<<"-----------------------------------------------------------"<<endl;
164     cout<<"How many square feet ? ";
165     int nReturn;
166     cin>>nReturn;
167     // display entered char
168     cout<<nReturn<<endl;
169     cout<<"-----------------------------------------------------------"<<endl;
170
171     // display out-parameters
172     cout<<" return "<<nReturn;
173
174     // display out-parameters
175     cout<<"MRoom::GetArea left"<<endl<<endl;
176
177     return nReturn;
178
179 // replaced code:
180 // return roo.Area;
181 }
182
183
184 // Displays the attributes
185 void MRoom::Show(TRoom roo)
186 {
187     // display in-parameters
188     cout<<"MRoom::Show entered - not affecting anything !"<<endl;
189     cout<<" IN: Room: "<<roo<<endl;
190
191     // display out-parameters
192     cout<<"MRoom::Show left"<<endl<<endl;
193
194 // replaced code:
195 // cout<<"Es sind "<<roo.NumberOfRooms<<" Raeume mit einer Flaeche von "<<roo.Area
196 // <<"."<<endl;
197 }
198
199 // end of namespace Room
200
201