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
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
| //---------------------------------------------------------------------------
#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <Grids.hpp>
#include <Menus.hpp>
#include <Dialogs.hpp>
#include <iostream>
#include <fstream>
#include <stdio.h>
#define LName "Имя :"
#define LColor "Цвет :"
#define LPower "Мощность,л/с :"
#define LMass "Масса,кг :"
#define LCargo "Груз,т :"
#define LPassPL "Мест :"
#define LVCargo "Объем груза,м3 :"
#define TtypeAUTO "<АВТО>"
#define TtypePASS "<Пассажирский>"
#define TtypeTRUCK "<Грузовой>"
#define TtypeCARPAS "<Грузопассажирский>"
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
TComboBox *ComboBox1;
TStringGrid *StringGrid1;
TCheckBox *CheckBox1;
TButton *Button1;
TButton *NewAuto;
TMainMenu *MainMenu1;
TMenuItem *File1;
TMenuItem *CreateNewObject1;
TMenuItem *Open1;
TMenuItem *Save1;
TMenuItem *Close1;
TMenuItem *Exit1;
TOpenDialog *OpenDialog1;
TSaveDialog *SaveDialog1;
void __fastcall FormCreate(TObject *Sender);
void __fastcall ComboBox1Change(TObject *Sender);
void __fastcall CheckBox1Click(TObject *Sender);
void __fastcall Button1Click(TObject *Sender);
void __fastcall NewAutoClick(TObject *Sender);
void __fastcall Exit1Click(TObject *Sender);
void __fastcall CreateNewObject1Click(TObject *Sender);
void __fastcall Save1Click(TObject *Sender);
private: // User declarations
public: // User declarations
__fastcall TForm1(TComponent* Owner);
};
/////////////////////////////функция очистки StringGrid//////////////////////////
void __fastcall ClearStringGrid(TStringGrid *StringGrid)
{
for (int i = 0; i < (StringGrid->ColCount); ++i)
{
for (int j = 0; j < (StringGrid->RowCount); ++j)
{
StringGrid->Cells[i][j] = "";
}
}
}
/*
/////////////////////////////////Класс Интерфейс////////////////////////////////
*/
class Auto_Interface
{
public:
Auto_Interface(){;}
virtual ~Auto_Interface(){;}
virtual void get_info(TStringGrid *StringGrid)=0;//вывести информацию из класса
virtual void giv_info(TStringGrid *StringGrid, int n)=0;// записать информацию в класс
virtual void save_to_file(FILE *F)=0;// сохранить в файл.
};
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
/*
/////////////////////////////////Класс Авто Общий////////////////////////////////
*/
class auto_general: public Auto_Interface
{
public:
auto_general();
auto_general(AnsiString nm,AnsiString cl,int pw,int m);
~auto_general(){;}
void get_info(TStringGrid *StringGrid);
void giv_info(TStringGrid *StringGrid, int n);
void save_to_file(FILE *F);
protected:
AnsiString name;
AnsiString color;
int power_engine;
int mass;
};
auto_general::auto_general()
{
name = "Undefined_name";
color = "Undefined_color";
power_engine = 0;
mass = 0;
}
auto_general::auto_general(AnsiString nm,AnsiString cl,int pw,int m)
{
name =nm;
color =cl;
power_engine = pw;
mass = m;
}
/*
функция выводит в StringGrid
*/
void auto_general::get_info(TStringGrid *StringGrid)
{
if (StringGrid->RowCount!=5)StringGrid->RowCount=5;
int i;
i = StringGrid->ColCount;
StringGrid->ColCount=StringGrid->ColCount+1;
StringGrid->FixedCols=1;
StringGrid->Cells[0][0]= "Тип :"; StringGrid->Cells[i][0]=TtypeAUTO;
StringGrid->Cells[0][1]= LName; StringGrid->Cells[i][1]=name;
StringGrid->Cells[0][2]= LColor; StringGrid->Cells[i][2]=color;
StringGrid->Cells[0][3]= LPower; StringGrid->Cells[i][3]=power_engine;
StringGrid->Cells[0][4]= LMass; StringGrid->Cells[i][4]=mass;
}
/*
функция записыват данные из StringGrid
*/
void auto_general::giv_info(TStringGrid *StringGrid, int n)
{
name= StringGrid->Cells[n][1];
color= StringGrid->Cells[n][2];
power_engine= StrToInt(StringGrid->Cells[n][3]);
mass= StrToInt(StringGrid->Cells[n][4]);
}
void auto_general::save_to_file(FILE *F)
{
fprintf(F,"\nИМЯ : %s\nЦвет : %s\nМощность : %i л.с\nМасса : %i кг\n",name,color,power_engine,mass);
}
//---------------------------------------------------------------------------
/*
/////////////////////////////////класс авто Пассажирский транспорт////////////////////////////////
*/
//---------------------------------------------------------------------------
class passenger: virtual public auto_general
{
public:
passenger();
passenger(int ns);
passenger(AnsiString nm,AnsiString cl,int pw,int m,int ns);
~passenger(){;}
void get_info(TStringGrid *StringGrid);
void giv_info(TStringGrid *StringGrid, int n);
int get_numseats(void);
void giv_numseats(int NumS);
private:
int number_seats;
};
passenger::passenger()
{
number_seats =1;
}
passenger::passenger(int ns)
{
number_seats =ns;
}
passenger::passenger(AnsiString nm,AnsiString cl,int pw,int m,int ns)
{
name =nm;
color =cl;
power_engine = pw;
mass = m;
number_seats =ns;
}
void passenger::get_info(TStringGrid *StringGrid)
{
int i;
i = StringGrid->ColCount;
auto_general::get_info(StringGrid);
if (StringGrid->RowCount!=6)StringGrid->RowCount=6;
StringGrid->Cells[i][0]= TtypePASS;
StringGrid->Cells[0][5]=LPassPL; StringGrid->Cells[i][5]=number_seats;
}
void passenger::giv_info(TStringGrid *StringGrid, int n)
{
auto_general::giv_info(StringGrid, n);
number_seats = StrToInt(StringGrid->Cells[n][5]);
}
int passenger::get_numseats()
{
return(number_seats);
}
void passenger::giv_numseats(int NumS)
{
number_seats=NumS;
}
//---------------------------------------------------------------------------
/*
/////////////////////////////////Класс Авто Грузовой транспорт////////////////////////////////
*/
//---------------------------------------------------------------------------
class truck: virtual public auto_general
{
public:
truck();
truck(int cg);
~truck(){;}
void get_info(TStringGrid *StringGrid);
void giv_info(TStringGrid *StringGrid, int n);
int get_Mcargo(void);
void giv_Mcargo(int Mc);
private:
int Mcargo; //масса груза в тоннах
};
truck::truck()
{
Mcargo = 0;
}
truck::truck(int cg)
{
Mcargo =cg;
}
void truck::get_info(TStringGrid *StringGrid)
{
int i;
i = StringGrid->ColCount;
auto_general::get_info(StringGrid);
if (StringGrid->RowCount!=6)StringGrid->RowCount=6;
StringGrid->Cells[i][0]= TtypeTRUCK;
StringGrid->Cells[0][5]=LCargo; StringGrid->Cells[i][5]=Mcargo;
}
void truck::giv_info(TStringGrid *StringGrid, int n)
{
auto_general::giv_info(StringGrid, n);
Mcargo = StrToInt(StringGrid->Cells[n][5]);
}
int truck::get_Mcargo()
{
return(Mcargo);
}
void truck::giv_Mcargo(int Mc)
{
Mcargo=Mc;
}
//---------------------------------------------------------------------------
/*
/////////////////////////////////Класс Грузопассажирского Авто////////////////////////////////
*/
class CargoPass: public passenger, public truck
{
public:
CargoPass();
CargoPass(int V);
~CargoPass(){;}
void get_info(TStringGrid *StringGrid);
void giv_info(TStringGrid *StringGrid, int n);
private:
int Vcargo;
};
//---------------------------------------------------------------------------
CargoPass::CargoPass()
{
Vcargo=1;
}
//---------------------------------------------------------------------------
CargoPass::CargoPass(int V)
{
Vcargo=V;
}
//---------------------------------------------------------------------------
void CargoPass::get_info(TStringGrid *StringGrid)
{
int i;
i = StringGrid->ColCount;
auto_general::get_info(StringGrid);
if (StringGrid->RowCount!=8)StringGrid->RowCount=8;
StringGrid->Cells[i][0]= TtypeCARPAS;
StringGrid->Cells[0][5]= LPassPL; StringGrid->Cells[i][5]=passenger::get_numseats();
StringGrid->Cells[0][6]= LCargo; StringGrid->Cells[i][6]=truck::get_Mcargo();
StringGrid->Cells[0][7]= LVCargo; StringGrid->Cells[i][7]=Vcargo;
}
//---------------------------------------------------------------------------
void CargoPass::giv_info(TStringGrid *StringGrid, int n)
{
name= StringGrid->Cells[n][1];
color= StringGrid->Cells[n][2];
power_engine= StrToInt(StringGrid->Cells[n][3]);
mass= StrToInt(StringGrid->Cells[n][4]);
passenger::giv_numseats( StrToInt(StringGrid->Cells[n][5]));
truck::giv_Mcargo(StrToInt(StringGrid->Cells[n][6]));
Vcargo = StrToInt(StringGrid->Cells[n][7]);
}
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif |