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
| unit Unit6;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.Buttons, Vcl.StdCtrls;
type
TForm1 = class(TForm)
OpenDialog1: TOpenDialog;
SaveDialog1: TSaveDialog;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label7: TLabel;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Edit4: TEdit;
Edit5: TEdit;
Edit6: TEdit;
Memo1: TMemo;
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
BitBtn1: TBitBtn;
Button5: TButton;
Label6: TLabel;
Edit7: TEdit;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure Button5Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
Type
TATC=record
data: string[40]; // дата
numbers: array[1..2] of int64; //массив номеров
tariff : extended; // тариф
time:integer; //время разговора
cityname:string[40]; //название города
citycode:word;
end;
Var
Fz : file of TATC; // Файл типа запись
Ft : TextFile; // Текстовой файл
ATC : array[1..100] of TATC; // Массив записей
nzap : integer; // Номер записи
FileNameZ, FileNameT : string; // Имя файла
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
I: integer;
begin
nzap:=nzap+1;
with ATC[nzap] do begin
data:=Edit1.Text;
numbers[1]:=StrToInt(Edit6.Text);
numbers[2]:=StrToInt(Edit7.Text);
citycode:=StrToInt(Edit2.Text);
cityname:=Edit3.Text;
time:=StrToInt(Edit4.Text);
tariff:=StrToFloat(Edit5.Text);
Memo1.Lines.Add(data+' '+IntToStr(numbers[1])+' '+ IntToStr(numbers[2])+' '+IntToStr(citycode)+' '+cityname+' '+IntToStr(time)+' '+FloatToStr(tariff));
end;
Write(fz,ATC[nzap]); // Запись в файл
Edit1.Text:='';
Edit2.Text:='';
Edit3.Text:='';
Edit4.Text:='';
Edit5.Text:='';
Edit6.Text:='';
Edit7.Text:='';
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
OpenDialog1.Title :='Создать новый файл'; // Изменение заголовка окна диалога
if OpenDialog1.Execute then // Выполнение стандартного диалога выбора имени файла
begin
FileNameZ:= OpenDialog1.FileName; // Возвращение имени дискового файла
AssignFile(Fz, FileNameZ); // Связывание файловой переменной Fz c именем файла
Rewrite(Fz); // Создание нового файла
end;
Button1.Show;
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
if OpenDialog1.Execute then // Выполнение стандартного диалога выбора имени файла
begin
FileNameZ:= OpenDialog1.FileName; // Возвращение имени дискового файла
AssignFile(Fz, FileNameZ); // Связывание файловой переменной Fz c именем файла
Reset(Fz); // Открытие существующего файла
end;
while not eof(fz) do begin
nzap:=nzap+1;
Read(fz,ATC[nzap]); // Чтение записи из файла
with ATC[nzap] do
Memo1.Lines.Add(data+' '+IntToStr(numbers[1])+' '+ IntToStr(numbers[2])+' '+IntToStr(citycode)+' '+cityname+' '+IntToStr(time)+' '+FloatToStr(tariff));
end;
end;
procedure TForm1.Button4Click(Sender: TObject);
var i:word;
begin
if SaveDialog1.Execute then // Выполнение стандартного диалога выбора имени файла
begin
FileNameT:= SaveDialog1.FileName; // Возвращение имени дискового файла
AssignFile(Ft, FileNameT); // Связывание файловой переменной Ft c именем файла
Rewrite(Ft); // Открытие нового текстового файла
end;
for i:=1 to nzap do
with ATC[i] do Writeln(Ft,i:4,'. ',data,numbers[1],numbers[2],citycode,cityname,time,tariff);
// Запись в текстовой файл
CloseFile(Ft); // Закрытие текстового файла
end;
procedure TForm1.Button5Click(Sender: TObject);
var
i,j,k:integer;
temp,temp2,temp3:extended;
begin
temp:=0;
temp2:=0;
temp3:=0;
for i:=1 to nzap do
for j := 2 to nzap do
begin
with ATC[i] do begin
if (cityname[i]=cityname[j]) then begin
temp:=tariff*time;
with ATC[j] do
temp2:=tariff*time;
temp3:=temp+temp2;
end;
end;
Memo1.Lines.Add('temp '+FloatToStr(temp)+' '+'temp2 '+FloatToStr(temp2));
end;
Memo1.Lines.Add('стоимость равна '+FloatToStr(temp3));
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Memo1.Clear;
Button1.Hide; //Сделать невидимой кнопку "Ввести запись"
nzap := 0;
end;
end. |