中易网

C++编程: 定义一个基类点,功能:获得坐标、移动、初始化坐标;怎么编程????急急急!!!!!!!

答案:2  悬赏:0  
解决时间 2021-04-27 18:07
  • 提问者网友:我稀罕你
  • 2021-04-27 09:04

编写一个程序,要求:  

•  ①定义一个基类点,功能:获得坐标、移动、初始化坐标;

•  ②定义基类的派生类长方形,除了初始化参数、获得参数功能外,还要计算其面积;

•  ③定义主函数,给长方形初始化、移动、求面积并输出其参数。

 

 

能帮我编完。另外加分!!!!

最佳答案
  • 二级知识专家网友:萝莉姐姐鹿小北
  • 2021-04-27 10:01

#include<iostream>
#include<iomanip>
using namespace std;


class  Shape
{
private:
 int x,y;
public:
 Shape(int x,int y)
 {
  this->x=x;
  this->y=y;
 }
 int GetX(){return x;}
 int GetY(){return y;}
 void Yidong(int a,int b){this->x+=a;this->y+=b;}
}
class Changfang:public Shape
{
private:
 int width,high;
public:
 Changfang(int x,int y,int width,int high):Shape(x,y)
 {
  this->width=width;
  this->high=high;
 }
 int GetW(){return width;}
 int GetH(){return high;}
 int Area(){return width*high;}
}
void mian()
{
 Changfang a(1,1,4,5);
 cout<<a.GetX()<<endl<<a.GetY()<<endl;
 a.Yidong(2,2);
 cout<<a.GetX()<<endl<<a.GetY()<<endl;
 cout<<"面积"<<a.Area();
}

全部回答
  • 1楼网友:时光不老我们不分离
  • 2021-04-27 10:51
Template is preferred for this case.
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息!
大家都在看
推荐信息