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
| #include <iostream>
#include <vector>
using namespace std;
class mes // AbstractProductA
{
public:
char *result;
char stroka[100];
};
class dat: public mes // ConcreteProductA1
{public:
void Stroka()
{
cout<< "Fail dat"<<endl;
cout << "Vvedite stroku "<<endl;
result=gets(stroka);
}
void fail()
{
FILE *f=NULL;
f = fopen("dat.txt", "a+");
if (f == NULL)
{
cout << "no fail ";
system("pause");
}
fprintf(f, "%s", __TIME__);
fprintf(f, "%s", " || ");
fprintf(f, "%s", __DATE__);
fprintf(f, "%s", " || ");
fprintf(f, "%s",result);
fprintf(f, "%s", " || ");
}
};
class log1: public mes // ConcreteProductA2
{public:
void Stroka()
{ cout<< "Fail log1"<<endl;
cout << "Vvedite stroku "<<endl;
result=gets(stroka);
}
void fail()
{
FILE *f=NULL;
f = fopen("log1.txt", "a+");
if (f == NULL)
{
cout << "no fail ";
system("pause");
}
fprintf(f, "%s", __TIME__);
fprintf(f, "%s", " || ");
fprintf(f, "%s", __DATE__);
fprintf(f, "%s", " || ");
fprintf(f, "%s",result);
fprintf(f, "%s", " || ");
}
};
class sms: public mes // ConcreteProductA1
{public:
void Stroka()
{
cout<< "Fail sms"<<endl;
cout << "Vvedite stroku "<<endl;
result=gets(stroka);
}
void fail()
{
FILE *f=NULL;
f = fopen("sms.txt", "a+");
if (f == NULL)
{
cout << "no fail ";
system("pause");
}
fprintf(f, "%s", __TIME__);
fprintf(f, "%s", " || ");
fprintf(f, "%s", __DATE__);
fprintf(f, "%s", " || ");
fprintf(f, "%s",result);
fprintf(f, "%s", " || ");
}
};
class FAIL
{
public:
vector<sms> s;
vector<dat> d;
vector<log1> l;
void info() {
int i;
for(i=0; i<s.size(); ++i) { s[i].Stroka();s[i].fail();}
for(i=0; i<d.size(); ++i) { d[i].Stroka();d[i].fail();}
for(i=0; i<l.size(); ++i) { l[i].Stroka();l[i].fail();}
}
};
class FAILBuilder
{
protected:
FAIL* p;
public:
FAILBuilder(): p(0) {}
virtual ~FAILBuilder() {}
virtual void createFAIL() {}
virtual void buildsms() {}
virtual void buildlog1() {}
virtual void builddat() {}
virtual FAIL* getFAIL() { return p; }
};
class RomanFAILBuilder: public FAILBuilder
{
public:
void createFAIL() { p = new FAIL; }
void buildsms() { p->s.push_back( sms()); }
void builddat() { p->d.push_back( dat()); }
};
class PavelFAILBuilder: public FAILBuilder
{
public:
void createFAIL() { p = new FAIL; }
void buildsms() { p->s.push_back( sms()); }
void buildlog1() { p->l.push_back( log1()); }
};
class Director
{
public:
FAIL* createFAIL( FAILBuilder & builder )
{
builder.createFAIL();
builder.buildsms();
builder.builddat();
builder.buildlog1();
return( builder.getFAIL());
}
};
int main()
{
Director dir;
RomanFAILBuilder ra_builder;
PavelFAILBuilder pa_builder;
FAIL * ra = dir.createFAIL( ra_builder);
FAIL * pa = dir.createFAIL( pa_builder);
cout << "Roman fail:" << endl;
ra->info();
cout << "\nPavel fail:" << endl;
pa->info();
return 0;
} |