Bài giảng Môn Tin học lớp 10 - Bài 16: Ví dụ làm việc với tệp
Program khoang_cach;
var
d:real;
f,f1: text;
x,y: real;
begin
assign(f,'E:\TRAI.TXT');
reset(f);
assign(f1,'E:\KHCACH.TXT');
rewrite(f1);
While not eof(f) do
begin
-oOo- Ví dụ 1 Ví dụ 2 -oOo- Ví dụ 1: Xem sách giáo khoa trang 87. Program khoang_cach; var d:real; f,f1: text; x,y: real; begin assign(f,'E:\TRAI.TXT'); reset(f); assign(f1,'E:\KHCACH.TXT'); rewrite(f1); While not eof(f) do begin read(f,x,y); d:= sqrt(x*x+y*y); writeln('Khoang cach d =',d:8:2); close(f); readln end. Program khoang_cach; var d:real; f,f1: text; x,y: real; begin assign(f,'E:\TRAI.TXT'); reset(f); assign(f1,'E:\KHCACH.TXT'); rewrite(f1); While not eof(f) do begin read(f,x,y); d:= sqrt(x*x+y*y); writeln('Khoang cach d =',d:8:2); readln; writeln(f1,' khoang cách d = ',d:8:2); writeln(f1); end; close(f); close(f1); readln end. -oOo- Ví dụ 2: Xem sách giáo khoa trang 87. Program dientro; var a: array[1..5] of real; f1,f2:text; r1,r2,r3:real; i:integer; begin assign(f1,'E:\RESIST.DAT'); reset(f1); assign(f2,'E:\RESIST2.EQU'); rewrite(f2); while not eof(f1) do begin read(f1,R1,R2,R3); a[1]:=R1*R2*R3/(R1*R2+R1*R3+R2*R3); a[2]:=R1*R2/(R1+R2)+R3; a[3]:=R1*R3/(R1+R3)+R2; a[4]:=R2*R3/(R2+R3)+R1; a[5]:=R1+R2+R3; for i:= 1 to 5 do write(f2,a[i]:9:2, ' '); writeln(f2); end; close(f1); close(f2); readln end.
File đính kèm:
- VD LAM VIEC VOI TEP.ppt