
急求!!!一道C++题目
设计一个程序;声明一个Rectangle类,有数据成员length(长),width(宽),成员函数GetArea(),计算矩形的面积,在函数内输入矩形的长和宽,构造一个...
设计一个程序;声明一个Rectangle类, 有数据成员length(长),width(宽),成员函数GetArea(),计算矩形的面积,在函数内输入矩形的长和宽,构造一个Rectanglede 对象,并初始化该对象的长,宽值,通过该对象的成员函数GetArea()求出相应的面积。
展开
4个回答
展开全部
#include<iostream.h>
class Rectangle
{
public:
Rectangle(int x,int y)
{
length=x;
width=y;
}
~Rectangle(){}
int GetArea()
{
return length*width;
}
private:
int length,width;
};
void main()
{
int l,w,a;
cout<<"please input the length and the width:"<<endl;
cin>>l>>w;
Rectangle shape(l,w);
cout<<"the area of the shap is :"<<endl;
a=shape.GetArea();
cout<<a<<endl;
}
class Rectangle
{
public:
Rectangle(int x,int y)
{
length=x;
width=y;
}
~Rectangle(){}
int GetArea()
{
return length*width;
}
private:
int length,width;
};
void main()
{
int l,w,a;
cout<<"please input the length and the width:"<<endl;
cin>>l>>w;
Rectangle shape(l,w);
cout<<"the area of the shap is :"<<endl;
a=shape.GetArea();
cout<<a<<endl;
}
展开全部
#include "stdafx.h"
#include <iostream>
using namespace std;
class Rectangle {
protected : double m_length;
double m_width;
public:
Rectangle(){};
Rectangle(double len,double wid){
this->m_length = len;
this->m_width = wid;
}
double getArea() {
return m_length*m_width;
}
};
void main() {
Rectangle rect(30.5,20.7);
cout<<"面积:"<<rect.getArea()<<endl;
}
按照你的要求最简单的,想复杂点可以自己再加,比如输入长宽之类的。
#include <iostream>
using namespace std;
class Rectangle {
protected : double m_length;
double m_width;
public:
Rectangle(){};
Rectangle(double len,double wid){
this->m_length = len;
this->m_width = wid;
}
double getArea() {
return m_length*m_width;
}
};
void main() {
Rectangle rect(30.5,20.7);
cout<<"面积:"<<rect.getArea()<<endl;
}
按照你的要求最简单的,想复杂点可以自己再加,比如输入长宽之类的。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#includ<iostream.h>
class Rectangle{
float length,width
Public:
Rectangle(){return 0;}
Rectangle(x,y){x=length;y=width;}
GetArea()
}
Class::GetArea()
{renturn x*y;}
void mian()
{
Rectangle Rectanglede;
cin>>X>>y;
Rectanglede.GetArea(x,y);
cout<<"Area="<<GetArea()<<endl;
}
不好意思我学习的很有限 不知道对不对,假如不对请原谅我
class Rectangle{
float length,width
Public:
Rectangle(){return 0;}
Rectangle(x,y){x=length;y=width;}
GetArea()
}
Class::GetArea()
{renturn x*y;}
void mian()
{
Rectangle Rectanglede;
cin>>X>>y;
Rectanglede.GetArea(x,y);
cout<<"Area="<<GetArea()<<endl;
}
不好意思我学习的很有限 不知道对不对,假如不对请原谅我
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询