C++题目求解~~~

定义一个Point类表示平面上的一个点,再定义一个Rectangle类来表示政企矩形。在Rectangle类中包含Point类的对像,作为矩形左上角的坐标。要求为Rectangle类创建一个带参数的构造函数,并在其中对Point类的对像初始化。
定义一个Point类表示平面上的一个点,再定义一个Rectangle类来表示一个矩形。在Rectangle类中包含Point类的对像,作为矩形左上角的坐标。要求为Rectangle类创建一个带参数的构造函数,并在其中对Point类的对像初始化。

第1个回答  2011-05-04
#include<iostream>
using namespace std;
int main()
{
int i,j,n;
for(i=0;i<4;i++) //正着输出
{
for(j=3;j>i;j--)
cout<<" ";
for(n=2*i+1;n>=0;n--)
{
if(n==i) //除去对角线上的*
cout<<" ";
cout<<"*";
}
cout<<endl;
}

for(i=2;i>=0;i--) //倒着输出
{
for(j=3;j>i;j--)
cout<<" ";
for(n=2*i+1;n>=0;n--)
{
if(n==i) //除去对角线上的*
cout<<" ";
cout<<"*";
}
cout<<endl;
}
return 0;
}
另外,团IDC网上有许多产品团购,便宜有口碑
第2个回答  2011-04-28
class Point
{
public:
Point(double x=0, double y=0)
: _x(x), _y(y) {}
const double x() const {return _x;}
const double y() const {return _y;}
private:
double _x,_y;
};

class Rectangle
{
public:
Rectangle(double x=0, double y=0, double width=0, double height=0)
: _LT(x,y), _width(width), _height(height) {}
const Point LT() const {return _LT;}
const double width() const {return _width;}
const double height() const {return _height;}
private:
Point _LT;
double _width,_height;
};
第3个回答  2011-04-28
class Point
{
public:
Point(double x1=0, double y1=0)
{x=x1;y=y1;}
double getx() {return x;}
double gety() {return y;}
private:
double x,y;
};

class Rectangle
{
public:
Rectangle(double x=0, double y=0, double width=0, double height=0)
: p(x,y), width(width1), height(height1) {}
point getp(){return p;}
double getwidth(){return width;}
double getheight(){return height;}
private:
Point p ;
double width,height;
};本回答被提问者采纳
相似回答