编写一个程序,要求:
• ①定义一个基类点,功能:获得坐标、移动、初始化坐标;
• ②定义基类的派生类长方形,除了初始化参数、获得参数功能外,还要计算其面积;
• ③定义主函数,给长方形初始化、移动、求面积并输出其参数。
能帮我编完。另外加分!!!!
编写一个程序,要求:
• ①定义一个基类点,功能:获得坐标、移动、初始化坐标;
• ②定义基类的派生类长方形,除了初始化参数、获得参数功能外,还要计算其面积;
• ③定义主函数,给长方形初始化、移动、求面积并输出其参数。
能帮我编完。另外加分!!!!
#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();
}