您的位置:首页 > 其它

用隐式方法调用一个计算长方体表面积和体积的类

2010-12-23 17:43 495 查看
实现函数下:

在对话框的头文件下:

#include "AreaVolumnClass.h"
#pragma comment(lib,"ExportClassDll.lib")
#if _MSC_VER >1000
#pragma once
#endif // _MSC_VER >1000

/////////////////////////////////////////////////////////////////////////////
// CUseExportClassDllDlg dialog

class CUseExportClassDllDlg : public CDialog
{
// Construction
public:
 CUseExportClassDllDlg(CWnd* pParent = NULL); // standard constructor
 AreaVolumnClass MyClass;

 

 

功能实现函数:

void CUseExportClassDllDlg::OnCal()
{
 // TODO: Add your control notification handler code here
 UpdateData(TRUE);
 MyClass.SetLenth(m_lenth);
 MyClass.SetWidth(m_width);
 MyClass.SetHeitht(m_height);
 m_SurfaceArea=MyClass.GetArea();
 m_Volumn=MyClass.GetVolumn();
 UpdateData(FALSE);

}

 

被调用的文件下:(新建的AreaVolumnClass类,.h文件下)

class _declspec(dllexport) AreaVolumnClass 
{
public:
 void SetHeitht(double c);
 void SetWidth(double b);
 void SetLenth(double a);
 double GetVolumn();
 double GetArea();
 AreaVolumnClass();
 virtual ~AreaVolumnClass();
 
private:
 double lenth;
 double width;
 double height;
};

 

实现cpp下:

// AreaVolumnClass.cpp: implementation of the AreaVolumnClass class.
//
//////////////////////////////////////////////////////////////////////

#include "AreaVolumnClass.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

AreaVolumnClass::AreaVolumnClass()
{
 height=lenth=width=0.0;

}

AreaVolumnClass::~AreaVolumnClass()
{

}

double AreaVolumnClass::GetArea()
{
    return 2*(height*lenth+height*width+width*lenth);
}

double AreaVolumnClass::GetVolumn()
{
  return height*lenth*width;
}

void AreaVolumnClass::SetLenth(double a)
{
   lenth=a;
}

void AreaVolumnClass::SetWidth(double b)
{
    width=b;
}

void AreaVolumnClass::SetHeitht(double c)
{
 height=c;

}

 

 

最后要注意的是:

1、那些功能函数必须一个个添加;

2、AreaVolumnClass.h必须拷到调用的工程文件中,否则出错;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  class null c
相关文章推荐