QuangHoang
.:Administrator:.

| Tuổi: 19 |
|
| Ngày tham gia: 30 1 2008 |
| Số bài: 104 |
|
| Level: |
|
Gửi: 04 Tháng 5, 2008 9:45 pm |
|
 |
 |
Chương trình mình làm theo đề bài tập của cô giáo, các bạn xem rồi nhận xét dùm mình nhé!
| Code: | uses crt;
type
ngay_thang=record
ngay :1..31;
thang :1..12;
nam :integer;
end;
sv=record
hoten :string;
masv :string[10];
ngay_sinh :ngay_thang;
dtb :real;
end;
mang=array[1..10] of sv;
var
A :mang;n:byte;
{--------------------------------------------------------------------- ---------}
procedure nhap; {nhap danh sach n sinh vien}
var ch,i :byte; dk :boolean;
begin
writeln(' NHAP DANH SACH SINH VIEN ');
for i:=1 to n do
with A[i],ngay_sinh do
begin
writeln(' * Nhap du lieu cua sinh vien thu: ',i);
write(' - Ho ten: ');readln(hoten);
write(' - Ma sinh vien: ');readln(masv);
repeat
write(' - Ngay thang nam sinh: ');readln(ngay,thang,nam);{kiem tra viec nhap ngay thang nam}
ch:=0; dk:=true;
if ((nam mod 400=0) and (nam>0)) or ((nam mod 4=0) and (nam mod 10<>0)) then ch:=1;
if (thang<1) or (thang>12) or ((ngay>31) and ((thang=1) or (thang=3) or (thang=5) or (thang=7)
or (thang=8) or (thang=10) or (thang=12))) or ((ngay>30) and ((thang=4) or (thang=6) or (thang=9)
or (thang=11)) or ((ngay>28) and (thang=2) and (ch=0))) or ((ngay>29) and (thang=2) and (ch=1))
then dk:=false;
until dk=true;
repeat
write(' - Diem trung binh: ');readln(dtb);
if (dtb>=0) and (dtb<=10) then break;
until false;
writeln;
end;
end;
{------------------------------------------------------------------}
procedure chuan_hoa(var st:string); {chuan hoa ho ten cua cac sinh vien}
var i:byte;
begin
while st[1] =' ' do delete(st,1,1); {xoa cach trong: dau > }
while st[length(st)]=' ' do delete(st,length(st),1); { < cuoi xau}
for i:=1 to length(st) do {xoa dau cach trong trong xau}
if (st[i]=#32) and (st[i+1]=#32) then
begin delete(st,i,1);i:=i-1; end;
for i:=1 to length(st) do st[i]:=upcase(st[i]);
for i:=1 to length(st) do
if (st[i]<>' ') then st[i]:=chr(ord(st[i]) + 32); {chuyen het thanh chu thuong}
st[1]:=upcase(st[1]);
for i:=1 to length(st) do
if st[i]=#32 then st[i+1]:=upcase(st[i+1]); {viet hoa dau chu}
end;
{------------------------------------------------------------------}
procedure chuan_hoa_sv;
var j :byte;
begin
for j:=1 to n do
chuan_hoa(A[j].hoten);
end;
{-----------------------------------------------------------------}
procedure sap_xep;
var i,j :byte; tam:sv;
begin
for i:=1 to n-1 do
for j:=i+1 to n do
if A[i].ngay_sinh.nam<A[j].ngay_sinh.nam then
begin
tam:=A[i];
A[i]:=A[j];
A[j]:=tam;
end;
end;
{----------------------------------------------------------------}
procedure xuat; {in ra man hinh sinh vien sinh thang 1}
var i: byte;
begin
clrscr;
writeln(' DANH SACH SINH VIEN');
for i:=1 to n do
with A[i],ngay_sinh do
if thang=1 then
begin
writeln(' * Thong tin ve sinh vien thu: ',i);
writeln(' - Ho ten: ',hoten);
writeln(' - Ma sinh vien: ',masv);
writeln(' - Ngay sinh: ',ngay,'/',thang,'/',nam);
writeln(' - Diem trung binh: ',dtb:5:2);
writeln;
end;
end;
{----------------------------------------------------------------}
begin
clrscr;
write(' Ban muon nhap vao danh sach bao nhieu sinh vien: ');readln(n);
clrscr;
nhap;
chuan_hoa_sv;
sap_xep;
xuat;
readln
end. |
|
|