满意答案
woshizdz
2013.04.27
采纳率:46% 等级:13
已帮助:14778人
//main.cpp文件内容
#include
#include
#include "rectangle.h"
using namespace std;
int main(int argc, char *argv[])
{
Rectangle rect1;
rect1.setLengthAndWidth();
rect1.showArea();
system("PAUSE");
return 0;
}
//Rectangle.h文件内容
#include
using namespace std;
class Rectangle
{
public:
void showArea();
void setLengthAndWidth();
private:
float length,width;
}
//rectangle.cpp文件内容
#include
#include"rectangle.h"
using namespace std;
void Rectangle::showArea()
{
cout<
}
void Rectangle::setLengthAndWidth()
{
do{
cout<
cin>>length>>width;
if (length<0||width<0) cout<
}while(length<0||width<0);
}
//运行通过的,你也可以把这三部分放一个文件里。
//其实并不长,只是为了可读性增加了空行,你可以去掉。
//而且如果放一个文件里可以去掉重复声明的头文件。
//但是为了更标准一些,建议你还是分三个文件放
60分享举报