sources:
m05_1.cpp (2.1k)


website:
more info here
studies/bauelemente/Softwarebauelemente-CodeM5/m05_1.cpp
download file

  1 ///////////////////////////////////////////////////////////
  2 // Softwarebauelemente I, Aufgabe M5.1
  3 //
  4 // author: Stephan Brumme
  5 // last changes: November 20, 2000
  6
  7
  8 // import cout to display some data
  9 #include <iostream>
 10
 11 // open std namespace
 12 using namespace std;
 13
 14
 15
 16 // Data structure representing a room unit
 17 struct TRoom {
 18     int NumberOfRooms;
 19     int Area;
 20 };
 21
 22
 23
 24 // Initializes the TRoom structure
 25 void Init(TRoom &roo, int nor, int ar)
 26 {
 27     roo.NumberOfRooms = nor;
 28     roo.Area = ar;
 29 }
 30
 31
 32 // Compares two exemplars
 33 // returns "true" if attributes of both are equal; "false" otherwise
 34 bool EqualValue(TRoom roo1, TRoom roo2)
 35 {
 36     return ((roo1.Area == roo2.Area) &&
 37             (roo1.NumberOfRooms = roo2.NumberOfRooms))
;
 38 }
 39
 40
 41 // Copies the attributes of roo2
 42 // returns "true" if successful, "false" if no memory allocated
 43 bool Copy(TRoom* roo1, TRoom roo2)
 44 {
 45     if (roo1 == NULL)
 46         return false;
 47
 48     roo1->Area = roo2.Area;
 49     roo1->NumberOfRooms = roo2.NumberOfRooms;
 50     return true;
 51 }
 52
 53
 54 // Returns the NumberOfRooms attribute
 55 int GetNumberOfRooms(TRoom roo)
 56 {
 57     return roo.NumberOfRooms;
 58 }
 59
 60
 61 // Sets the NumberOfRooms attribute
 62 void SetNumberOfRooms(TRoom &roo, int nor)
 63 {
 64     roo.NumberOfRooms = nor;
 65 }
 66
 67
 68 // Returns the Area attribute
 69 int GetArea(TRoom roo)
 70 {
 71     return roo.Area;
 72 }
 73
 74
 75 // Displays the attributes
 76 void Show(TRoom roo)
 77 {
 78     cout<<"Es sind "<<roo.NumberOfRooms<<" Raeume mit einer Flaeche von "<<roo.Area         <<"."<<endl;
 79 }
 80
 81
 82
 83 void main()
 84 {
 85     TRoom Wohnheim;
 86     TRoom ZuHause;
 87
 88     Init(Wohnheim, 1, 20);
 89     Init(ZuHause, 5, 75);
 90
 91     cout<<"Wohnheim: ";
 92     Show(Wohnheim);
 93
 94     cout<<"Zu Hause: ";
 95     Show(ZuHause);
 96
 97     cout<<endl;
 98
 99     if (EqualValue(Wohnheim, ZuHause))
100         cout<<"Muttersöhnchen !"<<endl;
101     else         cout<<"Party People !"<<endl;
102
103     cout<<endl;
104
105     cout<<"Im Wohnheim sind es "<<GetArea(Wohnheim)<<"qm in "
106         <<GetNumberOfRooms(Wohnheim)<<" Zimmer(n)."<<endl;
107
108     cout<<endl;
109
110     SetNumberOfRooms(Wohnheim, 2);
111     cout<<"Wenn ich eine Trennwand hinstelle, habe ich ploetzlich "
112         <<GetNumberOfRooms(Wohnheim)<<" Zimmer !"<<endl;
113 }
114
115