?? 5_7.cpp
字號:
#include <iostream.h>
class point //point 類的定義
{
public: //外部接口
point(int a=0,int b=0);//構造函數
~point();
void display(void);
void move(int xx,int yy);
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 xx,int yy)
{
x+=xx;
y+=yy;
}
//主程序
int main()
{
int i;
point p[3]={point(1,1),2};
cout<<"第一次顯示各點的坐標"<<endl;
for(i=0;i<3;i++)
p[i].display();//顯示每一個元素的坐標
for(i=0;i<3;i++)
p[i].move(1,1);
cout<<"第二次顯示各點的坐標"<<endl;
for(i=0;i<3;i++)
p[i].display();//顯示每一個元素的坐標
return(0);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -