windy angel
New member
- Xu
- 0
Ai giúp wind một số tài liệu về bài tập, chạy chương trình pascal dạng làm việc với tệp với
Wind cảm ơn
Wind cảm ơn
Ai giúp wind một số tài liệu về bài tập, chạy chương trình pascal dạng làm việc với tệp với
Wind cảm ơn
Mình kiếm tìm được mấy bài này, bạn tham khảo thêm
Program Vi_du_1;
Type
St20 = String[20];
St10 = String[10];
SinhVien = record
Hoten: St20;
Ngaysinh,Quequan: St10;
DiemTb: real;
Xeploai: Char;
end;
Var
f: File of SinhVien;
filename:String;
Sv: sinhvien;
Bhoten:st20;
i:word;
Begin
write('Nhap ten file: ');
readln(filename);
assign(f,filename);
rewrite(f);
i:=1;
repeat
writeln('Nhap thong tin cua cac sinh vien');
writeln('Thong tin cua sinh vien thu ', i);
write('Ho ten: ');
readln(Bhoten);
if Bhoten <> '' then
begin
sv.hoten:= Bhoten;
write('Ngay sinh (dd/mm/yyyy): ');
readln(sv.ngaysinh);
write('Quequan: ');
readln(sv.quequan);
write('Diem trung binh: ');
readln(sv.diemtb);
if sv.diemtb<5 then
sv.xeploai:='D'
else
if sv.diemtb<6.5 then
sv.xeploai:='C'
else
if sv.diemtb<8 then
sv.xeploai:='B'
else
sv.xeploai:='A';
write(f,sv);
end;
inc(i);
until Bhoten = '';
close(f);
end.
[FONT=Verdana]
Program Vi_du_2;
Type
St20 = String[20];
St10 = String[10];
SinhVien = record
Hoten: St20;
Ngaysinh,Quequan: St10;
DiemTb: real;
Xeploai: Char;
end;
Var
f: File of SinhVien;
Sv: sinhvien;
Bhoten:st20;
i:word;
Begin
assign(f,'Sinhvien.dat');
{$I-}
reset(f);
{$I+}
if IOResult <> 0 then
Begin
writeln('File khong ton tai');
exit;
End;
writeln(#32:10, 'DANH SACH SINH VIEN');
writeln(#32:6,'HO TEN',#32:8,'NGAY SINH',#32:4,'QUE QUAN DTB');
while not eof(f) do
begin
read(f,sv);
with sv do
writeln(hoten,#32:20,length(hoten),ngaysinh,#32:2,quequan,#32:10- length(quequan),Diemtb:5:2);
end;
close(f);
readln;
End.[/FONT]
Program Vi_du_3;
Type
St20 = String[20];
St10 = String[10];
SinhVien = record
Hoten: St20;
Ngaysinh,Quequan: St10;
DiemTb: real;
Xeploai: Char;
end;
Var
f: File of SinhVien;
filename:String;
Sv: sinhvien;
Bhoten:st20;
n:word;
Begin
assign(f,'sinhvien.dat');
{$I-}
reset(f);
{$I+}
if IOResult <>0 then
begin
writeln('File khong ton tai');
exit;
end;
n:=0;
writeln('Danh sach sinh vien dat loai kha tro len');
while not Eof(f) do
begin
read(f,sv);
with sv do
if xeploai <= 'B' then { (xeploai = ‘B’) or (xeploai = ‘A’) }
begin
writeln(hoten,ngaysinh,quequan,diemtb);
inc(n);
end;
end;
close(f);
writeln('Danh sach nay gom ',n,' sinh vien');
readln;
end.
Program Vi_du_4;
Type
St20 = String[20];
St10 = String[10];
SinhVien = record
Hoten: St20;
Ngaysinh,Quequan: St10;
DiemTb: real;
Xeploai: Char;
end;
Var
f: File of SinhVien;
filename:String;
Sv: sinhvien;
Bhoten:st20;
Bngaysinh,Bquequan:St10;
Begin
assign(f,'sinhvien.dat');
{$I-}
reset(f);
{$I+}
if IOResult <>0 then
begin
writeln('File khong ton tai');
exit;
end;
write('Ho ten sinh vien: ');
readln(bhoten);
write('Ngay sinh: ');
readln(Bngaysinh);
write('Que quan: ');
readln(bquequan);
while not Eof(f) do
begin
read(f,sv);
with sv do
if (hoten=bhoten) and ((ngaysinh=bngaysinh) and (quequan=bquequan)) then
begin
write('Nhap dtb can sua: ');
readln(diemtb);
if diemtb <5 then
xeploai:='D'
else
if diemtb <6.5 then
xeploai:='C'
else
if diemtb <8 then
xeploai:='B'
else
xeploai:='A';
n:=filepos(f);
seek(f,n-1);
write(f,sv);
exit;
end;
end;
Close(f);
readln;
End.
Program Vidu_5;
Var
f: Text;
filename,St: String;
Begin
write(‘Nhap ten file: ‘);
readln(filename);
assign(f,filename);
{$I-}
reaset(f);
{$I+}
if IOResult <> 0 then
begin
writeln(‘File khong ton tai’);
halt;
end;
writeln(‘Noi dung cua file ‘,filename)
while not Eof(f) do
begin
readln(f,st);
writeln(st);
end;
close(f);
readln;
End.
Program Vidu_6;
Var
f: Text;
filename,St: String;
NLines,NStr: word;
i: byte;
Begin
write(‘Nhap ten file: ‘);
readln(filename);
assign(f,filename);
reaset(f);
NBl:=0;
NStr:=0;
while not Eof(f) do
begin
readln(f,st);
inc(NStr);
for i:= 1 to length(St) do
if St[i] = #32 then
inc(NBl);
end;
Close(f);
writeln(‘So dong : ‘,NStr);
writeln(‘So ky tu trang: ‘, NBl)
readln;
End.
Program Vidu_7;
Type
St20 = String[20];
St10 = String[10];
SinhVien = record
Hoten: St20;
Ngaysinh,Quequan: St10;
DiemTb: real;
Xeploai: Char;
end;
Var
f: File of SinhVien;
g:Text;
St:String;
Sv: sinhvien;
Bdiem: String[5];
Begin
assign(f,'sinhvien.dat');
{$I-}
reset(f);
{$I+}
if IOResult <>0 then
begin
writeln('File khong ton tai');
exit;
end;
rewrite(g);
while not Eof(f) do
begin
read(f, Sv);
with Sv do
begin
Str(diemtb,bdiem:5:2);
St:= hoten+#32+ngaysinh+#32+quequan+#32+Bdiem;
writeln(g,St);
end;
end;
Close(f);
Close(g);
readln;
End.
Program Vidu_8;
Var
f,g: Text;
S:array[byte] of real;
m,n,i,j: byte;
Begin
assign(f,’MT.INP’);
reset(f);
readln(f,m,n);
fillchar(S,m,0);
for i:= 1 to m do
begin
for j:=1 to n do
begin
read(f,x);
S[i]:=S[i]+x;
end;
readln(f);
end;
close(f);
assign(g,’KQ.OUT’);
rewrite(g);
writeln(g,m);
for i:= 1 to m do
write(g,S[i]:0:2,#32);
close(g);
End.
Program Vidu_9;
Var
f,g: Text;
A, B, C, D:array[1..100,1..100] of integer;
m,n,p,q,i,j,k,l,r,s: byte;
Begin
assign(f,’MATRIX.INP’);
reset(f);
readln(f,m,n,p,q);
fillchar(D,mxq,0);
for i := 1 to m do
begin
for j:= 1 to n do read(f,A[i,j]);
readln(f);
end;
for j:= 1 to n do
begin
for k:=1 to p do read(f,B[j,k]);
readln(f);
end;
for k:= 1 to p do
begin
for l:=1 to q do read(f,C[k,l]);
readln(f);
end;
close(f);
assign(g,’MATRIX.OUT’);
rewrite(g);
writeln(g,m,#32,q);
for i:= 1 to m do
begin
for l:=1 to q do
begin
for j:= 1 to n do
for k:=1 to p do
D[i,l] := D[i,l] + A[i,j]*B[j,k]*C[k,l];
write(g,D[i,l], #32);
end;
writeln(g);
end;
close(g);
readln;
End.
Program Vi_du_10;
Var
f,g: Text;
S:array[1..100] of real;
T: Set of byte;
GTMax: real;
m,n,i,j: byte;
Begin
assign(f,’DULIEU.INP’);
reset(f);
readln(f,m,n);
fillchar(S,m,0);
for i:= 1 to m do
begin
S:=0;
for j:=1 to n do
begin
read(f,x);
S[i]:=S[i]+x;
end;
readln(f);
end;
close(f);
T:=[1];
GTMax:=S[1];
for i:= 2 to m do
if S[i] > GtMax then
begin
T:=[i];
GtMax:= S[i];
end
else
if S[i] = GTMax then
T:= T+[i];
assign(g,’DULIEU.OUT’);
rewrite(g);
writeln(g,GTMax:0:2);
for i:=1 to 100 do
if i in T then
write(g,i,#32);
readln;
End.
Program Sao_chep_File;
const
bufsize = 200;
var
f,g: file;
File_nguon, file_dich: String;
Buf: array[1..63000] of Byte;
No_read, Temp: integer;
Begin
write(‘Nhap ten file nguon: ‘);
readln(file_nguon);
assign(f,file_nguon);
reset(f);
write(‘Nhap ten file dich: ‘);
readln(file_dich);
assign(g,file_dich);
rewrite(g);
Temp:= filesize(f);
while Temp > 0 do
begin
if bufsize < =Temp then
No_read:= bufsize
else
No_read:= Temp;
BlockRead((f, Buf, No_read);
BlockWrite(g,Buf, No_Read);
Temp:=Temp – No_read;
end;
close(g);
End.