dang tep
program baitapfile;
Uses crt;
Type Quanlyhoso=record
MaCB:string[5];
Hoten:string[20];
Phong:string[5];
HSL:string[5];
end;
DS=file of Quanlyhoso;
var f:DS; DS1,ds2:Quanlyhoso; i,n:integer;lam:char;bMaCB:string[5];
procedure TaoDS;
Begin
writeln;
Writeln('Nhap tong tin can bo');
writeln;
Assign(f,'QLHS.dat');
rewrite(f);
lam:='C';
i:=1;
repeat
with DS1 do
Write('Ma can bo: ');readln(MaCB);
Write('Ho va ten: ');readln(Hoten);
Write('Phong ban: ');readln(Phong);
Write('He so luong: ');readln(HSL);
end;
i:=i+1;
write(f,DS1);
writeln;
Write('Nhap tiep hay thoi? (C/K): ');readln(lam);
writeln;
until upcase(lam)='K';
close(f);
writeln;
end;
procedure Hienthi;
writeln(' Danh sach can bo ');
Assign(f,'QLHS.dat');
reset(f);
writeln('MaCB':4,'Ho va ten':16,'Phong ban':14,'He so luong':14);
while not eof(f) do
with DS1 do
Read(f,DS1);
Writeln(MaCB:3,Hoten:18,Phong:10,HSL:13);
end;
end;
close(f);
end;
procedure Them;
reset(f);
writeln(' Nhap them can bo vao danh sach ');
Seek(f,filesize(f));
with DS1 do
Write('Ma can bo: ');readln(MaCB);
Write('Ho va ten: ');readln(Hoten);
Write('Phong ban: ');readln(Phong);
Write('He so luong: ');readln(HSL);
end;
Seek(f,filesize(f));
write(f,DS1);
close(f);
end;
procedure timvasua;
Var Kt:boolean;
reset(f);
writeln('Can bo can sua co ma la: CNP12');
writeln;
KT:=false;
while not eof(f) do
read(f,DS1);
with ds1 do
if MaCB='CNP12' then
KT:=True;
HSL:='2.67';
write('He so luong sua thanh: ',HSL:9);
n:=filepos(f);
seek(f,n-1);
write(f,DS1);
end;
End;
if kt=false then writeln('Khong tim thay du lieu de sua');
close(f);
end;
procedure xoa;
var f1:ds; i:integer;KT:boolean;
assign(f,'QLHS.dat');
reset(f);
assign(f1,'Dulieu1.dat');
rewrite(f1);
KT:=False;
while not eof(f) do
read(f,DS1);
if DS1.MaCB='CNP20' then KT:=True
else write(f1,DS1);
end;
if Kt=False then writeln('Trong tep ban dau khong ban ghi co ma la CNP20')
else writeln('Tep moi la tep Dulieu1.dat');writeln;
close(f);
close(f1);
erase(f);
rename(f1,'QLHS.dat');
end;
clrscr;
textcolor(red);
writeln;
Writeln(' MENU CHUONG TRINH CHINH ');
writeln;
textcolor(white);
Writeln(' 1:Tao danh sach ');
Writeln(' 2:Hien thi danh sach ');
Writeln(' 3:Them can bo ');
Writeln(' 4:Tim va sua thong tin can bo ');
Writeln(' 5:Xoa can bo');
Writeln(' 6:Nhan phim 9 de ket thuc ');
writeln;
repeat
writeln;
textcolor(green);
write('Ban chon cong viec nao? ');readln(n);
writeln;
textcolor(white);
case n of
1:TaoDS;
2:Hienthi;
3:begin Them; Hienthi; end;
4:begin TimvaSua; Hienthi; end;
5:begin xoa; Hienthi; end;
end;
until n=9;
end.
Bạn đang đọc truyện trên: AzTruyen.Top