sources:
BasicClass.h (1.4k)
C1_2.cpp (604 bytes)
CashOffice.cpp (3.8k)
CashOffice.h (1.8k)
Date.cpp (6.0k)
Date.h (2.9k)
Exception.cpp (2.5k)
Exception.h (1.4k)
House.cpp (6.8k)
House.h (2.5k)
Room.cpp (3.0k)
Room.h (1.6k)


binaries:
Release/C1_2.exe (140.0k)


website:
more info here
studies/bauelemente/Softwarebauelemente-CodeC1-2/Room.cpp
download file

  1 ///////////////////////////////////////////////////////////
  2 // Softwarebauelemente II, Aufgabe C1.1
  3 //
  4 // author: Stephan Brumme
  5 // last changes: July 3, 2001
  6
  7 #include "Room.h"
  8 #include <iostream>
  9
 10
 11 // default constructor
 12 CRoom::CRoom()
 13 {
 14     m_nArea = 0;
 15     m_nNumberOfRoom = 0;
 16 }
 17
 18 // copy constructor
 19 CRoom::CRoom(const CRoom &room)
 20 {
 21     operator=(room);
 22 }
 23
 24 CRoom::CRoom(int nNumberOfRoom, int nArea)
 25 {
 26     m_nArea = nArea;
 27     m_nNumberOfRoom = nNumberOfRoom;
 28 }
 29
 30
 31 // show attributes
 32 string CRoom::Show() const
 33 {
 34     // check invariance
 35     if (!ClassInvariant())
 36         return "";
 37
 38     ostringstream strOutput;
 39
 40     strOutput << "Room no. " << m_nNumberOfRoom
 41               << " covers an area of " << m_nArea << " square feet." << endl;
 42
 43     return strOutput.str();
 44 }
 45
 46
 47 // display the attributes
 48 // only for internal purposes !
 49 string CRoom::ShowDebug() const
 50 {
 51     ostringstream strOutput;
 52
 53     strOutput << "DEBUG info for 'CRoom'" << endl
 54               << " m_nArea = " << m_nArea
 55               << " m_nNumberOfRoom = " << m_nNumberOfRoom << endl;
 56
 57     return strOutput.str();
 58 }
 59
 60
 61 // verify invariance
 62 bool CRoom::ClassInvariant() const
 63 {
 64     // only positive numbers allowed
 65     return (m_nArea         > 0 && m_nArea         <= MAXAREA &&
 66             m_nNumberOfRoom > 0 && m_nNumberOfRoom <= MAXNUMBER)
;
 67 }
 68
 69
 70 // copy one room to another one
 71 // prevents user from copying an object to itself
 72 CRoom& CRoom::operator=(const CRoom &room)
 73 {
 74     // copy all variables
 75     m_nArea         = room.m_nArea;
 76     m_nNumberOfRoom = room.m_nNumberOfRoom;
 77
 78     return *this;
 79 }
 80
 81
 82 // virtual, see operator=
 83 bool CRoom::Copy(const CBasicClass* pClass)
 84 {
 85     // cast to CRoom
 86     const CRoom *room = dynamic_cast<const CRoom*>(pClass);
 87
 88     // invalid class (is NULL when pClass is not a CRoom)
 89     if (room == NULL || room == this)
 90         return false;
 91
 92     // use non virtual reference based copy
 93     // return value isn't needed
 94     operator=(*room);
 95
 96     // we're done
 97     return true;
 98 }
 99
100
101 // compare the room with another one
102 bool CRoom::operator==(const CRoom &room) const
103 {
104     return ((room.m_nArea         == m_nArea) &&
105             (room.m_nNumberOfRoom == m_nNumberOfRoom))
;
106 }
107
108
109 // virtual, see operator==
110 bool CRoom::EqualValue(const CBasicClass* pClass) const
111 {
112     // cast to CRoom
113     const CRoom *room = dynamic_cast<const CRoom*>(pClass);
114
115     // invalid class (is NULL when pClass is not a CRoom)
116     if (room == NULL || room == this)
117         return false;
118
119     // use non virtual reference based copy
120     return operator==(*room);
121 }
122
123
124 // retrieve the private value of m_nNumberOfRoom
125 int CRoom::GetNumberOfRoom() const
126 {
127     return m_nNumberOfRoom;
128 }
129
130
131 // change private m_nNumberOfRoom
132 void CRoom::SetNumberOfRoom(const int nNumberOfRoom)
133 {
134     m_nNumberOfRoom = nNumberOfRoom;
135 }
136
137
138 // retrieve the private value of m_nArea
139 int CRoom::GetArea() const
140 {
141     return m_nArea;
142 }
143
144
145 // needed to use a STL set
146 bool CRoom::operator<(const CRoom &room) const
147 {
148     return m_nNumberOfRoom < room.m_nNumberOfRoom;
149 }
150