sources:
BasicClass.h (1.4k)
CashOffice.cpp (3.7k)
CashOffice.h (1.7k)
Date.cpp (6.1k)
Date.h (2.9k)
House.cpp (6.1k)
House.h (2.3k)
O3_1.cpp (737 bytes)
Room.cpp (2.9k)
Room.h (1.5k)


binaries:
Release/O3_1.exe (124.0k)


website:
more info here
studies/bauelemente/Softwarebauelemente-CodeO3-1/Room.cpp
download file

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