1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
|
program testobj;
{$APPTYPE CONSOLE}
{Define TCADRE} // ajouter $
uses
SysUtils;
{$ifDef TCADRE}
const Nb=5;
{$Else}
const Nb=4;
{$Endif}
type
TEmploye = class
public
Fnom : String;
Constructor Create(nom : String);
Function GetSalaire : String;Virtual;Abstract;
end;
TEmployeHoraire = class(TEmploye)
private
Fnbheures : Integer;
FTarifHoraire : Real;
FAugmentationHeuresSupp : Real;
public
Constructor create(nom : String;nbheures : Integer; TarifH,Augment : Real);
Function GetSalaire : String;Override;
end;
TCommercial = class(TEmploye)
Ffixe : real;
FChiffreAffaire : Real;
Constructor create (nom : String; fixe,CA : Real);
Function GetSalaire : String;Override;
end;
{$ifDef TCADRE}
TCadre = class(TEmploye)
Function GetSalaire : String;Override;
end;
{$Endif}
Constructor TEmploye.Create(nom : String);
begin
FNom:=Nom;
end;
{EmployeHoraire}
Constructor TEmployeHoraire.Create(nom : String;nbheures : Integer; TarifH,Augment : Real);
begin
Inherited create(Nom);
Fnbheures := nbheures;
FTarifHoraire :=TarifH;
FAugmentationHeuresSupp :=Augment;
end;
Function TEmployeHoraire.GetSalaire : String;
begin
result:='Salaire employé(e) horaire';
end;
{TCommercial}
Constructor TCommercial.Create(nom : String; fixe,CA : Real);
begin
Inherited create(Nom);
Ffixe:=Fixe;
FChiffreAffaire:=ca;
end;
Function TCommercial.GetSalaire : String;
begin
result:='Salaire commercial(e)';
end;
{TCadre}
{$ifDef TCADRE}
Function TCadre.GetSalaire : String;
begin
result:='Salaire cadre';
end;
{$Endif}
var
TableauEmployes : Array [1..nb] of TEmploye;
procedure TraiteTableau;
// l'ajout d'une nouvelle classe ne nécessite pas la modification de ce
// traitement POUR CE CONTEXTE
var I : Integer;
begin
For I:=1 to Length(TableauEmployes) do
begin
Write(TableauEmployes[I].Classname+' : ');
Writeln(TableauEmployes[I].GetSalaire);
end;
end;
begin
TableauEmployes[1]:=TEmployeHoraire.Create('E1',8,100,10);
TableauEmployes[2]:=TCommercial.Create('E2',2000,100);
TableauEmployes[3]:=TCommercial.Create('E43',2000,500);
TableauEmployes[4]:=TEmployeHoraire.Create('E4',8,100,5);
{$ifDef TCADRE}
TableauEmployes[5]:=TCadre.Create('E5');
{$Endif}
TraiteTableau;
readln;
end. |
Partager