30/09/2018, 16:00

Mọi người xem bài nay cần sửa ntn cho hop lí?

Uses crt;
Type


Date = Record
dd:1..31;
mm:1..12;
yy:2000..2010;
End;
Hour = Record
h:0..23;
p:0..59;
End;
contro1 = ^Customer;
Cus = Record
Name:String[25];
Numb:String[7];
Mone:Real;
NH,LC,X,RX:Byte;
End;
Customer =record
info:cus;
next:contro1;
end;

contro2 = ^Dienthoai;
Phone = Record
Name:String[25];
Numb:String[7];
Minu:Integer;
Mone:Real;
NH,LC,X,RX:Byte;
Area:String;
End;
Dienthoai =record
info: Phone;
next:contro2;
end;



var
p,q,Temp,Fist:contro1;
p1,Fist1:contro2;
Name,SDT,Mien: String;
Day: Date;
Gio:Hour;

Phut:integer;
ST,ST1,ST2:string;
f:text;
g,h:text;
HS:integer;
Tien:real;
NH,LC,X,RX:byte;
TT:real;
TNH,TLC,TX,TRX:byte;
i:integer;

{----------------------------------------------------------------}
Function NgayDB(Day: Date):Boolean;
Var Thu:Byte;
Begin
Day.yy:= 1900 + (Day.yy Mod 1900);
If Day.mm < 3 Then
Begin
Day.mm:= Day.mm + 12;
Day.yy:= Day.yy - 1;
End;
Thu:= (ABS(Day.dd + 2*Day.mm + 3*(Day.mm + 1) Div 5 + Day.yy + Day.yy Div 4)) Mod 7;
If Thu=0 Then NgayDB:=True
Else NgayDB:=False;
End;
{----------------------------------------------------------------}
Procedure Xuly1(ST:string;Var Name:string;Var SDT:String);
var
i,j,k:integer;
begin
i:=1;
While(ST[i]<>';') do
inc(i);
j:=i-1;
k:=i+2;
Name:=copy(ST,1,j);
SDT:=copy(ST,k,(length(ST)-k)+1);
end;
{----------------------------------------------------------------}
procedure Xuly2(ST:String; Var SDT:String; Var Phut:Integer; Var Gio:Hour; Var Day: Date; Var Mien:String);
var
mode:integer;
i,j:integer;
trong,tg:integer;
temp,tam:string;
tgio:string;
tngay:string;
a,b,c,d,e:integer;
k,l,m,n:integer;
begin
trong:=0;
for i:=1 to length(ST) do
begin
if (ST[i]=' ') or (i=length(ST)) then
begin
inc(trong);
case trong of
1:begin
a:=i;
end;
2:begin
b:=i;
end;
3:begin
c:=i;
end;
4:begin
d:=i;
end;
5:begin
e:=i
end;
end;
end;
end;
SDT:=copy(ST,1,a-1);
temp:=copy(ST,a+1,(b-a-1));
Val(temp,Phut,mode);
tgio:=copy(ST,b+1,(c-b-1));
tngay:=copy(ST,c+1,(d-c-1));
Mien:=copy(ST,d+1,e-d);
j:=1;
while(tgio[j]<>'.') do
begin
j:=j+1;
end;
tam:=copy(tgio,1,j-1);
Val(tam,Gio.h,mode);
val(copy(tgio,(length(tam)+2),(length(tgio)-length(tam)-1)),Gio.p,mode);
tg:=0;
for k:=1 to length(tngay) do
begin
if (tngay[k]='/') or (k=length(tngay)) then
begin
tg:=tg+1;
case tg of
1:begin
l:=k;
end;
2:begin
m:=k;
end;
3:begin
n:=k;
end;
end;
end;
end;
Val(copy(tngay,1,l-1),Day.dd,mode);
Val(copy(tngay,l+1,m-l-1),Day.mm,mode);
val(copy(tngay,m+1,n-m),Day.yy,mode);
End;

{----------------------------------------------------------------}
Function Giamgia(ST: String): Boolean;
Begin
Giamgia:= False;
Xuly2(ST,SDT,Phut,Gio,Day,Mien);
If NgayDB(Day) Then Giamgia:= True;
If (Gio.h = 23) Or (Gio.h < 5) Then Giamgia:=True;

End;
{----------------------------------------------------------------}
begin

begin
assign(h,'customer.dat');
reset(h);
fist:=nil;
while not eof(h) do
begin
readln(h,ST);
New(P);
Xuly1(ST,Name,SDT);
P^.Info.Name:=Name;
P^.info.Numb:=SDT;
P^.Info.NH:=0;
P^.Info.LC:=0;
P^.Info.X:=0;
P^.Info.RX:=0;
P^.next:=fist;
fist:=P;
end;
close(h);
end;

begin
assign(g,'phone.dat');
reset(g);
fist1:=nil;
while not Eof(g) do
begin
readln(g,ST1);
New(P1);
Xuly2(ST1,SDT,Phut,Gio,Day,Mien);
P1^.info.Numb:=SDT;
P1^.info.Minu:=Phut;
P1^.info.Mone:=0;
P1^.info.NH:=0;
P1^.info.LC:=0;
P1^.info.X:=0;
P1^.info.RX:=0;
P1^.info.Area:=Mien;
for i:=1 to length(Mien) do
begin
case Mien[1] of
'N':begin
HS:=1;
P1^.info.NH:=1;
end;
'L':begin
HS:=2;
P1^.info.LC:=1;
end;
'X':begin
Hs:=3;
P1^.info.X:=1;
end;
'R':begin
HS:=4;
P1^.info.RX:=1;
end;
end;
end;
if Giamgia(ST1) then
P1^.info.Mone:=400*0.7*HS*Phut
else
P1^.info.Mone:=400*HS*Phut;
P1^.next:=fist1;
fist1:=P1;
end;
close(g);
end;


begin
Tien:=0;
NH:=0;LC:=0;X:=0;
P:=fist;
while P<>nil do
begin
P1:=fist1;
while P1<>nil do
begin
if (P^.info.Numb=P1^.info.Numb) then
begin
Tien:=P1^.info.Mone;
NH:=P1^.info.NH;
LC:=P1^.info.LC;
X:=P1^.info.X;
RX:=P1^.info.RX;
end;
P1:=P1^.next;
end;
P^.info.Mone:=Tien;
P^.info.NH:=NH;
P^.info.LC:=LC;
P^.info.X:=X;
P^.info.RX:=RX;
P:=P^.next;
end;
end;


begin
assign(f,'result.dat');
rewrite(f);
TT:=0;
TNH:=0;
TLC:=0;
TX:=0;
TRX:=0;
i:=0;
writeln(f,' CHUONG TRINH TINH TIEN DIEN THOAI');
writeln(f,' THONG TIN KHACH HANG ');
writeln(f,'STT Ho va ten Tongtien NH LC X RX');
P:=fist;
while P<>nil do
begin
i:=i+1;
writeln(f,i:3,' ',P^.info.Name:25,' ',P^.info.Mone:9,' ',P^.info.NH:3,
' ',P^.info.LC:3,' ',P^.info.X,' ',P^.info.RX:3);
TT:=TT+P^.info.Mone;
TNH:=TNH+P^.info.NH;
TLC:=TLC+P^.info.LC;
TX:=TX+P^.info.X;
TRX:=TRX+P^.info.RX;
P:=P^.next;
end;
writeln(f,' THONG TIN TONG THE ');
writeln(f,'Tong so tien thu duoc: ',TT);
writeln(f,'So cuoc goi Noi hat : ',TNH);
writeln(f,'So cuoc goi Lan can : ',TLC);
writeln(f,'So cuoc goi di Xa : ',TX);
writeln(f,'So cuoc goi di Rat xa: ',TRX);
close(f);
end;
end.
buithaiminh viết 18:11 ngày 30/09/2018

Đọc bài này để biết cách post code lên diễn đàn: Cách post Code dùng Markdown trong Category Programming

Bài liên quan
0