⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 5_17.cpp

📁 c++书籍的源代码
💻 CPP
字号:
#include <iostream.h>
 class point	//point 类的定义
{
 public:	
  point(int a=0,int b=0);//构造函数
  ~point();
  void display(void);
  void move(int x,int y);
 private:	
  int x;
  int y;
};
//成员函数的实现
 point::point(int a,int b)
{
  x=a;
  y=b;
  cout<<"x="<<x<<" 构造函数被调用"<<endl;
}
 point::~point()
{
  cout<<"x="<<x<<" 析构函数被调用"<<endl;
}
 void point::display(void)
{
  cout<<"x="<<x<<" y="<<y<<endl;
}
 void point::move(int x,int y)
{
  this->x=this->x+x;//this指针
  this->y=this->y+y;
}
//主程序
 int main()
{
  void move(point *q,int x,int y);//函数声明
  int i;
  point p[3]={point(1,1),2};	
  cout<<"第一次显示各点的坐标"<<endl;
  for(i=0;i<3;i++)
   p[i].display();//显示每一个元素的坐标
  move(p,1,1);
  cout<<"第二次显示各点的坐标"<<endl;
  for(i=0;i<3;i++)
   p[i].display();//显示每一个元素的坐标
  return(0);
}
 void move(point *q,int x,int y)//函数定义
{
  for(int i=0;i<3;i++)
   (q+i)->move(x,y);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -