Mar 7, 2009

Delphi中属性的使用(unit2)

unit Unit2;

interface

uses
Windows, Messages, SysUtils, Variants, Classes;

type
// 基类employee
employee=class
protected
name:string; // 姓名
empno:string; // 雇员号
accumpay:real;// 月薪
public
constructor create();// 构造函数
Procedure pay(); Virtual; // 计算月薪函数(虚拟方法)
Procedure displaystatus(); Virtual;// 显示信息函数(虚拟方法)
end;

//技术员类technician
technician=class(employee)
private
hrRate:string;//每小时酬金
hr:string; //当月工作时数
function GetHourlyRate():string;
procedure SetHourlyRate(Value: string);
function GetWorkHours():string;
procedure SetWorkHours(Value: string);

public
property MyHourlyRate: string read GetHourlyRate write SetHourlyRate;
property MyWorkHours: string read GetWorkHours write SetWorkHours;
Procedure pay(); override; //计算月薪函数(覆盖基类中同名方法)
Procedure displaystatus();override; //显示信息函数(覆盖基类中同名方法)
end;

//销售员类(派生于employee)
salesman=class(employee)
private
comm:string;//提取销售额的百分比
sale:string;//销售额
function GetCommrateRate():string;
procedure SetCommrateRate(Value: string);
function GetSales():string;
procedure SetSales(Value: string);
public
property MyCommRate: string read GetCommrateRate write SetCommrateRate;
property MySales: string read GetSales write SetSales;
Procedure pay(); override; //计算月薪函数(覆盖基类中同名方法)
Procedure displaystatus(); override; //显示信息函数(覆盖基类中同名方法)
end;

var
tech: technician;
sales: salesman;
name1,number,result1: string;

implementation
//employee类的函数实现
constructor employee.create();
begin
name:=name1; // name1为存放雇员姓名的全局变量
empno:=number; // number为存放雇员号的全局变量
accumpay:=0.0;
end;

Procedure employee.pay();
begin
end;

Procedure employee.displaystatus();
begin
end;

//技术员类的函数实现
Procedure technician.pay();
begin
accumpay:=strtofloat(GetHourlyRate)*strtofloat(GetWorkHours);
end;

Procedure technician.displaystatus();
begin
result1:=empno+'号技术员'+name+'的本月工资为 '+floattostr(accumpay);
end;
//技术员工资结算
function technician.GetHourlyRate(): string;
begin
GetHourlyRate:=hrRate;
end;
procedure technician.SetHourlyRate(Value: string);
begin
hrRate:=Value;
end;
function technician.GetWorkHours(): string;
begin
GetWorkHours:=hr;
end;
procedure technician.SetWorkHours(Value: string);
begin
hr:=value;
end;

//销售员类的函数实现
Procedure salesman.pay();
begin
accumpay:=strtofloat(GetCommrateRate)*strtofloat(GetSales);
end;

Procedure salesman.displaystatus();
begin
result1:=empno+'号销售员'+name+'的本月工资为 '+floattostr(accumpay);
end;
//销售人员工资结算
function salesman.GetCommrateRate(): string;
begin
GetCommrateRate:=comm;
end;
procedure salesman.SetCommrateRate(Value: string);
begin
comm:=value;
end;
function salesman.GetSales(): string;
begin
GetSales:=sale;
end;
procedure salesman.SetSales(Value: string);
begin
sale:=value;
end;

end.

No comments:

Powered By Blogger