很急!!(100分)

  • 主题发起人 dengminli
  • 开始时间
D

dengminli

Unregistered / Unconfirmed
GUEST, unregistred user!
定义一个盒子box类,其数据成员有:长(length)、宽(width)和高(height),成员函数包括构造函数、析构函数、提供盒子体积函数及提供盒子表面积函数。
并定义一个box类的对象进行测试。
 
5

52free

Unregistered / Unconfirmed
GUEST, unregistred user!
type Tbox=class
l:longint;
W:longint;
H:longint;
public:
construct create(ll,ww,hh:longint);
function gettj:longint;
function getmj:longint;
end;
Tbox.create(ll,ww,hh:longint);
begin
l:=ll;
w:=ww;
h:=hh;
end;
function Tbox.gettj:longint;
begin
result:=l*w*h;
end;

function Tbox.getmj:longint;
begin
result:=2*(l*w+l*h+w*h);
end;
 
S

st_cumt

Unregistered / Unconfirmed
GUEST, unregistred user!
同意楼上
 
W

wr960204

Unregistered / Unconfirmed
GUEST, unregistred user!
unit UnitBox;
interface
uses
Classes, Windows, Messages, SysUtils, Variants, TypInfo, ActiveX;
type
TBox = class(TObject)
private
FLong:do
uble;
FWidth:do
uble;
FHeight:do
uble;
function GetAcreage:do
uble;
function GetBulk:do
uble;
public
constructor Create(ALong, AWidth, AHeight:do
uble);
virtual;
destructor Destroy;
override;
property Long:do
uble read FLong write FLong;
property Width:do
uble read FWidth write FWidth;
property Height:do
uble read FHeight write FHeight;
property Acreage:do
uble read GetAcreage;
//面积
property Bulk:do
uble read GetBulk;
//体积
end;
implementation
{ TBox }
constructor TBox.Create(ALong, AWidth, AHeight:do
uble);
begin
FLong := ALong;
FWidth := AWidth;
FHeight := AHeight;
end;

destructor TBox.Destroy;
begin
inherited Destroy;
end;

function TBox.GetAcreage:do
uble;
begin
Result := 2 * (FHeight * FLong + FHeight * FWidth + FLong * FWidth);
end;

function TBox.GetBulk:do
uble;
begin
Result := FHeight * FWidth * FLong;
end;

end.

测试
var
Box:TBox;
....
Box:=TBox.Create(10,10,10);
showmessage(floattostr(Box.Bulk));
Box.free;
 
W

woyaoying

Unregistered / Unconfirmed
GUEST, unregistred user!
同意wr960204
写的非常好,体现了属性封装类的特性,还有重载create!
 
S

sid033

Unregistered / Unconfirmed
GUEST, unregistred user!
wr960204很专业
 
W

WorkForYou

Unregistered / Unconfirmed
GUEST, unregistred user!
什么问题?
 

老人家

Unregistered / Unconfirmed
GUEST, unregistred user!
再加上一个构造函数吧
constructor Create();
virtual;
constructor TBox.Create();
begin
FLong := 1
FWidth := 1;
FHeight := 1;
end;
要不下面的就没有意义了;
property Long:do
uble read FLong write FLong;
property Width:do
uble read FWidth write FWidth;
property Height:do
uble read FHeight write FHeight
 

Similar threads

回复
0
查看
810
不得闲
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
D
回复
0
查看
2K
DelphiTeacher的专栏
D
顶部