本实验报告为天津理工大学C++课程设计,包含多个基础与进阶实验的详细记录及源代码,旨在帮助学生深入理解C++编程语言的应用和实践。
1)输入下列程序,按要求进行实验,并记录实验的结果。
```cpp
#include
using namespace std;
class Coordinate {
public:
Coordinate(int x1, int y1) {
x = x1;
y = y1;
cout << Constructor is called. << endl;
}
Coordinate(Coordinate &p);
~Coordinate() {
cout << Destructor is called. << endl;
}
int getx() {
return x;
}
int gety() {
return y;
}
private:
int x, y;
};
Coordinate::Coordinate(Coordinate &p) {
x = p.x;
y = p.y;
cout << Copy initianization constructor is called. << endl;
}
int main() {
Coordinate p1(3, 4);
Coordinate p2(p1); // 原代码中似乎有一个拼写错误,这里可能是想定义一个名为Coordinate的类对象p2并使用p1进行初始化。
}
```