Cho 1 tệp có tên là mang.txt viết chương trình đọc dữ liệu từ tệp sau đó tính tổng các giá trị đọc được ghi vào tệp tong.txt
Viết chương trình đọc dữ liệu từ tệp fi với tệp fi chứa dữ liệu là 1 xâu dữ liệu. Ghi kết quả vào tệp fo các kết quả sau khi xử lý xâu.
a. Xâu vừa đọc được từ tệp fi, xâu chuyển thành chữ in hoa
b. Xâu s1 được tạo gồm n kí tự liên tiếp của xâu s bắt đầu tại vt.
c. Xâu sau khi xóa a kí tự của xâu s bắt đầu tại vị trí vt
Cho tệp văn bản có tên DATA2.TXT chứa một xâu bất kì không quá 255 kí tự gồm các chữ và số. Viết chương trình đọc xâu kí tự S từ từ tệp DATA2.TXT sau đó ghi dữ liệu là các thông tin sau vào tệp KQ2.TXT:
- Dòng 1: Số lần xuất hiện của kí tự "k" trong xâu?
- Dòng 2: Số lượng kí tự là số xuất hiện trong S (giữ nguyên thứ tự xuất hiện)?
Cho tệp văn bản có tên DATA2.TXT chứa một xâu bất kì không quá 255 kí tự gồm các chữ và số. Viết chương trình đọc xâu kí tự S từ từ tệp DATA2.TXT sau đó ghi dữ liệu là các thông tin sau vào tệp KQ2.TXT:
- Dòng 1: Số lần xuất hiện của kí tự "k" trong xâu?
- Dòng 2: Số lượng kí tự là số xuất hiện trong S (giữ nguyên thứ tự xuất hiện)?
Cho tệp văn bản có tên DATA2.TXT chứa một xâu bất kì không quá 255 kí tự gồm các chữ và số. Viết chương trình đọc xâu kí tự S từ từ tệp DATA2.TXT sau đó ghi dữ liệu là các thông tin sau vào tệp KQ2.TXT:
- Dòng 1: Số lần xuất hiện của kí tự "k" trong xâu?
- Dòng 2: Số lượng kí tự là số xuất hiện trong S (giữ nguyên thứ tự xuất hiện)?
Help me!!! Mai mk thi ạ
Cho tệp văn bản có tên DATA2.TXT chứa một xâu bất kì không quá 255 kí tự gồm các chữ và số. Viết chương trình đọc xâu kí tự S từ từ tệp DATA2.TXT sau đó ghi dữ liệu là các thông tin sau vào tệp KQ2.TXT:
- Dòng 1: Số lần xuất hiện của kí tự "k" trong xâu?
- Dòng 2: Số lượng kí tự là số xuất hiện trong S (giữ nguyên thứ tự xuất hiện)?
Ai giúp em với ạ.
Câu 1: cho tệp mang .txt có nội dung là 4 số nguyên như sau: 1 3 2 1. Hãy viết chương trình đọc dữ liệu từ tệp này. Tính tổng các giá trị đọc được. Ghi giá trị đọc được từ tệp mang.txt và tổng này vào tệp tong.txt
Câu 2: Viết chương trình thực hiện các công việc sau:
- đọc ba số a,b,c từ tệp ptb2.txt
- giải phương trình bậc 2 với hệ số a b c vừa đọc được
- ghi kết quả giải phương trình bậc 2 vào tệp ketqua.txt
Câu 5: Cho file dulieu.dat gồm hai dòng, mỗi dòng chứa hai số nguyên. ghi lên file tb.dat từ giá trị trung bình cộng của các số trên file dulieu.dat
Câu 1:
Program hotrotinhoc_hoc24;
const fi='mang.txt';
fo='tong.txt';
var f: text;
a,b,c,d: integer;
procedure ip;
begin
assign(f,fi);
reset(f);
read(f,a,b,c,d);
close(f);
end;
procedure out;
begin
assign(f,fo);
rewrite(f);
write(f,a+b+c+d);
close(f);
end;
begin
ip;
out;
end.
Câu 1:
const fi='mang.txt';
fo='tong.txt';
var f1,f2:text;
dem,i,t:integer;
a:array[1..4]of integer;
begin
assign(f1,fi); reset(f1);
assign(f2,fo); rewrite(f2);
dem:=0;
while not eoln(f1) do
begin
inc(dem);
read(f1,a[dem]);
end;
t:=0;
for i:=1 to dem do
t:=t+a[i];
writeln(f2,t);
close(f1);
close(f2);
end.
Câu 2:
const fi='ptb2.txt';
fo='ketqua.txt';
var f1,f2:text;
a,b,c,delta,x1,x2:real;
begin
assign(f1,fi); reset(f1);
assign(f2,fo); rewrite(f2);
readln(f1,a,b,c);
delta:=sqr(b)-4*a*c;
if delta>0 then
begin
x1:=(-b-sqrt(delta))/2*a;
writeln(f2,'x1=',x1:4:2);
x2:=(-b+sqrt(delta))/2*a;
writeln(f2,'x2=',x2:4:2);
end
else if delta=0 then writeln(f2,'x1=x2=',-b/(2*a):4:2)
else writeln(f2,'phuong trinh vo nghiem');
close(f1);
close(f2);
end.
Câu 5:
const fi='dulieu.dat';
fo='tb.dat';
var f1,f2:text;
a:array[1..4]of integer;
dem,i:integer;
tb:real;
begin
assign(f1,fi); reset(f1);
assign(f2,fo); rewrite(f2);
dem:=0;
while not eof(f1) do
begin
inc(dem);
read(f1,a[dem]);
end;
tb:=0;
for i:=1 to dem do
tb:=tb+a[i];
writeln(f2,tb/dem:4:2);
close(f1);
close(f2);
end.
Câu 2:
Program hotrotinhoc_hoc24;
const fi='ptb2.txt';
fo='ketqua.txt';
var f: text ;
a,b,c,denta: real;
procedure ip;
begin
assign(f,fi);
reset(f);
read(f,a,b,c);
close(f);
end;
procedure out;
begin
assign(f,fo);
rewrite(f);
denta:=sqr(b)-4*(a)*(c);
if denta<0 then write(f,'Phuong trinh vo nghiem');
if denta=0 then write(f,'Phuong trinh co nghiem kep ,gia tri x=',-(b/2*a));
if denta>0 then write(f,'Phuong trinh co hai nghiem phan biet,gia tri x1=',(-(b)+sqr(denta))/(2*a):1:2,' gia tri x2=',(-(b)-sqr(denta))/(2*a):1:2);
close(f);
end;
begin
ip;
out;
end.
Viết chương trình đọc dữ liệu từ tệp input.pas (tệp có chứa 2 số nguyên cách nhau bởi dấu cách) và ghi vào tệp output.pas tích của hai số nguyên vừa đọc từ tệp input.pas
Program HOC24;
var f1,f2: text;
a,b: integer;
t: longint;
begin
assign(f1,'input.pas');
reset(f1);
assign(f2,'output.pas');
rewrite(f2);
readln(f1,a,b);
t:=a*b;
write(f2,t);
close(f1);
close(f2);
End.
Viết chương trình đọc từ tệp Dữ liệu.int chứa 2 số nguyên bất kì . Tính và ghi kết quả vào tệp Kết quả.out 2 dòng , dòng đầu ghi giá trị tổng 2 số , dòng thứ 2 ghi giá trị trung bình của 2 số đó
#include <bits/stdc++.h>
using namespace std;
long long a,b;
double tb;
int main()
{
freopen("dulieu.inp","r",stdin);
freopen("ketqua.out","w",stdout);
cin>>a>>b;
cout<<a<<" "<<b;
cout<<fixed<<setprecision(2)<<(a*1.0+b*1.0)/(2*1.0);
return 0;
}
cho tệp văn bản XAU.INP lưu trũ họ tên của các học sinh trong lớp. Mỗi học sinh được lưu trữ trên một dòng. Viết chương trình đọc dữ liệu từ tệp XAU.INP, kết quả ghi vào XAU.OUT là độ dài tên từng học sinh trong lớp
with open('XAU.INP', 'r') as input_file, open('XAU.OUT', 'w') as output_file:
for line in input_file:
length = len(line.strip())
output_file.write(f'{length}\n')