prog4.cpp
来自「C++语言程序设计题典」· C++ 代码 · 共 29 行
CPP
29 行
#include <iostream.h>
class Sample
{
int x,y;
public:
Sample() { x=y=0; }
Sample(int i,int j) { x=i;y=j; }
void copy(Sample &s);
void setxy(int i,int j) { x=i;y=j; }
void print() { cout << "x=" << x << ",y=" << y << endl; }
};
void Sample::copy(Sample &s)
{
x=s.x;y=s.y;
}
void func(Sample s1,Sample &s2)
{
s1.setxy(10,20);
s2.setxy(30,40);
}
void main()
{
Sample p(1,2),q;
q.copy(p);
func(p,q);
p.print();
q.print();
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?