//
you're reading...
Chủ đề bản ghi (Record), Dùng cho cấp THCS, Dùng cho cấp THPT

Bài 12: Kiểu dữ liệu bản ghi (record)

Bài tập

Bài tập

 Program KT_ngay;
CONST
 Ngay = [1..31];
 Thang = [1..12];
 Th31ngay: Set of byte = [1,3,5,7,8,10,12];

 BaoLoi : Array[1..3] Of String[30] =('-Ban nhap sai ngay, thang',
 '-Thang nay khong co ngay 31','-thang 2 khong co ngay nay');

TYPE
 NgayThang = RECORD
 Ng, Th : Byte;
 Nam : Word;
 End;

VAR
 Nhatky : NgayThang;
 Loi : Array[1..3] Of Boolean;
 i : Byte;
 Nhuan : Boolean;
BEGIN
 With Nhatky Do
 Begin
 Write('-Nhap ngay = ');
 Readln(Ng);
 Write('-Nhap thang= ');
 Readln(Th);
 Write('-Nhap nam = ');
 Readln(Nam);
 Loi[1] := (NOT(Ng In Ngay)) OR (NOT (Th In Thang));
 Loi[2] := (Ng = 31) AND (NOT (Th In Th31Ngay));
 Nhuan := ((Nam Mod 4) = 0) AND ((Nam Mod 100) <> 0)
 OR ((Nam Mod 400) = 0);
 Loi[3] := ((Ng > 29) AND (Th = 2)) OR ((Ng = 29)
 AND (th = 2) AND (NOT Nhuan));
 End;
 For i := 1 To 3 Do
 If Loi[i] Then
 Writeln(BaoLoi[i]);
 Readln
END.

.

Bài tập

 Program Van_Toan_Ly;
CONST
 Max = 50;
 Td1='|------------------------|-----|-----|------|';
 Td2=#124 +' HO VA TEN ' + #124 + ' VAN ' + #124+
 'TOAN ' + #124 + ' LY |';

TYPE
 HocSinh = RECORD
 HoTen : String[24];
 Van,Toan,Ly : Real;
 End;

VAR
 Hs : Array[1..Max] Of HocSinh;
 i,n : 1..Max;
BEGIN
 Writeln('NHAP XUAT DU LIEU KIEU BAN GHI');
 Writeln('------------------------------');
 Writeln;
 Write('-Lop co bao nhieu hoc sinh: ');
 Readln(n);
 For i := 1 To N Do {Nhap du lieu}
 With Hs[i] Do
 Begin
 Write('-Ho ten hoc sinh thu: ',i:2,' = ');
 Readln(HoTen);
 Write('-Diem Van : ');
 Readln(Van);
 Write('-Diem Toan: ');
 Readln(Toan);
 Write('-Diem Ly : ');
 Readln(Ly);
 End;
 Writeln;
 Writeln(' BANG DIEM');
 Writeln;
 Writeln(Td1);
 Writeln(Td2);
 Writeln(Td1);
 For i := 1 To N Do {Xuat du lieu }
 With Hs[i] Do
 Writeln(#124,HoTen,#32:24 - Length(HoTen),
 #124,Van :5:1,
 #124,Toan :5:1,
 #124,Ly :5:1,' |');
 Writeln(Td1);
 Readln
END.

.

Bài tập

 Program Sap_Xep_Tuoi_Giam;
CONST
    Max = 50;
   Td1 = '|========================|============|';
   Td2 = #124+'      HO VA TEN         '+#124 + '  NAM SINH  |';
   Td3 = '|------------------------|------------|';

TYPE
    HoSo = RECORD
       HoTen : String[24];
      Ngay  : 1..31;
      Thang : 1..12;
      Nam   : 1900..2000;
   End;
VAR
   Nhanvien :Array[1..Max] Of HoSo;
   i,n  : 1..Max;
   Tam  : HoSo;
   Kthuc: Boolean;

BEGIN
    Writeln('SAP XEP BAN GHI THEO GIAI THUAT NOI BOT');
   Writeln('---------------------------------------');
   Writeln;
   Write('-Co bao nhieu nguoi: ');
   Readln(n);
   For i := 1 to N Do   { Nhap du lieu }
       With Nhanvien[i] Do
          Begin
             Write('-Ho va ten nguoi thu: ',i:2,' = ');
            Readln(HoTen);
            Write('-Ngay sinh: ');
            Readln(Ngay);
            Write('-Thang    : ');
            Readln(Thang);
            Write('-Nam      : ');
            Readln(Nam);
         End;
   Repeat          { Sap xep ban ghi}
       KThuc := True;
      For i := 1 To N - 1 Do
          If (Nhanvien[i].Nam > Nhanvien[i+1].Nam)
                OR ((Nhanvien[i].Nam = Nhanvien[i+1].Nam) AND
                     (Nhanvien[i].Thang > Nhanvien[i+1].Thang))
                OR ((Nhanvien[i].Nam = Nhanvien[i+1].Nam) AND
                     (Nhanvien[i].Thang = Nhanvien[i+1].Thang) AND
                (Nhanvien[i].Ngay > Nhanvien[i+1].Ngay)) Then
            Begin
                Tam:=Nhanvien[i];
               Nhanvien[i] := Nhanvien[i+1];
               Nhanvien[i+1] := Tam;
               KThuc :=False;
            End;
   Until KThuc;
   Writeln;
   Writeln('          SAP XEP THEO TUOI');
   Writeln;
   Writeln(Td1);
   Writeln(Td2);
   Writeln(Td3);
   For i := 1 to N Do
       With Nhanvien[i] Do
          Writeln(#124, HoTen, #32 :24 - Length(HoTen),
                 #124,Ngay,' / ',Thang,' / ',nam, #124);
   Writeln(Td1);
   Readln
END.

.

Bài tập

 Program Trac_Nghiem;
TYPE
    Tracnghiem = RECORD
       CauHoi     : String;
      A,B,C,D : String;
      DapAn   : Char;
   End;

VAR
    a:Array[1..5] Of Tracnghiem;
   i,dung : Integer;
   Traloi : Char;

BEGIN
    Writeln('CAU HOI TRAC NGHIEM');
   Writeln('-------------------');
   Writeln;
   Writeln('-Nhap 5 cau hoi,y nghia va dap an');
   For i := 1 To 5 Do
       With a[i] Do
          Begin
             Write('-Cau hoi thu: ',i:2,' : ');
            Readln(CauHoi);
            Write('    +Nghia    A: ');
            Readln(A);
            Write('    +Nghia    B: ');
            Readln(B);
            Write('    +Nghia    C: ');
            Readln(C);
            Write('    +Nghia    D: ');
            Readln(D);
            Write('-Dap an: ');
            Readln(DapAn);
            DapAn := UpCase(DapAn);
         End;

   Dung := 0;
   Writeln('-Ban chon nghia cho tung cau hoi');
   For i := 1 To 5 Do
       Begin
          Writeln(i,'. ',a[i].CauHoi);
         Writeln(' A)',a[i].A);
         Writeln(' B)',a[i].B);
         Writeln(' C)',a[i].C);
         Writeln(' D)',a[i].D);
         Write('-Lua cau nao go vao nghia cua cau do: ');
         Readln(TraLoi);
         If UpCase(TraLoi) = a[i].DapAn Then
             Dung := Dung + 1;
      End;
   Writeln;
   Writeln('-So cau tra loi dung: ',Dung);
   Readln
END.

.

Bài tập

Program Tu_dien;
TYPE
 Tudien = RECORD
 Anh,Viet : String;
 End;

VAR
 a: Array[1..5] Of TuDien;
 St : String;
 i : Integer;
 TimDuoc : Boolean;

BEGIN
 For i := 1 To 5 Do
 Begin
 Writeln('-Tu thu: ',i);
 Write(' +Nghia tieng Anh : ');
 Readln(a[i].Anh);
 Write(' +Nghia tieng Viet : ');
 Readln(a[i].Viet);
 End;
 Writeln;
 Write('*Tu tieng Anh can tim: ');
 Readln(St);
 TimDuoc :=False;
 i := 1;
 While (NOT TimDuoc) AND (i <= 5) Do
 Begin
 If St = a[i].Anh Then
 Begin
 Write('*Nghia tieng Viet : ',a[i].Viet);
 TimDuoc := True;
 End;
 i := i + 1;
 End;
 If NOT TimDuoc then
 Writeln('Tu nay khong co trong tu dien');
 Readln
END.

.

Bài tập

 Program TT_Doi_Bong;
 CONST
 Max = 23;
 TYPE
 ThanhTich=RECORD
 HoTen:String[24];
 Tuoi,BanThang:Integer;
 END;
 DoiBong = Array[1..Max] Of ThanhTich;
 VAR
 i,n,TuoiCao,TuoiThap,nam:Integer;
 Ten1,Ten2,TenDoi:String[20];
 CauThu:DoiBong;
 ThangNhieu,ThangIt:Integer;
 Tb:Real;
BEGIN
 Writeln('THANH TICH CUA DOI BONG DA');
 Writeln('--------------------------');
 Write('-Thanh tich nam nao: ');
 Readln(Nam);
 Write('-Ten doi bong: ');
 Readln(TenDoi);
 Write('-So cau thu: ');
 Readln(n);
 For i:=1 To n Do
 With Cauthu[i] Do
 Begin
 Write('-Ho va ten cau thu thu: ',i:2,' la: ');
 Readln(HoTen);
 Write('-Tuoi cua cau thu thu: ',i:2,' la: ');
 Readln(Tuoi);
 Write('-So ban thang cua cau thu thu: ',i:2,' la: ');
 Readln(BanThang);
 End;
 TuoiCao:=CauThu[1].Tuoi;
 Tuoithap:=CauThu[1].Tuoi;
 ThangNhieu:=Cauthu[1].Banthang;
 ThangIt:=CauThu[1].BanThang;
 Ten1:=CauThu[1].HoTen;
 Ten2:=CauThu[1].HoTen;
 Tb:=CauThu[1].BanThang;
 For i:=2 To n Do
 Begin
 If CauThu[i].Tuoi > TuoiCao Then
 TuoiCao:=CauThu[i].Tuoi
 Else
 If CauThu[i].Tuoi < TuoiThap Then
 Tuoithap :=CauThu[i].Tuoi;
 If CauThu[i].BanThang > ThangNhieu Then
 Begin
 ThangNhieu:=Cauthu[i].BanThang;
 Ten1:=CauThu[i].HoTen;
 End
 Else
 If CauThu[i].BanThang < ThangIt Then
 Begin
 ThangIt:= CauThu[i].BanThang;
 Ten2:=CauThu[i].HoTen;
 End;
 Tb:=Tb+CauThu[i].BanThang;
 End;
 Writeln;
 Writeln('THANH TICH NAM: ',nam);
 Writeln('Cua doi bong: ',TenDoi);
 Writeln('-----------------------');
 Writeln;
 Writeln('-Cau thu: ',Ten1,' co tuoi lon nhat: ',TuoiCao);
 Writeln('-Cau thu: ',Ten2,' co tuoi nho nhat: ',TuoiThap);
 Writeln;
 Writeln('-Cau thu: ',Ten1,' Co ban thang nhieu nhat: ',ThangNhieu);
 Writeln('-Cau thu: ',Ten2,' Co ban thang it nhat: ',ThangIt);
 Writeln;
 Writeln('-So ban thang trung binh cua toan doi: ',Round(Tb/n));
 Readln
END.

.

Bài tập

 Program So_Huu_Ty;
TYPE
 HuuTy = RECORD
 TuSo, MauSo : Integer;
 End;

VAR
 So1, So2, Kq : HuuTy;
 St1, St2 : String;
 i,Result, n, m : Integer;
 Ch : Char;

BEGIN
 Writeln('NHAP, XUAT SO HUU TY');
 Writeln('--------------------');
 Writeln;
 Write('-So thu nhat: ');
 Readln(St1);
 Write('-So thu hai : ');
 Readln(St2);
 i := Pos('/', St1);
 With so1 Do
 If i = 0 Then
 Begin
 Val(St1, TuSo, Result);
 MauSo := 1;
 End
 Else
 Begin
 Val(Copy(St1, 1, i-1), TuSo, Result);
 Val(Copy(St1, i+1, Length(St1)-i), MauSo, Result);
 End;
 i := Pos('/', St2);
 With So2 Do
 If i = 0 Then
 Begin
 Val(St2, TuSo, Result);
 MauSo := 1;
 End
 Else
 Begin
 Val(Copy(St2, 1, i-1), TuSo, Result);
 Val(Copy(St2, i+1, Length(St2)-i), MauSo, Result);
 End;
 Write('Chon phep tinh (+, -, *, /): ');
 Readln(Ch);
 Case Ch Of
 '+' : Begin
 Kq.TuSo := So1.TuSo*So2.MauSo + So1.MauSo * So2.TuSo;
 Kq.MauSo := So1.MauSo * So2.MauSo;
 End;
 '-' : Begin
 Kq.TuSo := So1.TuSo*So2.MauSo - So1.MauSo * So2.TuSo;
 Kq.MauSo := So1.MauSo * So2.MauSo;
 End;
 '*' : Begin
 Kq.TuSo := So1.TuSo*So2.TuSo;
 Kq.MauSo := So1.MauSo * So2.MauSo;
 End;
 '/' : Begin
 Kq.TuSo := So1.TuSo*So2.MauSo;
 Kq.MauSo := So1.MauSo * So2.TuSo;
 End;
 End;
 If Kq.TuSo = 0 Then
 Write('Ket qua : 0')
 Else
 With Kq Do
 Begin
 n := ABS(TuSo);
 m := ABS(MauSo);
 While n <> m Do
 If n > m Then
 n := n-m
 Else
 m := m-n;
 TuSo :=TuSo Div n;
 MauSo := MauSo Div n;
 If MauSo = 1 Then
 Write('Ket qua : ',TuSo)
 Else
 Write('Ket qua : ',TuSo,'/',MauSo);
 End;
 Readln
END.

.

Bài tập

 Program Sap_Xep_Theo_Ten;
TYPE
 HoSo = RECORD
 HoLot : String[17];
 Ten : String[7];
 Diem : Real;
 End;

VAR
 a : Array[1..50] Of HoSo;
 Tam : HoSo;
 i,j,PhanTu : Integer;

BEGIN
 PhanTu := 0;
 With Tam Do
 Repeat
 Write('-Nhap ho lot ( 0 de ket thu): ');
 Readln(HoLot);
 If HoLot <> '0' Then
 Begin
 Write('-Nhap ten : ');
 Readln(Ten);
 Write('-Nhap diem : ');
 Readln(Diem);
 PhanTu := PhanTu + 1;
 a[PhanTu] := Tam;
 End;
 Until HoLot = '0';

 For i := 1 To PhanTu - 1 Do
 For j := PhanTu DownTo i+1 Do
 If a[j].Ten[1] < a[j-1].Ten[1] Then
 Begin
 Tam := a[j];
 a[j] := a[j-1];
 a[j-1] := Tam;
 End;
 Writeln;
 Writeln('------------------------------------');
 Writeln('| HO VA TEN | DIEM |');
 Writeln('|--------------------------|-------|');
 For i := 1 To PhanTu Do
 With a[i] Do
 Writeln('|',HoLot:17,' ',Ten:7,' |',Diem:5:1,' |');
 Writeln('------------------------------------');
 Readln
END.

.

Bài tập

 Program Hoa_Don;
CONST
    Max = 100;
TYPE
    HoaDon = RECORD
       NguoiMua : String[24];
      TenHang  : String[10];
      DonGia   : Real;
      SoLuong  : Integer;
   End;

VAR
    a   : Array[1..Max] Of HoaDon;
   DsTenHang : Array[1..Max] Of String[10];
   Tam       : HoaDon;
   Spt, SoTenHang, i, j : Integer;
   Tong                 : Real;
   KiemTra              : Boolean;

BEGIN
    Writeln('HOA DON BAN HANG');
   Writeln('----------------');
   Writeln;
   Spt := 0;
   With Tam do
       Repeat
          Write('-Ten nguoi mua (go 0 de thoat): ');
         Readln(NguoiMua);
         If NguoiMua <> '0' Then
             Begin
                Write('-Ten hang: ');
               Readln(TenHang);
               Write('-Don gia : ');
               Readln(DonGia);
               Write('-So luong: ');
               Readln(SoLuong);
               Spt := Spt + 1;
               a[Spt] := Tam;
            End;
      Until NguoiMua = '0';
   SoTenHang := 0;
   For i := 1 To Spt Do
       Begin
          KiemTra :=False;
         For j := 1 To SoTenHang Do
             If DsTenHang[j] = a[i].TenHang Then
                KiemTra := True;
            If NOT KiemTra Then
                Begin
                   SoTenHang :=SoTenHang + 1;
                  DsTenHang[SoTenHang] := a[i].TenHang;
               End;
      End;
   Writeln;
   For i := 1 To SoTenHang Do
       Begin
          Tong := 0;
         For j := 1 To Spt Do
             With a[j] Do
                If TenHang = DsTenHang[i] Then
                   Tong := Tong + (DonGia * Soluong);
               Writeln('  +Tong so tien mua: ',DsTenHang[i]:10,' = ',tong:10:2);
      End;
   Readln
END.

.

Bài tập

 Program The_Tich_Long_Go;
TYPE
 CachDo = (DuongKinh, ChuVi);
 LongGo = RECORD
 Cdai : Real;
 Dscdai : Real;
 Case Cdo : CachDo Of
 DuongKinh : (Dk,Dsdk : Real);
 ChuVi : (Cvi, Dscvi : Real);
 End;

VAR
 MaDo :Char;
 Go : LongGo;
 Ttich : Real;
 {------------------------}
 Function TheTich(A: LongGo): Real;
 Begin
 With A Do
 Case Cdo Of
 DuongKinh : TheTich := Pi*Sqr(Dk-Dsdk)*(Cdai-Dscdai)/40000;
 ChuVi : TheTich := Sqr(Cvi-Dscvi)*(Cdai-Dscdai)/(Pi*40000);
 End;
 End;

BEGIN
 Writeln('TINH THE TICH LONG GO');
 Writeln('---------------------');
 Writeln;
 Repeat
 Writeln('*Chon phuong phap do ?');
 Write('+Duong kinh (go K), +Chu vi (go V): ');
 Readln(Mado);
 Until Pos(Mado,'kKvV') <> 0;
 With Go Do
 Begin
 Write('-Chieu dai (m) = ');
 Readln(Cdai);
 Write('-Dung sai (m) = ');
 Readln(Dscdai);
 Case Mado Of
 'k','K' : Begin
 Cdo := DuongKinh;
 Write('+Duong kinh (Cm): ');
 Readln(Dk);
 Write('+Dung sai (Cm) : ');
 Readln(Dsdk);
 End;
 'v','V' : Begin
 Cdo := Chuvi;
 Write('+Chu vi (Cm) : ');
 Readln(Cvi);
 Write('+Dung sai (Cm) : ');
 Readln(Dscvi);
 End;
 End;
 End;
 Ttich :=TheTich(Go);
 Writeln;
 Writeln('*The tich long go la: ',Ttich:10:4,' m3');
 Writeln;
 Writeln('Bam phim <Enter> de ket thuc');
 Readln
END.

.

Bài tập

 Program Gia_Canh;
CONST
 Max = 100;
 Td1 ='|========================|========================|======|';
 Td2 =#124 +' HO VA TEN '+
 #124 +' HO TEN VO CHONG '+
 #124 +'SO CON'+#124;
 Td3 ='|------------------------|------------------------|------|';
TYPE
 GiaCanh = RECORD
 HoTen :String[24];
 Case GiaDinh : Boolean Of
 True : (VoChong : String[24];
 SoCon : Byte);
 End;

VAR
 Hsgc :Array[1..Max] Of GiaCanh;
 n, i : 1..Max;
 Ch : Char;
BEGIN
 Writeln('HO SO GIA CANH');
 Writeln('--------------');
 Writeln;
 Write('-So luong nhan vien: ');
 Readln(n);
 For i := 1 To N Do {Nhap du lieu}
 With Hsgc[i] Do
 Begin
 Write('+Ho va ten nhan vien thu: ',i:2,' la= ');
 Readln(HoTen);
 Write('+Co gia dinh chua (C/K) ');
 Readln(Ch);
 Ch := UpCase(Ch);
 If Ch = 'C' Then
 Begin
 GiaDinh := True;
 Write(' +Ho ten vo/chong: ');
 Readln(VoChong);
 Write(' +So con : ');
 Readln(SoCon);
 End
 Else
 GiaDinh := False;
 End;
 Writeln;
 Writeln(#32:25,'HOAN CANH GIA DINH NHAN VIEN');
 Writeln(#32:12,Td1);
 Writeln(#32:12,Td2);
 Writeln(#32:12,Td3);
 For i := 1 To N Do {Xuat du lieu }
 With Hsgc[i] Do
 Begin
 Write(#32:12);
 Write(#124,HoTen,#32:24-Length(HoTen));
 If GiaDinh Then
 Begin
 Write(#124,VoChong,#32:24-Length(VoChong));
 Writeln(#124,SoCon:6,#124);
 End
 Else
 Begin
 Write(#124,#32:24);
 Writeln(#124,#32:6,#124);
 End;
 End;
 Writeln(#32:12,Td1);
 Readln
END.

.

Bài tập

Program Ho_So;
CONST
 Max = 100;
TYPE
 Str = String[24];
 HoSo = RECORD
 HoTen : Str;
 Tuoi : Integer;
 Luong : Real;
 End;
 CongTy = Array[1..Max] Of HoSo;
VAR
 Hoten1, Hoten2 : Str;
 i,n,TuoiMax,TuoiMin : Integer;
 LuongMax, LuongMin,LuongTb : Real;
 Nv : CongTy;
Begin
 Writeln('HO SO NHAN VIEN');
 Writeln('---------------');
 Writeln;
 Write('-Co bao nhieu nguoi: ');
 Readln(n);
 For i := 1 To N Do
 With Nv[i] Do
 Begin
 Write('-Ho ten nhan vien thu: ',i:2,' la= ');
 Readln(HoTen);
 Write('-Tuoi = ');
 Readln(Tuoi);
 Write('-Bac luong = ');
 Readln(Luong);
 End;
 TuoiMax := Nv[1].Tuoi;
 TuoiMin := Nv[1].Tuoi;
 LuongMax := Nv[1].Luong;
 LuongMin := Nv[1].Luong;
 HoTen1 := Nv[1].HoTen;
 HoTen2 := Nv[1].HoTen;
 LuongTb := Nv[1].Luong;
 For i := 2 To N Do
 Begin
 If Nv[i].Tuoi > TuoiMax Then
 TuoiMax := Nv[i].Tuoi
 Else
 If Nv[i].Tuoi < TuoiMin Then
 TuoiMin := Nv[i].Tuoi;
 If Nv[i].Luong > LuongMax Then
 Begin
 LuongMax := Nv[i].Luong;
 HoTen1 := Nv[i].HoTen;
 End
 Else
 If Nv[i].Luong < LuongMin Then
 Begin
 LuongMin := Nv[i].Luong;
 HoTen2 := Nv[i].HoTen;
 End;
 LuongTb := LuongTb + Nv[i].Luong;
 End;
 Writeln;
 Writeln('+Nhan vien co tuoi lon nhat la: ',TuoiMax);
 Writeln('+Nhan vien co tuoi nho nhat la: ',TuoiMin);
 Writeln('+Nhan vien: ',HoTen1,' co bac luong lon nhat: ',LuongMax:10:2);
 Writeln('+Nhan vien: ',HoTen2,' co bac luong nho nhat: ',LuongMin:10:2);
 Writeln('+Bac luong trung binh cua toan Cong Ty : ',LuongTb/n:10:2);
 Readln
End.


.

Bài tập

Program Thu_vien;
CONST
 Max = 100;
TYPE
 ThuVien = RECORD
 TenSach : String[30];
 TacGia : String[24];
 NamXb : 1900..1999;
 NguoiMuon : String[24];
 End;
VAR
 Sach : Array[1..Max] Of ThuVien;
 i, n, x : Integer;
Begin
 Writeln('QUAN LY SACH CUA THU VIEN');
 Writeln('-------------------------');
 Write('-So luong sach: ');
 Readln(n);
 For i := 1 To N Do
 With Sach[i] Do
 Begin
 Write('+Ten sach : ');
 Readln(TenSach);
 Write('+Tac gia : ');
 Readln(TacGia);
 Write('+Nam Xuat ban : ');
 Readln(NamXb);
 Write('+Nguoi muon (Neu khong co ai muon thi bam <Enter>: ');
 Readln(NguoiMuon);
 End;
 Writeln;
 x := 0;
 For i := 1 To N Do
 With Sach[i] Do
 Begin
 Writeln('-Ten sach: ',TenSach);
 Writeln(' +Tac gia : ',TacGia);
 Writeln(' +Nam xuat ban : ',NamXb);
 If NguoiMuon <> ' ' Then
 Begin
 Writeln(' +Nguoi muon : ',NguoiMuon);
 x := x + 1;
 End;
 End;
 Writeln;
 Writeln('+So sach da cho muon: ',x,' quyen');
 Readln
End.

.

Bài tập

 Program Sap_Xep_Diem_Tang;
TYPE
 Lop = RECORD
 HoTen : String[24];
 NamSinh : Integer;
 DiemTb : Real;
 End;
VAR
 Hs : Array[1..50] Of lop;
 i,j,n : Integer;
 Tam : Lop;
Begin
 Writeln('SAP XEP DIEM TANG DAN);');
 Writeln('Giai thuat noi Buble');
 Writeln('--------------------');
 Writeln;
 Write('-So hoc sinh: ');
 Readln(n);
 For i := 1 To N Do
 With Hs[i] Do
 Begin
 Write('+Ho ten hoc sinh thu: ',i:2,' la: ');
 Readln(Hoten);
 Write('+Nam sinh: ');
 Readln(NamSinh);
 Write('+Diem trung binh: ');
 Readln(DiemTb);
 End;
 For i := 1 To N-1 Do
 For j := 1 To N-i Do
 If Hs[j].DiemTb > Hs[j+1].DiemTb Then
 Begin
 Tam := Hs[j];
 Hs[j] := Hs[j+1];
 Hs[j+1] := Tam;
 End;
 Writeln;
 Writeln(' DANH SACH SAP XEP');
 Writeln;
 For i := 1 To N Do
 With Hs[i] Do
 Writeln('-',HoTen:24,' :',Namsinh:4,' , ',DiemTb:5:2);
 Readln
End.

.

Bài tập

 Program Tinh_Diem_Xep_Hang;
TYPE
 Lop = RECORD
 HoTen : String[24];
 NamSinh : Integer;
 Tb1,Tb2,Tb : Real;
 End;
VAR
 Hs : Array[1..50] Of lop;
 i,j,n,Hang: Integer;
 Tam : Lop;
Begin
 Writeln('TINH DIEM VA XEP HANG);');
 Writeln('Giai thuat noi Buble');
 Writeln('--------------------');
 Writeln;
 Write('-So hoc sinh: ');
 Readln(n);
 For i := 1 To N Do
 With Hs[i] Do
 Begin
 Write(' +Ho ten hoc sinh thu: ',i:2,' la: ');
 Readln(Hoten);
 Write(' +Nam sinh: ');
 Readln(NamSinh);
 Write(' +Diem trung binh hoc ky 1: ');
 Readln(Tb1);
 Write(' +Diem trung binh hoc ky 2: ');
 Readln(Tb2);
 Tb :=(Tb1 + Tb2)/2;
 Writeln;
 End;
 For i := 1 To N-1 Do
 For j := 1 To N-i Do
 If Hs[j].Tb < Hs[j+1].Tb Then
 Begin
 Tam := Hs[j];
 Hs[j] := Hs[j+1];
 Hs[j+1] := Tam;
 End;
 Writeln;
 Writeln(' DANH SACH XEP HANG');
 Writeln;
 Hang := 1;
 For i := 1 To N Do
 Begin
 If (i > 1) And (Hs[i].Tb <> Hs[i-1].Tb) Then
 Hang := i;
 Writeln(' .Hoc sinh : ',Hs[i].HoTen);
 Writeln(' .Nam sinh : ',Hs[i].NamSinh);
 Writeln(' .Diem trung binh ca nam : ',Hs[i].Tb:5:2);
 Writeln(' .Xep hang ca nam : ',Hang);
 End;
 Readln
End.

.

Bài tập

 Program Tinh_Diem_Xep_Hang_Hoc_ky;
TYPE
 Lop = RECORD
 HoTen : String[24];
 V,T,L,H,Nn,Tb : Real;
 End;
VAR
 Hs : Array[1..50] Of lop;
 i,j,n,Hang: Integer;
 Tam : Lop;
Begin
 Writeln('TINH DIEM VA XEP HANG);');
 Writeln('Giai thuat noi Buble');
 Writeln('--------------------');
 Writeln;
 Write('-So hoc sinh: ');
 Readln(n);
 For i := 1 To N Do
 With Hs[i] Do
 Begin
 Write(' +Ho ten hoc sinh thu: ',i:2,' la: ');
 Readln(Hoten);
 Write(' +Diem mon Van: ');
 Readln(V);
 Write(' +Diem mon Toan: ');
 Readln(T);
 Write(' +Diem mon Ly: ');
 Readln(L);
 Write(' +Diem mon Hoa: ');
 Readln(H);
 Write(' +Diem mon Ngoai ngu: ');
 Readln(Nn);
 Tb :=((V*3 + T*3)+(L*2 + H*2 + Nn*2)) /12;
 Writeln;
 End;
 For i := 1 To N-1 Do
 For j := 1 To N-i Do
 If Hs[j].Tb < Hs[j+1].Tb Then
 Begin
 Tam := Hs[j];
 Hs[j] := Hs[j+1];
 Hs[j+1] := Tam;
 End;
 Writeln;
 Writeln(' DANH SACH XEP HANG');
 Writeln;
 Hang := 1;
 For i := 1 To N Do
 Begin
 If (i > 1) And (Hs[i].Tb <> Hs[i-1].Tb) Then
 Hang := i;
 Writeln(' .Hoc sinh : ',Hs[i].HoTen);
 Writeln(' .Diem trung binh ca nam : ',Hs[i].Tb:5:2);
 Writeln(' .Xep hang ca nam : ',Hang);
 End;
 Readln
End.

.

Bài tập

 Program Sap_Xep_Tuoi;
TYPE
 Ngay_Sinh = RECORD
 Ngay,Thang,Nam : Integer;
 End;

 CongTy = RECORD
 HoTen : String[24];
 NgaySinh : Ngay_Sinh;
 End;
VAR
 i,j,n : Integer;
 Tam : CongTy;
 Nv : Array[1..100] Of CongTy;
Begin
 Writeln('SAP XEP THEO TUOI');
 Writeln('-----------------');
 Writeln;
 Write('-So nhan vien: ');
 Readln(n);
 For i := 1 To N Do
 With Nv[i] Do
 Begin
 Write('-Ho ten nhan vien thu: ',i,' la: ');
 Readln(HoTen);
 Writeln('-Nhap ngay, thang, nam sinh');
 With NgaySinh Do
 Begin
 Write(' +Ngay : ');
 Readln(ngay);
 Write(' +Thang: ');
 Readln(Thang);
 Write(' +Nam : ');
 Readln(Nam);
 End;
 End;
 For i := 1 To N-1 Do
 For j := 1 To N - i Do
 If (Nv[j].Ngaysinh.Nam > Nv[j+1].NgaySinh.Nam) OR
 ((Nv[j].Ngaysinh.Nam = Nv[j+1].NgaySinh.Nam) AND
 (Nv[j].Ngaysinh.Thang > Nv[j+1].NgaySinh.Thang)) OR
 ((Nv[j].Ngaysinh.Nam = Nv[j+1].NgaySinh.Nam) AND
 (Nv[j].Ngaysinh.Thang = Nv[j+1].NgaySinh.Thang) AND
 (Nv[j].Ngaysinh.Ngay > Nv[j+1].NgaySinh.Ngay)) Then
 Begin
 Tam := Nv[j];
 Nv[j] := Nv[j+1];
 Nv[j+1] := Tam;
 End;
 Writeln;
 Writeln('DANH SACH NHAN VIEN XEP THEO TUOI GIAM DAN');
 Writeln;
 For i := 1 To N Do
 With Nv[i] Do
 Writeln('-',Hoten:24,' ,sinh ngay: ',NgaySinh.Ngay,'/',NgaySinh.Thang,'/',NgaySinh.Nam);
 Readln
End.

.

Bài tập

 Program Khao_Sat_Hai_Duong_Tron;
TYPE
 DuongTron = RECORD
 R : Real;
 x, y : Real;
 End;
VAR
 Dt1, Dt2 : DuongTron;
 Kc, Tong, Hieu : Real;

BEGIN
 Writeln('KHAO SAT 2 DUONG TRON');
 Writeln('---------------------');
 Writeln;
 Writeln('*Duong tron thu nhat');
 Write(' +Ban kinh: ');
 Readln(Dt1.R);
 Write(' +Toa do x: ');
 Readln(Dt1.x);
 Write(' +Toa do y: ');
 Readln(Dt1.y);
 writeln;
 Writeln('*Duong tron thu hai');
 Write(' +Ban kinh: ');
 Readln(Dt2.R);
 Write(' +Toa do x: ');
 Readln(Dt2.x);
 Write(' +Toa do y: ');
 Readln(Dt2.y);

 Kc := Sqrt(Sqr(Dt1.x - Dt2.x) + Sqr(Dt1.y - Dt2.y));
 Tong := Dt1.R + Dt2.R;
 Hieu := ABS(Dt1.R - Dt2.R);
 If (Kc = 0) AND (Hieu = 0) Then
 Writeln('-Hai duong tron trung nhau')
 Else
 If (Hieu > Kc) Then
 Writeln('-Hai duong tron long nhau')
 Else
 If (Tong = Kc) OR (Hieu = Kc) Then
 Writeln('-Hai duong tron tiep xuc nhau')
 Else
 If (Tong > Kc) AND (Hieu < Kc) Then
 Writeln('-Hai duong tron cat nhau')
 Else
 If (Tong < Kc) Then
 Writeln('-Hai duong tron o ngoai nhau');
 Readln
END.

.

Bài tập

 Program Diem_Thi;
CONST
 Max = 50;
 Td1 = '|========================|======|======|======|';
 Td2 = '| HO VA TEN | DIEM | TL1 | TL2 |';
 Td3 = '|------------------------|------|------|------|';
 Td4 = '|---------------------------------------------|';

TYPE
 DiemThi = RECORD
 HoTen : String[24];
 Diem1 : Real;
 Case ThiLai1 : Boolean Of
 True : (Diem2 : Real;
 Case ThiLai2 : Boolean Of
 True : (Diem3 : Real));
 End;
VAR
 Diem : Array[1..Max] Of DiemThi;
 n, i : 1..Max;
BEGIN
 Writeln('-So luong sinh vien: ');
 Readln(n);
 For i := 1 To N Do
 With Diem[i] do
 Begin
 Write('+Ho va ten sinh vien thu: ',i,' = ');
 Readln(HoTen);
 Write('+Diem thi : ');
 Readln(Diem1);
 If Diem1 < 5 Then
 Begin
 ThiLai1 := True;
 Write(' -Diem thi lai lan 1= ');
 Readln(Diem2);
 If Diem2 < 5 Then
 Begin
 ThiLai2 := True;
 Write(' -Diem thi lai lan 2= ');
 Readln(Diem3);
 End;
 End;
 End;
 Writeln(#32:34,'KET QUA HOC TAP');
 Writeln(#32:20,Td1);
 Writeln(#32:20,Td2);
 Writeln(#32:20,Td3);
 For i := 1 To N Do
 With Diem[i] Do
 Begin
 Write(#32:20);
 Write(#124,HoTen,#32:24-length(HoTen));
 Write(#124,Diem1:6:1);
 If Diem1 < 5 Then
 Begin
 Write(#124,Diem2:6:1);
 If Diem2 < 5 Then
 Writeln(#124,Diem3:6:1,#124)
 Else
 Writeln(#124,#32:6,#124);
 End
 Else
 Writeln(#124,#32 :6, #124, #32 :6, #124);
 End;
 Writeln(#32:20,Td4);
 Readln
END.

.

Bài tập

 Program Da_Thuc;
CONST
 MaxOrder = 10;
TYPE
 PolyNom = RECORD
 Bac : Integer;
 HeSo : Array[0..MaxOrder] Of Real;
 End;
VAR
 A,B,C : Polynom;
 i : Integer;
{-------------------------}
Procedure Nhap;
Var
 i : Integer;
Begin
 Repeat
 Writeln;
 Writeln('Hay nhap 2 da thu A(x), B(x) voi');
 Write('-Bac A (phai <= ',MaxOrder,' ) = ');
 Readln(A.Bac);
 If A.Bac > MaxOrder Then
 Writeln(#7,'Bac A phai <= ',MaxOrder,' ! nhap lai ');
 Write('-Bac B (phai <= ',MaxOrder,' ) = ');
 Readln(B.Bac);
 If B.Bac > MaxOrder Then
 Writeln(#7,'Bac B phai <= ',MaxOrder,' ! nhap lai ');
 Until (A.Bac <= MaxOrder) And (B.Bac <= MaxOrder);
 For i := 0 To MaxOrder Do
 Begin
 A.Heso[i] :=0;
 B.Heso[i] :=0;
 End;
 Writeln;
 Writeln('Nhap ca he so cua da thuc A: ');
 For i := A.Bac DownTo 0 Do
 Begin
 Write(' A[',i,'] = ');
 Readln(A.heso[i]);
 End;
 Writeln;
 Writeln('Nhap ca he so cua da thuc B: ');
 For i := B.Bac DownTo 0 Do
 Begin
 Write(' B[',i,'] = ');
 Readln(B.heso[i]);
 End;
End;

{-------------------------}
Procedure Cong(A,B : Polynom; Var C : Polynom);
Var
 BacMax :Integer;
Begin
 If A.Bac < B.Bac Then
 Begin
 C.Bac :=B.Bac;
 For i := A.Bac + 1 To B.Bac Do
 A.Heso[i] := 0
 End
 Else
 Begin
 C.Bac := A.Bac;
 For i := B.Bac + 1 To A.Bac Do
 B.Heso[i] := 0
 End;
 C.Bac :=A.Bac;
 For i := C.Bac To MaxOrder Do
 C.Heso[i] := 0;
 For i := 0 To C.Bac Do
 C.Heso[i] := A.Heso[i] + B.Heso[i];
End;

{-------------------------}
Procedure Nhan(A,B : Polynom; Var C:Polynom);
Var
 i,j : Integer;
Begin
 For i := 0 To MaxOrder Do
 C.Heso[i] := 0;
 For i := 0 To A.Bac Do
 For j := 0 To B.Bac Do
 C.Heso[i+j] := C.Heso[i+j] + A.Heso[i] * B.Heso[j];
 C.Bac :=A.Bac + B.Bac;
End;

{-------------------------}
procedure Chia(P, Q :Polynom);
Var
 i,k,kk : Integer;
 G : Polynom;
Begin
 If P.Bac < Q.Bac Then
 For i := P.Bac + 1 To Q.Bac Do
 P.Heso[i] := 0;
 If P.Bac > Q.Bac Then
 For i := Q.Bac + 1 To P.Bac Do
 Q.Heso[i] := 0;
 Write('-Hay cho he so trong ket qua phep chia: ');
 Readln(kk);
 Writeln('Da thuc ket qua xep theo so mu giam dan. ');
 Writeln;
 Write('Bac: ');
 For k := 0 To kk Do
 Write(P.Bac-Q.Bac-k:6);
 Writeln;
 Write('He so ');
 For k := 0 To kk Do
 Begin
 G.Heso[k] := P.Heso[P.bac] / Q.Heso[Q.Bac];
 If Frac(G.Heso[k]) =0 Then
 Write(G.Heso[k]:6:0)
 Else
 Write(G.Heso[k]:6:0);
 For i:= Q.Bac DownTo 1 Do
 P.Heso[P.Bac-Q.Bac+i] := P.Heso[P.Bac+i-1] - G.Heso[k]*Q.Heso[i-1];
 For i := P.Bac-Q.bac Downto 0 Do
 P.Heso[i] :=0;
 End;
End;

{--------------------------}
BEGIN
 Nhap;
 Nhan(A,B,C);
 Writeln;
 Writeln('Cac he so cua da thuc tich: ');
 Write('Bac: ');
 For i := 0 To C.Bac Do
 Write(i:7);
 Writeln;
 Write('He so: ');
 For i := 0 To C.Bac Do
 If Frac(C.Heso[i]) = 0 Then
 Write(C.Heso[i]:7:0)
 Else
 Write(C.Heso[i]:7:0);
 Writeln;
 Writeln;
 Chia(A,B);
 Readln
END.

.

Bài tập


.

Advertisements

About pascalteacher

Trang thông tin Toán học và Tin học

Thảo luận

Không có bình luận

Trả lời

Mời bạn điền thông tin vào ô dưới đây hoặc kích vào một biểu tượng để đăng nhập:

WordPress.com Logo

Bạn đang bình luận bằng tài khoản WordPress.com Log Out / Thay đổi )

Twitter picture

Bạn đang bình luận bằng tài khoản Twitter Log Out / Thay đổi )

Facebook photo

Bạn đang bình luận bằng tài khoản Facebook Log Out / Thay đổi )

Google+ photo

Bạn đang bình luận bằng tài khoản Google+ Log Out / Thay đổi )

Connecting to %s

Các tác giả

Danh mục

Tháng Mười 2014
H B T N S B C
« Th11   Th11 »
 12345
6789101112
13141516171819
20212223242526
2728293031  

NCT Computer

Flickr Photos

surge

Edge of the Sun

JWL0043 Eagle..

More Photos

Thống kê

  • 137,017 lượt xem

pascalteacher.nct@gmail.com


Trang huấn luyện học sinh giỏi Tin học

%d bloggers like this: