dang fifo
Program baitapFIFO;
Uses crt;
Type DS=^Quanlycanbo;
Quanlycanbo=record
MaCB:string[5];
Hoten:string[20];
Phong:string[5];
HSL:real;
Tiep:DS;
end;
Var ct,ct1,ctcuoi,ctdau:DS; n:integer;SMaCB:string[5];i,k:integer;
{Tao danh sach can bo}
Procedure TaoDS;
var lam:char; i,k:integer;
begin
writeln('Yeu cau ma can bo phai nhap chu hoa');
writeln('Nhap thong tin can bo');
lam:='C';
ctdau:=nil;
Repeat
New(ct);
With ct^ do
begin
write('Ma can bo: ');readln(MaCB);
write('Ho va ten: ');readln(Hoten);
write('Phong ban: ');readln(Phong);
write('He so luong: ');readln(HSL);
For i:=1 to k do MaCB[k]:=upcase(MaCB[k]);
end;
if ctdau=nil then ctdau:=ct
else ctcuoi^.Tiep:=ct;
ctcuoi:=ct;
ctcuoi^.Tiep:=nil;
write('Nhap tiep hay thoi? (C/K): ');readln(lam);
writeln;
Until Upcase(lam)='K';
end;
{Duyet danh sach can bo tu dau ve cuoi}
Procedure DuyetDS;
begin
writeln(' Danh sach can bo');
writeln;
ct:=ctdau;
writeln('MaCB':3,'Ho va ten':15,'Phong ban':13,'He so luong':13);
while ct<>nil do
begin
with ct^ do
begin
writeln(MaCB:2,Hoten:17,Phong:10,HSL:12:2);
ct:=ct^.tiep;
For i:=1 to k do MaCB[k]:=upcase(MaCB[k]);
end;
end;
end;
{Them can bo vao cuoi danh sach}
Procedure ThemCB;
var n:string[5];
begin
writeln;
writeln(' Them mot can bo vao cuoi danh sach ');
New(ct);
With ct^ do
begin
write('Ma can bo: ');readln(MaCB);
write('Ho va ten: ');readln(Hoten);
write('Phong ban: ');readln(Phong);
write('He so luong: ');readln(HSL);
end;
ct^.tiep:=nil;
If ctcuoi=nil then
begin
ctdau:=ct;
ctcuoi:=ct;
end
else
begin
ctcuoi^.tiep:=ct;
ctcuoi:=ct;
end;
end;
{Tim va Sua can bo co ma CNP12 }
procedure TimvaSuaCB;
var k,i:integer;
begin
writeln('Yeu cau ma can bo can sua la CNP12');
write('Nhap ma can bo can sua: ');readln(SMaCB);
ct1:=ctdau;
while (ct1<>nil) and (ct1^.MaCB<>SMaCB)do
ct1:=ct1^.tiep;
if (ct1^.MaCB=SMaCB)and (ct1^.MaCB='CNP12')
then
ct1^.HSL:=2.67
else
writeln('Du lieu ban nhap khong dung yeu cau');
end;
procedure Xoa;
begin
writeln('Yeu cao xoa can bo co ma la: CNP20');
write('Nhap ma can bo can xoa: ');readln(SMaCB);
ct:=ctdau;
while (ct<>nil) and (ct^.MaCB<>SMaCB) do
begin
ct1:=ct;
ct:=ct^.Tiep;
end;
if ((ct=ctdau) and(ct^.MaCB<>'CNP20'))or((ct<>ctdau) and(ct^.MaCB<>'CNP20'))then
writeln('Du lieu ban nhap khong dung yeu cau')
else
if (ct=ctdau) and(ct^.MaCB='CNP20') then ctdau:=ct^.Tiep
else ct1^.Tiep:=ct^.Tiep;
end;
begin
clrscr;
writeln;
writeln;
textcolor(red);
writeln(' MENU CHUONG TRINH CHINH ');
writeln;
textcolor(white);
writeln(' 1:Tao danh sach ');
writeln(' 2:Duyet danh sach ');
writeln(' 3:Them can bo ');
writeln(' 4:Tim va sua thong tin can bo ');
writeln(' 5:Xoa ho so can bo ');
writeln(' 6:Nham phim 9 de ket thuc ');
writeln;
Repeat
textcolor(green);
write('Ban chon cong viec nao? ');readln(n);
writeln;
textcolor(white);
Case n of
1:TaoDS;
2:DuyetDS;
3:begin ThemCB; DuyetDS; end;
4:begin TimvaSuaCB; duyetDS; end;
5:begin Xoa; DuyetDS; end;
end;
writeln('Nhan phim 9 de dung lai ');
Until n=9;
end.
Bạn đang đọc truyện trên: AzTruyen.Top