C语言的一个编程题,求救
时间:2011-12-08
来源:互联网
声明一个rectangle类,包括数据成员l(长)和w(宽),求周长的函数成员getcir()类和求面积的函数成员getArea()。要求实现根据用户键盘输入的l和w值实例化一个rectangle类的对象,求出其周长和面积的输出。
作者: yo_yo2005 发布时间: 2011-12-08
这不会很难吧:
C/C++ code
C/C++ code
class rectangle{ public : rectangle() rectangle(unsigned l, unsigned w); ~rectangle(); float getcir(); float getArea(); private: float length; float width; }; rectangle :: rectangle() { length = 0; width = 0; } rectangle :: rectangle(float l, float w) { length = l; width = w; } float rectangle :: getcir() { return 2*(width + length); } float rectangle :: getArea() { return width * length; }
作者: Qoo_wzp 发布时间: 2011-12-08
补充一下:
C/C++ code
改成
C/C++ code
C/C++ code
rectangle(unsigned l, unsigned w);
改成
C/C++ code
rectangle(float l, float w);
作者: Qoo_wzp 发布时间: 2011-12-08
C/C++ code
#include<iostream> using namespace std; class rectangle { private: double l; double w; public: rectangle() { l = 0; w = 0; } rectangle(double dl, double dw) { l = dl; w = dw; } double getcir(); double getArea(); }; double rectangle::getcir() { return 2*(l+w); } double rectangle::getArea() { return l*w; } int main(void) { double l, w; cout << "请输入长和宽: "; cin >> l >> w; rectangle rect(l, w); cout << "周长: " << rect.getcir() << endl; cout << "面积: " << rect.getArea() << endl; return 0; }
作者: wangliangffaflgh 发布时间: 2011-12-08
我是在DEV C++上 实现的 希望帮到您了
#include<iostream>
using namespace std;
class rectangle
{
public :
rectangle(){};
rectangle( float l, float w){length = l;width = w;};
~rectangle(){};
float getcir();
float getArea();
private:
static float length,width;
};
float rectangle :: length = 0;
float rectangle :: width = 0;
float rectangle :: getcir()
{
float g1;
g1=2*(width + length);
cout<<"周长="<<g1;
return g1;
}
float rectangle :: getArea()
{
float g2;
g2=width * length;
cout<<"面积="<<g2;
return g2;
}
int main()
{
float l,w;
cout<<"请输入长和宽:"<<endl;
cin>>l>>w;
rectangle c(l,w);
c.getcir();
c.getArea();
cout<<endl;
system("pause");
return 0;
}
#include<iostream>
using namespace std;
class rectangle
{
public :
rectangle(){};
rectangle( float l, float w){length = l;width = w;};
~rectangle(){};
float getcir();
float getArea();
private:
static float length,width;
};
float rectangle :: length = 0;
float rectangle :: width = 0;
float rectangle :: getcir()
{
float g1;
g1=2*(width + length);
cout<<"周长="<<g1;
return g1;
}
float rectangle :: getArea()
{
float g2;
g2=width * length;
cout<<"面积="<<g2;
return g2;
}
int main()
{
float l,w;
cout<<"请输入长和宽:"<<endl;
cin>>l>>w;
rectangle c(l,w);
c.getcir();
c.getArea();
cout<<endl;
system("pause");
return 0;
}
作者: wowo55mimi 发布时间: 2011-12-08
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28