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 int NumberOfRooms;
19 int Area;
20 };
21
22
23
24
25 void Init(TRoom &roo, int nor, int ar)
26 {
27 roo.NumberOfRooms = nor;
28 roo.Area = ar;
29 }
30
31
32
33
34 bool EqualValue(TRoom roo1, TRoom roo2)
35 {
36 return ((roo1.Area == roo2.Area) &&
37 (roo1.NumberOfRooms = roo2.NumberOfRooms));
38 }
39
40
41
42
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
55 int GetNumberOfRooms(TRoom roo)
56 {
57 return roo.NumberOfRooms;
58 }
59
60
61
62 void SetNumberOfRooms(TRoom &roo, int nor)
63 {
64 roo.NumberOfRooms = nor;
65 }
66
67
68
69 int GetArea(TRoom roo)
70 {
71 return roo.Area;
72 }
73
74
75
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