实验 1 类和对象 1.1实验目的和要求 (1) 理解类和对象的概念,掌握声明类和定义对象的方法。 (2) 掌握构造函数和析构函数的实现方法。 (3) 初步掌握使用类和对象编制C++程序。 (4) 掌握对象数组、对象指针和string 类的使用方法。 (5) 掌握使用对象、对象指针和对象引用作为函数参数的方法。 (6) 掌握类对象作为成员的使用方法。 (7) 掌握静态数据成员和静态成员函数的使用方法。 (8) 理解友元的概念和掌握友元的使用方法。 1.2实验内容和步骤 1. 输入下列程序 //test4-1.cpp #include
using namespace std; class Coordinate { public: Coordinate(int x1,int y1) { x=x1; y=y1; } Coordinate(Coordinate &p); ~Coordinate() { cout<<”Destructor is calleded\n”;} int getx() {return x;} int gety() {return y;} private: int x,y; }; Coordinate::Coordinate(Coordinate &p) { x=p.x; y=p.y; cout<<”copy-initialization Constructou is called\n”; } int main() { Coordinate p1(3,4); Coordinate p2(p1); Coordinate p3=p2; cout<<” p3=(“ <