Практическая работа №4
Тема практической работы: Поля классов. Пример описания классов.
Цель практической работы: Рассмотреть классы и пример создания программы используя их.
Ход работы :
Рис13 Рис 14
Листинг :
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TPayment = class
SurnameNameMiddleName : string;
Salary : Real ;
YearOfEmployment : integer;
PercentagePremium : real;
IncomeTax : real ;
NumberOfDaysInMonthR : word;
NumberOfDaysInMonthN : word;
AssessedAmount : real;
WithheldAmount : real;
function FindAssessedAmount : real;
end;
type
TForm1 = class(TForm)
Label1: TLabel;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function TPayment.FindAssessedAmount : real;
begin
Result:=1300;
end;
procedure TForm1.Button1Click(Sender: TObject);
var MyZarplata:TPayment;
begin
MyZarplata:=TPayment.Create;
Button1.Caption:=Button1.ClassName;
Label1.Caption:=FloatToStr(MyZarplata.FindAssessedAmount());
end;
end.
Самостоятельное Задание
Рис 15
Листинг :
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TPayment = class
SurnameNameMiddleName : string;
Salary : Real ;
YearOfEmployment : integer;
PercentagePremium : real;
IncomeTax : real ;
NumberOfDaysInMonthR : word;
NumberOfDaysInMonthN : word;
AssessedAmount : real;
WithheldAmount : real;
function FindAssessedAmount : real;
function FindWithheldAmount : real;
function FindYearOfEmployment : real;
end;
type
TForm1 = class(TForm)
Label1: TLabel;
Button1: TButton;
Label2: TLabel;
Label3: TLabel;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end
var
Form1: TForm1;
implementation
{$R *.dfm}
function TPayment.FindAssessedAmount : real;
begin
Result:=1300;
end;
function TPayment.FindWithheldAmount : real;
begin
Result:=500;
end;function TPayment.FindYearOfEmployment : real;
begin
Result:=2015;
end;
procedure TForm1.Button1Click(Sender: TObject);
var MyZarplata:TPayment;
begin
MyZarplata:=TPayment.Create;
Button1.Caption:=Button1.ClassName;
Label1.Caption:=FloatToStr(MyZarplata.FindAssessedAmount());
Label2.Caption:=FloatToStr(MyZarplata.FindWithheldAmount());
Label3.Caption:=FloatToStr(MyZarplata.FindYearOfEmployment());
end;
end.
Достарыңызбен бөлісу: |