Московский государственный Институт Радиотехники. Г. Москва Курсовая работа по програмированию на языке высокого уровня. Тема Автосалон. Студента факультета вмс, группы вв607 Станкевича Сергея Алексеевича Г. Москва,2008 Реферат
Скачать 318.5 Kb.
|
Модуль Класса-машины unit Avtomobil; interface uses SysUtils, Dialogs; type Avto = class protected M : string; Y : integer; S : string; C : integer; public constructor Create_Avto(Marka : string; Year : integer; Sost : string; Cena : integer); destructor Destroy_Avto; procedure SetM(const Marka : string); procedure SetY(const Year : integer); procedure SetS(const Sostoianie : string); procedure SetC(const Cena : integer); procedure SetCar(Marka:string; Year:integer; Sostoianie:string; Cena:integer); function GetM : string; function GetY : integer; function GetS : string; function GetC : integer; published property PMarka : string read GetM write SetM; property PGod : integer read GetY write SetY; property PSostoianie : string read GetS write SetS; property PCena : integer read GetC write SetC; end; implementation constructor Avto.Create_Avto(Marka : string; Year : integer; Sost : string; Cena : integer); var s : string; begin if (Marka <> '') and (Sost <> '') then begin s := ' ' + Marka[1]; s := AnsiUpperCase(s); delete(Marka,1,1); delete(s,1,1); Marka := s + Marka; s := ' ' + Sost[1]; s := AnsiUpperCase(s); delete(Sost,1,1); delete(s,1,1); Sost := s + Sost; end; M := Marka; Y := Year; self.S := Sost; C := Cena; end; destructor Avto.Destroy_Avto; begin MessageDlg('Îáúåêò áûë óäàë¸í',mtInformation,[mbOK],1); end; procedure Avto.SetM(const Marka : string); begin M := Marka; end; procedure Avto.SetY(const Year : integer); begin Y := Year; end; procedure Avto.SetS(const Sostoianie : string); begin S := Sostoianie; end; procedure Avto.SetC(const Cena : integer); begin C := Cena; end; procedure Avto.SetCar(Marka:string; Year:integer; Sostoianie:string; Cena:integer); begin SetM(Marka); SetY(Year); SetS(Sostoianie); SetC(Cena); end; function Avto.GetM : string; begin GetM := M; end; function Avto.GetY : integer; begin GetY := Y; end; function Avto.GetS : string; begin GetS := S; end; function Avto.GetC : integer; begin GetC := C; end; end. Модуль класса – запроса unit Pokupatel; interface uses SysUtils, Dialogs; type Potrebitel = class protected T : string; M : string; S : string; C : integer; public constructor Create_potrebitel(Telefon,Marka,Sost : string; Cena : integer); destructor Destroy_Potrebitel; procedure SetT(const Telefon : string); procedure SetM(const Marka : string); procedure SetS(const Sostoianie : string); procedure SetC(const Cena : integer); procedure SetPokupatel(Telefon,Marka,Sostoianie : string; Cena:integer); function GetT : string; function GetM : string; function GetS : string; function GetC : integer; published property PMarka : string read GetM write SetM; property PTelefon : string read GetT write SetT; property PSostoianie : string read GetS write SetS; property PCena : integer read GetC write SetC; end; implementation constructor Potrebitel.Create_Potrebitel(Telefon : string; Marka : string; Sost : string; Cena : integer); var s:string; begin if (Length(Marka) <> 0) and (Length(Sost) <> 0) then begin s := ' ' + Marka[1]; s := AnsiUpperCase(s); delete(Marka,1,1); delete(s,1,1); Marka := s + Marka; s := ' ' + sost[1]; s := AnsiUpperCase(s); delete(sost,1,1); delete(s,1,1); Sost := s + Sost; end; T := Telefon; M := Marka; self.S := Sost; C := Cena; end; destructor Potrebitel.Destroy_Potrebitel; begin MessageDlg('Îáúåêò:Ïîêóïàòåëü - áûë óäàë¸í',mtInformation,[mbOK],1); end; procedure Potrebitel.SetT(const Telefon : string); begin T := Telefon; end; procedure Potrebitel.SetM(const Marka : string); begin M := Marka; end; procedure Potrebitel.SetS(const Sostoianie : string); begin S := Sostoianie; end; procedure Potrebitel.SetC(const Cena : integer); begin C := Cena; end; procedure Potrebitel.SetPokupatel(Telefon,Marka,Sostoianie : string; Cena:integer); begin SetT(Telefon); SetM(Marka); SetS(Sostoianie); SetC(Cena); end; function Potrebitel.GetT : string; begin GetT := T; end; function Potrebitel.GetM : string; begin GetM := M; end; function Potrebitel.GetS : string; begin GetS := S; end; function Potrebitel.GetC : integer; begin GetC := C; end; end. Модуль Класс-массива unit Salon; interface uses SysUtils, Windows, Avtomobil, Pokupatel, Dialogs; type AvtoSalon = class protected Avtos : array of Avto; N : integer; Variants : array of Avto; public constructor Create_Cars(const p:integer); procedure NullAvtos; procedure SetN(const l : integer); function GetN :integer; function GetZ : integer; procedure Insert_Car(Marka:string; const Year:integer; Sost :string; const Cena:integer; l:integer); procedure Add_Car(const Marka:string; const Year:integer; const Sost :string; const Cena:integer); function Get_Car(const i : integer) : string; function Get_Variant(const i : integer) : string; procedure Sort_Mas(Sposob:boolean); procedure Find_Variants(const Marka:string; const Sost : string; const Cena : integer); end; type AvtoSalon2 = class protected Zaprosi : array of Potrebitel; N : integer; public constructor Create_Zapros(const p:integer); procedure NullZapros; Function GetN : integer; procedure Insert_Zapros(Telefon,Marka,Sost :string; const Cena:integer; l:integer); procedure Add_Zapros(const Telefon : string; const Marka:string; const Sost :string; const Cena:integer); function Get_Zapros(const i : integer) : string; function Get_Marka(l : integer):string; function Get_Sost(l : integer):string; function Get_Cena(l : integer):integer; end; implementation constructor AvtoSalon.Create_Cars(const p:integer); var i:integer; begin if p>0 then begin SetLength(Avtos,p); for i:=0 to p-1 do Avtos[i] := Avto.Create_Avto('',0,'',0); N := p; end; end; procedure AvtoSalon.NullAvtos; begin SetLength(Avtos,0); N:=0; end; procedure AvtoSalon.SetN(const l : integer); begin N := l; end; function Avtosalon.GetN :integer; begin GetN := N; end; function AvtoSalon.GetZ : integer; begin GetZ := Length(Variants); end; procedure AvtoSalon.Add_Car(const Marka:string; const Year:integer; const Sost :string; const Cena:integer); begin N := N + 1; SetLength(Avtos,N); Avtos[N-1] := Avto.Create_Avto(Marka,Year,Sost,Cena); end; procedure AvtoSalon.Insert_Car(Marka:string; const Year:integer; Sost :string; const Cena:integer; l:integer); var s : string; begin if (l >= 0) and (l < N) then begin s := ' ' + Marka[1]; s := AnsiUpperCase(s); delete(Marka,1,1); delete(s,1,1); Marka := s + Marka; Avtos[l].SetM(Marka); Avtos[l].SetY(Year); s := ' ' + Sost[1]; s := AnsiUpperCase(s); delete(Sost,1,1); delete(s,1,1); Sost := s + Sost; Avtos[l].SetS(Sost); Avtos[l].SetC(Cena); end; end; function AvtoSalon.Get_Car(const i : integer):string; begin Get_Car := Avtos[i].GetM + Chr(VK_RETURN) + IntToStr(Avtos[i].GetY) + Chr(VK_RETURN) + Avtos[i].GetS + Chr(VK_RETURN) + IntToStr(Avtos[i].GetC); end; function AvtoSalon.Get_Variant(const i : integer) : string; begin Get_Variant := Variants[i].GetM + Chr(VK_RETURN) + IntToStr(Variants[i].GetY) + Chr(VK_RETURN) + Variants[i].GetS + Chr(VK_RETURN) + IntToStr(Variants[i].GetC); end; procedure AvtoSalon.Sort_Mas(Sposob:boolean); var C : Avto; i,i2,count : integer; begin count := High(Avtos); for i:=1 to count do begin for i2:=count downto i do begin if Sposob = true then if Avtos[i2 - 1].GetM > Avtos[i2].GetM then begin C := Avtos[i2-1]; Avtos[i2 - 1] := Avtos[i2]; Avtos[i2] := C; end; if Sposob = False then if Avtos[i2 - 1].GetY < Avtos[i2].GetY then begin C := Avtos[i2-1]; Avtos[i2 - 1] := Avtos[i2]; Avtos[i2] := C; end; end; end; end; procedure AvtoSalon.Find_Variants(const Marka:string; const Sost : string; const Cena : integer); var i,l : integer; begin Variants := nil; l:=0; for i:=0 to N-1 do begin if (Avtos[i].GetM = Marka) or (Avtos[i].GetS = Sost) or (Avtos[i].GetC = Cena) then begin l:=l+1; SetLength(Variants,l); Variants[l-1] := Avto.Create_Avto(Avtos[i].GetM,Avtos[i].GetY,Avtos[i].GetS,Avtos[i].GetC); end; end; end; constructor AvtoSalon2.Create_Zapros(const p:integer); var i:integer; begin if p>0 then begin SetLength(Zaprosi,p); for i:=0 to p-1 do Zaprosi[i] := Potrebitel.Create_potrebitel('','','',0); N := p; end; end; procedure AvtoSalon2.NullZapros; begin SetLength(Zaprosi,0); N:=0; end; function Avtosalon2.GetN :integer; begin GetN := N; end; procedure AvtoSalon2.Insert_Zapros(Telefon,Marka,Sost :string; const Cena:integer; l:integer); var s : string; begin if (l >= 0) and (l < N) then begin Zaprosi[l].SetT(Telefon); s := ' ' + Marka[1]; s := AnsiUpperCase(s); delete(Marka,1,1); delete(s,1,1); Marka := s + Marka; Zaprosi[l].SetM(Marka); s := ' ' + Sost[1]; s := AnsiUpperCase(s); delete(Sost,1,1); delete(s,1,1); Sost := s + Sost; Zaprosi[l].SetS(Sost); Zaprosi[l].SetC(Cena); end; end; procedure Avtosalon2.Add_Zapros(const Telefon : string; const Marka:string; const Sost :string; const Cena:integer); begin N := N + 1; SetLength(Zaprosi,N); Zaprosi[N-1] := Potrebitel.Create_potrebitel(Telefon,Marka,Sost,Cena); end; function AvtoSalon2.Get_Zapros(const i : integer) : string; begin Get_Zapros := Zaprosi[i].GetT + Chr(VK_RETURN) + Zaprosi[i].GetM + Chr(VK_RETURN) + Zaprosi[i].GetS + Chr(VK_RETURN) + IntToStr(Zaprosi[i].GetC); end; function AvtoSalon2.Get_Marka(l : integer):string; begin Get_Marka := Zaprosi[l].GetM; end; function AvtoSalon2.Get_Sost(l : integer):string; begin Get_Sost := Zaprosi[l].GetS; end; function AvtoSalon2.Get_Cena(l : integer):integer; begin Get_Cena := Zaprosi[l].GetC; end; end. Модуль работа с файлами unit GetFail; interface uses Salon, Dialogs; type RecCars = record Marka : string[20]; Year : integer; Sost : string[20]; Cena : integer; end; RecZapros = record Telefon : string[20]; Marka : string[20]; Sost : string[20]; Cena : integer; end; FileCar = File of RecCars; FileZapros = File of RecZapros; var FC : FileCar; FZ : FileZapros; RC : RecCars; RZ : RecZapros; procedure GetFileCars(var Mas : AvtoSalon; const FFF : string); procedure GetFileZapros(var Mas : AvtoSalon2; const FFF : string); implementation procedure GetFileCars(var Mas : AvtoSalon; const FFF : string); begin AssignFile(FC,FFF); {$I-} Reset(FC); {$I+} if IOResult = 0 then begin Mas.NullAvtos; while not( EOF(FC) ) do begin Read(FC,RC); Mas.Add_Car(RC.Marka,RC.Year,RC.Sost,RC.Cena); end; Close(FC); end else MessageDLG('Óêàçàííîãî ôàéëà íåò',mtWarning,[mbOk],1); end; procedure GetFileZapros(var Mas : AvtoSalon2; const FFF : string); begin AssignFile(FZ,FFF); {$I-} Reset(FZ); {$I+} if IOResult = 0 then begin Mas.NullZapros; while not( EOF(FZ) ) do begin Read(FZ,RZ); Mas.Add_Zapros(RZ.Telefon,RZ.Marka,RZ.Sost,RZ.Cena); end; closeFile(FZ); end else MessageDLG('Óêàçàííîãî ôàéëà íåò',mtWarning,[mbOk],1); end; end. |