View Single Post
Old 04-02-2009, 07:55 AM   #5
Hồ sơ
johnceduy
Senior Member
 
johnceduy's Avatar
 
Tham gia ngày: Dec 2008
Cư ngụ: Lê Quý Đôn
Số bài viết: 115
Tiền: 25
Thanks: 54
Thanked 83 Times in 18 Posts
johnceduy is on a distinguished road
Tim Ðề: Cứu bài tập pascal này với

Dạ vâng! Em cũng đã hỏi cô về trường hợp đó. Tuy nhiên do đây là đề để cô bồi dưỡng nên phải làm theo đề cô cho. Sau đây là toàn bộ code bài tập của em. Đáp án ra đúng, nhưng còn lộn xộn chỗ nhập dữ liệu, đồng thời em vẫn chưa nghĩ ra cách trình bày để xuất ra màn hình, mong các mod đóng góp cho em!
Program Tuyensinhlop10;
Uses crt;
Type hocsinh=record
hoten:string[20];
tong,Toan,Li,Hoa:real;
kp:string;
end;
var A:array[1..15]of hocsinh;
dem,j,i:byte;
tam:string; tam2,tam3,tam4,tam1:real;
f:text;
Begin
Clrscr;
assign(f,'D:\DuyGames\hocsinh.txt');
reset(f);
a[i].tong:=0;
i:=1;
dem:=0;
Write('Nhap vao a[',i,']:');readln(a[i].hoten);
Write('Toan:');Readln(a[i].Toan);
Write('Li :');Readln(a[i].Li);
Write('Hoa :');Readln(a[i].Hoa);
a[i].tong:=a[i].tong+a[i].toan+a[i].li+a[i].hoa;
While a[i].hoten<>'' do begin
dem:=dem+1;
i:=i+1;
Write('Nhap vao a[',i,']:'); readln(a[i].hoten);
Write('Toan:');Readln(a[i].Toan);
Write('Li :');Readln(a[i].Li);
Write('Hoa :');Readln(a[i].Hoa);
a[i].tong:=a[i].tong+a[i].toan+a[i].li+a[i].hoa;
end;
{ while ((a[i].tong>20) and not (a[i].toan<=2) and (a[i].li<=2) and (a[i].hoa<=2)) do a[i].kp:='Dau';}
For i:=1 to dem do a[i].hoten[1]:=UpCase(a[i].hoten[1]);
For i:=1 to dem-1 do
For j:=i+1 to dem do
If a[i].hoten>a[j].hoten then
begin
tam:=a[i].hoten;
a[i].hoten:=a[j].hoten;
a[j].hoten:=tam;
tam1:=a[i].tong;
a[i].tong:=a[j].tong;
a[j].tong:=tam1;
tam2:=a[i].toan;
a[i].toan:=a[j].toan;
a[j].toan:=tam2;
tam3:=a[i].Li;
a[i].Li:=a[j].Li;
a[j].Li:=tam3;
tam4:=a[i].hoa;
a[i].hoa:=a[j].hoa;
a[j].hoa:=tam4;
end;
For i:=1 to dem do
Writeln(a[i].hoten:5,a[i].toan:11:2,a[i].li:15:2,a[i].hoa:17:2,a[i].tong:19:2);
Writeln('Danh sach nguoi dau la:');
For i:=1 to dem+1 do begin
If ((a[i].tong>20) and not((a[i].toan<=2) or (a[i].li<=2) or (a[i].hoa<=2))) then
Writeln(a[i].hoten); end;
close(f);
readln;
end.
Trong chương trình trên biến "dem" có thể xem là "n" tức là số lượng học sinh có trong danh sách sau khi nhập.
__________________
Nhớ, nhớ, nhớ quá đi!

johnceduy is offline   Trả Lời Với Trích Dẫn
Đã có thành viên gửi lời cám ơn đến johnceduy vì bạn đã đăng bài:
Stevvinhith (14-09-2015)