Телефонная книга

  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
program project1;
{$APPTYPE CONSOLE}
uses CRT, SysUtils;
type person=record
name:shortstring;
age:integer;
phone:longint;
end;
personfile=file of person;
var a:array[1..200] of person;
b:array[1..200] of person;
pf:personfile;
command,i:integer;
id:integer=1;
function add_user(id:integer):string;
begin
writeln('------------------add user--------------------');
write('Enter name:');
readln(a[id].name);
write('Enter age:');
readln(a[id].age);
write('Enter phone:');
readln(a[id].phone);
writeln('------------------User info-------------------');
writeln('Name: ',a[id].name, ' Age: ', a[id].age,' Phone: ', a[id].phone);
writeln('----------------------------------------------');
writeln;
end;
function list_user(id:integer):string;
var i:integer;
begin
writeln('------------------Users list-----------------');
for i:=1 to id-1 do
begin
writeln(i, ') Name: ',a[i].name, ' Age: ', a[i].age,' Phone: ', a[i].phone);
end;
writeln('----------------------------------------------');
result:='';
end;
function find(id:integer):string;
var find_name:string;
find_phone:integer;
begin
i:=1;
writeln('------------------Find user-----------------');
write('Enter name:');
readln(find_name);
if(find_name='') then
begin
write('Enter phone:');
readln(find_phone);
for i:=1 to id-1 do
begin
if (find_phone=a[i].phone) then
writeln(i, ') Name: ',a[i].name, ' Age: ', a[i].age,' Phone: ', a[i].phone);
end;
end
else
begin
for i:=1 to id-1 do
begin
if (find_name=a[i].name) then
writeln(i, ') Name: ',a[i].name, ' Age: ', a[i].age,' Phone: ', a[i].phone);
end;
end;
writeln('----------------------------------------------');
end;
function save_file(id:integer):string;
var path:string;
i:integer;
begin
writeln('------------------Save base-------------------');
write('Enter path(press Return if "c:\base.txt"): ');
readln(path);
if(path='') then path:='c:\base.txt';
assign(pf,path);
rewrite(pf);
for i:=1 to id-1 do
begin
write(pf, a[i]);
end;
Close(pf);
writeln('----------------------------------------------');
writeln;
end;
function read_file():string;
var path:string;
begin
i:=1;
writeln('------------------Read base-------------------');
write('Enter path(press Return if "c:\base.txt"): ');
readln(path);
if(path='') then path:='c:\base.txt';
assign(pf,path);
reset(pf);
while not (eof(pf)) do
begin
read(pf,a[i]);
writeln(i, ') Name: ',a[i].name, ' Age: ', a[i].age,' Phone: ', a[i].phone);
i:=i+1;
end;
id:=i;
close(pf);
writeln('----------------------------------------------');
writeln;
end;
begin
command := 1;
while command <> 0 do
begin
begin
writeln('------------Menu-------------------');
writeln('| Press 1 to add new user |');
writeln('| Press 2 to list all users |');
writeln('| Press 3 to find user |');
writeln('| Press 4 to save base to file |');
writeln('| Press 5 to read base from file |');
writeln('| Press 0 to quit |');
writeln('-----------------------------------');
readln(command);
if (command=1)then
begin
ClrScr;
add_user(id);
end;
if(command=2) then
begin
ClrScr;
list_user(id);
end;
if(command=3) then
begin
ClrScr;
find(id);
end;
if(command=4) then
begin
ClrScr;
save_file(id);
end;
if(command=5) then
begin
ClrScr;
read_file();
end;
end;
end;
writeln('Press any key to exit');
readln;
end.