1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
| #include <iostream.h>
#include <conio.h>
#include <cstring.h>
#include <string.h>
class OverflowException {
public:
OverflowException() {
cout << endl << "Exception created!" << endl;
}
OverflowException(OverflowException&) {
cout << "Exception copied!" << endl;
}
~OverflowException() {
cout << "Exception finished!" << endl;
}
};
template <class T>
class Dators {
private:
string Processor;
T GHz;
short OP_atm;
public:
Dators();
Dators(string, T, short);
virtual ~Dators() {
cout << "Message from the "Dators" - destroyed!" <<
endl;
}
string GetProcessor() const {
return Processor;
}
void SetProcessor(const string& Processor) {
this->Processor = Processor;
}
T GetGHz() const;
void SetGHz(T);
short GetOP_atm() const;
void SetOP_atm(short);
virtual void Print() const;
};
template <class T>
class Netcomputer : public Dators<T> {
private:
string IP;
public:
Netcomputer():Dators<T>(), IP("0") {
}
Netcomputer(string, T, short, string);
virtual ~Netcomputer() {
cout << endl << "Message from the "Netcomputer" - destroyed!" << endl;
}
string GetIP() const {
return IP;
}
void SetIP(string IP) {
this->IP = IP;
}
virtual void Print() const;
};
template <class T>
class ComputerNetwork {
private:
typedef Netcomputer<T>* EPointer;
EPointer *Datorss;
static const unsigned int DEF_MAX_LENGTH;
unsigned int MaxLength;
unsigned int Length;
unsigned int LineColor;
public:
ComputerNetwork() : MaxLength(DEF_MAX_LENGTH),Length(0) {
Datorss = new EPointer[MaxLength];
}
ComputerNetwork(unsigned int MaxLength) : MaxLength(MaxLength), Length(0) {
Datorss = new EPointer[MaxLength];
}
~ComputerNetwork();
static unsigned int GetDefaultMaxLength() {
return DEF_MAX_LENGTH;
}
int GetMaxLength() const {
return MaxLength;
}
int GetLength() const {
return Length;
}
void AddDators(const Netcomputer<T>&);
void Print() const;
};
template <class T>
const unsigned int ComputerNetwork<T>::DEF_MAX_LENGTH = 5;
template <class T>
Dators<T>::Dators() : Processor("Nosaukums"), GHz('2'), OP_atm(0) {
}
template <class T>
Dators<T>::Dators(string Processor, T PGHz, short POP_atm) : Processor(Processor) {
GHz = PGHz;
OP_atm = POP_atm;
}
template <class T>
inline T Dators<T>::GetGHz() const {
return GHz;
}
template <class T>
inline void Dators<T>::SetGHz(T GHz) {
this->GHz = GHz;
}
template <class T>
inline short Dators<T>::GetOP_atm() const {
return OP_atm;
}
template <class T>
inline void Dators<T>::SetOP_atm(short OP_atm) {
this->OP_atm = OP_atm;
}
template <class T>
inline void Dators<T>::Print() const {
cout << "Processor = " << Processor << ", GHz = " << GHz << ", OP_atm = " << OP_atm;
}
template <class T>
Netcomputer<T>::Netcomputer(string Processor, T PGHz, short POP_atm, string TIP) : Dators<T>(Processor, PGHz, POP_atm) {
IP = TIP;
}
template <class T>
inline void Netcomputer<T>::Print() const {
Dators<T>::Print();
cout << ", IP = " << IP;
}
template <class T>
ComputerNetwork<T>::~ComputerNetwork() {
for(unsigned int i=0; i<Length; i++)
delete Datorss[i];
delete [] Datorss;
}
template <class T>
void ComputerNetwork<T>::Print() const {
cout << "\nBiggest IP: " << TIP << "." << endl
<< "IP nodes:" << endl;
for (unsigned int i=0; i<Length; i++) {
cout << (i+1) << ". ";
Datorss[i]->Print();
cout << "." << endl;
}
}
template <class T>
void ComputerNetwork<T>::AddDators(const Netcomputer<T>& Datorss) {
if (Length == MaxLength)
throw OverflowException();
else
Datorss[Length++] = new Netcomputer<T>(
Datorss.GetProcessor(),
Datorss.GetGHz(),
Datorss.GetOP_atm(),
Datorss.GetIP()
);
}
void main(void) {
ComputerNetwork<unsigned short> *CharGHz = new ComputerNetwork<unsigned short> (2);
ComputerNetwork<unsigned int> *UnsignedCharGHz = new ComputerNetwork<unsigned int> (1);
Netcomputer<unsigned short> *CharE1 = new Netcomputer <unsigned short> ("1",2,1);
Netcomputer<unsigned int> *UnsignedCharE1 = new Netcomputer<unsigned int> ("2",2,"123.132");
Netcomputer<unsigned short> CharE2("2",2,"123.132");
Netcomputer<unsigned int> UnsignedCharE2("2",2,"123.132");
try {
CharGHz->AddDators(*CharE1);
cout << "\nNew CHAR Dators added successfully!" << endl;
}
catch (OverflowException&) {
cout << "Error: maximal size exceeded!" << endl;
}
catch (...) {
cout << "Unknown Error !" << endl;
}
try {
CharGHz->AddDators(CharE2);
cout << "\nNew CHAR Dators added successfully!" << endl;
}
catch (OverflowException&) {
cout << "Error: maximal size exceeded !" << endl;
}
catch (...) {
cout << "Unknown Error !" << endl;
}
try {
UnsignedCharGHz->AddDators(*UnsignedCharE1);
cout << "\nNew UNSIGNED CHAR Dators added successfully!" << endl;
}
catch (OverflowException&) {
cout << "Error: maximal size exceeded!" << endl;
}
catch (...) {
cout << "Unknown Error !" << endl;
}
try {
UnsignedCharGHz->AddDators(UnsignedCharE2);
cout << "\nNew UNSIGNED CHAR Dators added successfully!" << endl;
}
catch (OverflowException&) {
cout << "Error: maximal size exceeded !" << endl;
}
catch (...) {
cout << "Unknown Error !" << endl;
}
delete CharE1;
delete UnsignedCharE1;
cout << endl << "CHAR line:";
CharGHz->Print();
cout << endl << "UNISGNED CHAR line:";
UnsignedCharGHz->Print();
delete CharGHz;
delete UnsignedCharGHz;
while (kbhit())
getch();
getch();
} |