1 ///////////////////////////////////////////////////////////
2 // Softwarebauelemente II, Aufgabe O2.1
3 //
4 // author: Stephan Brumme
5 // last changes: February 26, 2001
6
7 #include "Room.h"
8 #include <iostream>
9
10
11 CRoom::CRoom(int nNumberOfRoom, int nArea)
12 {
13 m_nArea = nArea;
14 m_nNumberOfRoom = nNumberOfRoom;
15 }
16
17
18 // attention ! this method is NOT part of CRoom
19 ostream& operator<<(ostream &mystream, const CRoom& room)
20 {
21 return room.OutStream(mystream);
22 }
23
24
25 // used to perform proper display in derived classes
26 ostream& CRoom::OutStream(ostream& mystream, bool bDebug) const
{
27 if (!bDebug)
28 {
29 mystream << "Room no. " << m_nNumberOfRoom
30 << " covers an area of " << m_nArea << " square feet.";
31 }
32 else
{
33 mystream << "DEBUG info for '" << ClassnameOf() << "'" << endl
34 << " m_nArea=" << m_nArea
<< " m_nNumberOfRoom=" << m_nNumberOfRoom << endl;
35 }
36
37 return mystream;
38 }
39
40
41 // compare the room with another one
42 bool CRoom::operator==(const CRoom &room) const
{
43 return ((room.m_nArea == m_nArea) &&
44 (room.m_nNumberOfRoom == m_nNumberOfRoom));
45 }
46
47
48 // compare the room with another one
49 // routes call down to "==" operator
50 bool CRoom::EqualValue(const CRoom* room) const
{
51 // disallow NULL pointer
52 if (room == NULL)
53 return false;
54
55 return (operator==(*room));
56 }
57
58
59
60 // copy one room to another one
61 // prevents user from copying an object to itself
62 CRoom& CRoom::operator=(const CRoom &room)
63 {
64 // copy all variables
65 m_nArea = room.m_nArea;
66 m_nNumberOfRoom = room.m_nNumberOfRoom;
67
68 return *this;
69 }
70
71
72 // copy one room to another one
73 // prevents user from copying an object to itself
74 // calls "=" operator internally
75 bool CRoom::Copy(const CRoom* room)
76 {
77 // disallow NULL pointer
78 if (room == NULL)
79 return false;
80
81 // cannot copy an object to itself
82 if (this == room)
83 return false;
84
85 // use "=" operator
86 operator=(*room);
87
88 return true;
89 }
90
91
92 // retrieve the private value of m_nNumberOfRoom
93 int CRoom::GetNumberOfRoom() const
{
94 return m_nNumberOfRoom;
95 }
96
97
98 // change private m_nNumberOfRoom
99 void CRoom::SetNumberOfRoom(const int nNumberOfRoom)
100 {
101 m_nNumberOfRoom = nNumberOfRoom;
102 }
103
104
105 // retrieve the private value of m_nArea
106 int CRoom::GetArea() const
{
107 return m_nArea;
108 }
109
110