C++///定义一个点类(Point) .
来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/05/15 19:58:10
C++///定义一个点类(Point) .
定义一个点类(Point)、矩形类(Rectangle)和立方体类(Cube)的层次结构.矩形包括长度和宽度两个新数据成员,矩形的位置从点类继承.立方体类由长度、宽度和高度构成.要求各类提供支持初始化的构造函数和显示自己成员的函数.编写主函数,测试这个层次结构,输出立方体类的相关消息.
定义一个点类(Point)、矩形类(Rectangle)和立方体类(Cube)的层次结构.矩形包括长度和宽度两个新数据成员,矩形的位置从点类继承.立方体类由长度、宽度和高度构成.要求各类提供支持初始化的构造函数和显示自己成员的函数.编写主函数,测试这个层次结构,输出立方体类的相关消息.
#include <stdio.h>
#include <stdlib.h>
class Point
{
private:
int _x;
int _y;
public:
Point(int x,int y)
{
this->_x=x;
this->_y=y;
}
int getX()
{
return this->_x;
}
int getY()
{
return this->_y;
}
};
class Rectangle:public Point
{
private:
int _width;
int _height;
public:
Rectangle(int x,int y,int width, int height):Point(x,y)
{
this->_width=width;
this->_height=height;
}
int getWidth()
{
return this->_width;
}
int getHeight()
{
return this->_height;
}
};
class Cube
{
private:
int _width;
int _height;
int _depth;
public:
Cube(int width,int height,int depth)
{
this->_width=width;
this->_height=height;
this->_depth=depth;
}
int getWidth()
{
return this->_width;
}
int getHeight()
{
return this->_height;
}
int getDepth()
{
return this->_depth;
}
};
int main(void)
{
Point *p=new Point(1,2);
printf("the point x is %d, y is %d\n",p->getX(),p->getY());
Rectangle *r=new Rectangle(3,4,5,6);
printf("the rectangle is position is (%d,%d) and width is %d, height is %d\n",(*r).getX(),(*r).getY(),(*r).getWidth(),(*r).getHeight());
Cube c(7,8,9);
printf("the cube's width is %d, height is %d, depth is %d\n",c.getWidth(),c.getHeight(),c.getDepth());
exit(0);
}
#include <stdlib.h>
class Point
{
private:
int _x;
int _y;
public:
Point(int x,int y)
{
this->_x=x;
this->_y=y;
}
int getX()
{
return this->_x;
}
int getY()
{
return this->_y;
}
};
class Rectangle:public Point
{
private:
int _width;
int _height;
public:
Rectangle(int x,int y,int width, int height):Point(x,y)
{
this->_width=width;
this->_height=height;
}
int getWidth()
{
return this->_width;
}
int getHeight()
{
return this->_height;
}
};
class Cube
{
private:
int _width;
int _height;
int _depth;
public:
Cube(int width,int height,int depth)
{
this->_width=width;
this->_height=height;
this->_depth=depth;
}
int getWidth()
{
return this->_width;
}
int getHeight()
{
return this->_height;
}
int getDepth()
{
return this->_depth;
}
};
int main(void)
{
Point *p=new Point(1,2);
printf("the point x is %d, y is %d\n",p->getX(),p->getY());
Rectangle *r=new Rectangle(3,4,5,6);
printf("the rectangle is position is (%d,%d) and width is %d, height is %d\n",(*r).getX(),(*r).getY(),(*r).getWidth(),(*r).getHeight());
Cube c(7,8,9);
printf("the cube's width is %d, height is %d, depth is %d\n",c.getWidth(),c.getHeight(),c.getDepth());
exit(0);
}
C++///定义一个点类(Point) .
用C/C++定义一个点类Point/
求一个c语言程序设计答案 题目是“定义一个点类Point,由此派生出一个圆类”
三、 定义一个点类Point,在Main函数中建立Point对象并显示点对.如:Point#1 四、 定义一个圆类,包
JAVA 定义一个Point类 它的对象是指一个平面上的点(x,y),在定义Point类中要定义它的三个构造函数
4.可以定义点类(Point),再定义一个类(Distance)描述两点之间的距离,其数据成员为两个点类对象,两点
定义一个点类(Point),其数据成员包含横坐标和纵坐标;再定义一个距离类(Distance),用于描述两点之间
编写程序:1.定义一个Point类来处理三维点points(x,y,z
定义一个点类POINT 要求重载构造方法,并能求出两点间距离
定义一个Point类,在其中定义两个变量表示一个点的坐标值,再定义构造函数初始化为坐标原点
设计Point类用来定义平面上的一个点,在point类中定义四个方法,分别用来设置点的横坐标、纵坐标,以及返回点的横坐标
定义一个Point类并用成员函数 double Distance(const& Point)求两点间距离