-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
123 lines (100 loc) · 3.33 KB
/
main.cpp
File metadata and controls
123 lines (100 loc) · 3.33 KB
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
#include <iostream>
#include <list>
#include <vector>
using namespace std;
#include "head.h"
#include "patterns.h"
//âîçâðàùàåò ñòðîêó íàçâàíèÿ
string PrintComponentType(const ComponentType type)
{
switch(type)
{
case ComponentType::CPU: return "CPU";
case ComponentType::GPU: return "GPU";
case ComponentType::RAM: return "RAM";
case ComponentType::Motherboard: return "Motherboard";
case ComponentType::Disk: return "Disk";
default: return "unknow";
}
}
// ñîçäàíèå ýêçêåìïëÿðà êëàññà ïî çàäàííîìó òèïó
Component *CreateComponent(ComponentType Type)
{
switch(Type)
{
case ComponentType::CPU: return new CPU();
case ComponentType::GPU: return new GPU();
case ComponentType::RAM: return new RAM();
case ComponentType::Motherboard: return new Motherboard();
case ComponentType::Disk: return new Disk();
}
}
//âûâîä îáúåêòîâ ñ ãàðàíòèåé áîëüøå n ìåÿöåâ
void Task1(ComponentContainer *componentBox, int n)
{
for(int i = 0; i < componentBox->GetCount(); i++)
{
const ComponentPtr currentComponent = componentBox->GetByIndex(i);
if(currentComponent->GetGuarant() >= n)
{
cout << i << " (" << PrintComponentType(currentComponent->GetType()) << " guarantee: " << currentComponent->GetGuarant() << " months)" << endl;
}
}
}
// Âûâîä òèï è õàðàêòêðèñòêè
void Task2(Iterator<ComponentPtr> * Iterator)
{
for(Iterator->First(); !Iterator->IsDone(); Iterator->Next())
{
const ComponentPtr CurrentComponent = Iterator->GetCurrent();
cout << PrintComponentType(CurrentComponent->GetType()) << endl;
CurrentComponent->GetCharacteristics();
cout << endl;
//CurrentComponent->GetCharacteristics();
}
}
// Âûâîä òèï è öåíà
void Task3(Iterator<ComponentPtr> * Iterator)
{
for(Iterator->First(); !Iterator->IsDone(); Iterator->Next())
{
const ComponentPtr CurrentComponent = Iterator->GetCurrent();
cout << PrintComponentType(CurrentComponent->GetType()) << " ";
cout << CurrentComponent->GetPrice() << " rub"<< endl;
//CurrentComponent->GetCharacteristics();
}
}
// ôóíêöèÿ âîçâðàùàåò ñëó÷àéíûé òèï
ComponentType GetRandomComponentType()
{
ComponentType a[5]{ComponentType::CPU, ComponentType::GPU,
ComponentType::RAM, ComponentType::Motherboard, ComponentType::Disk};
return *(a+getRandomNumber(0, 5));
}
int main()
{
// ðàíäîìíûå ÷èñëà
int a = getRandomNumber(0, 1000);
int b = getRandomNumber(0, 1000);
int c = getRandomNumber(0, 1000);
// èíèöèàëèçàöèÿ è çàïîëíåíèå ôàáðè÷íûì ìåòîæîì êîíòåéíåðà ìàññèâ
ComponentContainer array_container(b);
for(int i = 0; i < b; i++)
{
array_container.AddComponent(CreateComponent(GetRandomComponentType()));
}
// èíèöèàëèçàöèÿ è çàïîëíåíèå ôàáðè÷íûì ìåòîæîì êîíòåéíåðà âåêòîðà
VectorComponentContainer vector_container;
for(int i = 0; i < b; i++)
{
vector_container.AddComponent(CreateComponent(GetRandomComponentType()));
}
Iterator<ComponentPtr> *It_guarant = new ComponentGuarantDecorator(array_container.GetIterator(), 45);
Iterator<ComponentPtr> *It_data = new ComponentDataRangeDecorator(array_container.GetIterator(), 2015, 2018);
Task1(&array_container, 56);
Task2(It_guarant);
Task3(It_data);
delete It_guarant;
delete It_data;
return 0;
}