studies/bauelemente/Softwarebauelemente-CodeM5/m05_1.cpp
⇒
download file
1
2
3
4
5
6
7
8
9 #include <iostream>
10
11
12 using namespace std;
13
14
15
16
17 struct TRoom
18 {
19 int NumberOfRooms;
20 int Area;
21 };
22
23
24
25
26 void Init(TRoom &roo, int nor, int ar)
27 {
28 roo.NumberOfRooms = nor;
29 roo.Area = ar;
30 }
31
32
33
34
35 bool EqualValue(TRoom roo1, TRoom roo2)
36 {
37 return ((roo1.Area == roo2.Area) &&
38 (roo1.NumberOfRooms = roo2.NumberOfRooms));
39 }
40
41
42
43
44 bool Copy(TRoom* roo1, TRoom roo2)
45 {
46 if (roo1 == NULL)
47 return false;
48
49 roo1->Area = roo2.Area;
50 roo1->NumberOfRooms = roo2.NumberOfRooms;
51 return true;
52 }
53
54
55
56 int GetNumberOfRooms(TRoom roo)
57 {
58 return roo.NumberOfRooms;
59 }
60
61
62
63 void SetNumberOfRooms(TRoom &roo, int nor)
64 {
65 roo.NumberOfRooms = nor;
66 }
67
68
69
70 int GetArea(TRoom roo)
71 {
72 return roo.Area;
73 }
74
75
76
77 void Show(TRoom roo)
78 {
79 cout<<"Es sind "<<roo.NumberOfRooms<<" Raeume mit einer Flaeche von "<<roo.Area
80 <<"."<<endl;
81 }
82
83
84
85 void main()
86 {
87 TRoom Wohnheim;
88 TRoom ZuHause;
89
90 Init(Wohnheim, 1, 20);
91 Init(ZuHause, 5, 75);
92
93 cout<<"Wohnheim: ";
94 Show(Wohnheim);
95
96 cout<<"Zu Hause: ";
97 Show(ZuHause);
98
99 cout<<endl;
100
101 if (EqualValue(Wohnheim, ZuHause))
102 cout<<"Muttersöhnchen !"<<endl;
103 else
104 cout<<"Party People !"<<endl;
105
106 cout<<endl;
107
108 cout<<"Im Wohnheim sind es "<<GetArea(Wohnheim)<<"qm in "
109 <<GetNumberOfRooms(Wohnheim)<<" Zimmer(n)."<<endl;
110
111 cout<<endl;
112
113 SetNumberOfRooms(Wohnheim, 2);
114 cout<<"Wenn ich eine Trennwand hinstelle, habe ich ploetzlich "
115 <<GetNumberOfRooms(Wohnheim)<<" Zimmer !"<<endl;
116 }
117