# 考试范围 程序阅读题5题 1.类的成员函数调用(*、&的意义) 2.继承(final,子类using基类) 3.多态和sTL(虚函数、override、静态成员和vector) 4.类模板(template应用、auto迭代) 5.文件写入和异常类处理异常(文件写入和输出效果相同,继承标准异常类,what函数) 编程题3题 1.类的定义(强调类的设计,包括带缺省参数的构造函数、普通成员函数和静态成员函数的使用) 2.继承和多态(设计带有虚函数的基类,设计派生类和非派生类(组合关系),重点关注虚函数的不同实现以及继承和组合关系的构造函数初始化列表) 3.运算符重载(基本二元算术运算符、<<运算符和类内[]运算符重载) # 例题 # 程序阅读题 好的,以下是一个关于类的成员函数调用以及指针和引用(*、&的意义)的程序阅读题: ## 题目1: 阅读以下C++代码,并回答问题: cpp Copy ```cpp #include using namespace std; class Example { public: int value; Example(int v) : value(v) {} void display() { cout << "Value: " << value << endl; } void setValue(int v) { value = v; } }; void modifyByPointer(Example* ex) { ex->setValue(20); } void modifyByReference(Example& ex) { ex.setValue(30); } int main() { Example ex(10); Example* exPtr = &ex; Example& exRef = ex; ex.display(); modifyByPointer(exPtr); ex.display(); modifyByReference(exRef); ex.display(); return 0; } ``` ### 问题: 1. 代码中`exPtr`和`exRef`分别是什么类型? 2. `modifyByPointer`函数和`modifyByReference`函数分别是如何修改对象`ex`的值的? 3. 程序的输出是什么? ### 解答: 1.代码中`exPtr`和`exRef`分别是什么类型? exPtr是指针类型,exRef是引用类型 2.`modifyByPointer`函数和`modifyByReference`函数分别是如何修改对象`ex`的值的? modifyByPointer:通过指针调用Example类的成员函数setValue,修改指针ex的值 modifyByReference:通过地址引用调用Example类的成员函数setValue,修改ex的值 3.程序的输出是什么? Value: 20 Value: 30 ### 解析: 1. **代码中`exPtr`和`exRef`分别是什么类型?** - 你的回答是正确的。 - `exPtr`是指向`Example`对象的指针类型,即`Example*`。 - `exRef`是`Example`对象的引用类型,即`Example&`。 2. **`modifyByPointer`函数和`modifyByReference`函数分别是如何修改对象`ex`的值的?** - 你的回答部分正确。 - `modifyByPointer`:通过指针`exPtr`调用`Example`类的成员函数`setValue`,修改对象`ex`的值。具体来说,`ex->setValue(20)`将`ex`的`value`成员变量设置为20。 - `modifyByReference`:通过引用`exRef`调用`Example`类的成员函数`setValue`,修改对象`ex`的值。具体来说,`ex.setValue(30)`将`ex`的`value`成员变量设置为30。 3. **程序的输出是什么?** - 你的回答有误。 - 程序的实际输出如下: plaintext Copy ```plaintext Value: 10 Value: 20 Value: 30 ``` - 解释: - 首先,`ex.display()`输出`Value: 10`,因为`ex`的初始值是10。 - 然后,`modifyByPointer(exPtr)`将`ex`的`value`修改为20,因此`ex.display()`输出`Value: 20`。 - 最后,`modifyByReference(exRef)`将`ex`的`value`修改为30,因此`ex.display()`输出`Value: 30`。 好的,以下是一个关于继承(包括`final`关键字和子类使用基类成员)的程序阅读题: ## 题目2: final不允许重写,override不允许继承 阅读以下C++代码,并回答问题: cpp Copy ```cpp #include using namespace std; class Base { public: virtual void show() const { cout << "Base show" << endl; } virtual void display() const final {【m cout << "Base display" << endl; } }; class Derived : public Base { public: using Base::show; // void display() const override { // 这行代码如果取消注释会发生什么? // cout << "Derived display" << endl; // } void show() const override { cout << "Derived show" << endl; } }; int main() { Base* b = new Derived(); b->show(); b->display(); delete b; return 0; } ``` ### 问题: 1. 如果取消注释`Derived`类中的`display`函数,会发生什么? 2. `using Base::show;`在`Derived`类中有什么作用? 3. 程序的输出是什么? ### 解答: 1.如果取消注释`Derived`类中的`display`函数,会发生什么? 发生编译错误,final修饰的函数不允许。 2.`using Base::show;`在`Derived`类中有什么作用? 调用base中的虚函数show 3.程序的输出是什么? "Derived show" "Base display" ### 解析: 1. **如果取消注释`Derived`类中的`display`函数,会发生什么?** - 你的回答是正确的。 - 如果取消注释`Derived`类中的`display`函数,会发生编译错误。因为基类`Base`中的`display`函数被`final`关键字修饰,表示该函数不能在派生类中被重写。 2. **`using Base::show;`在`Derived`类中有什么作用?** - 你的回答部分正确。 - `using Base::show;`在`Derived`类中声明了从基类`Base`中继承的`show`函数,使得基类的`show`函数在派生类中可见。这样,即使派生类中有同名的`show`函数,基类的`show`函数仍然可以被调用。 3. **程序的输出是什么?** - 你的回答是正确的。 - 程序的实际输出如下: plaintext Copy ```plaintext Derived show Base display ``` - 解释: - `Base* b = new Derived();`创建了一个指向`Derived`对象的`Base`类指针。 - `b->show();`调用的是`Derived`类的`show`函数,因为`show`函数是虚函数,动态绑定到`Derived`类的实现,输出`"Derived show"`。 - `b->display();`调用的是`Base`类的`display`函数,因为`display`函数被`final`修饰,不能被重写,输出`"Base display"`。 你需要继续答题还是根据前面的答题情况开始分析你的知识掌握情况? 好的,以下是一个关于多态和STL(包括虚函数、`override`关键字、静态成员和`vector`)的程序阅读题: ## 题目3: 阅读以下C++代码,并回答问题: cpp Copy ```cpp #include #include using namespace std; class Shape { public: virtual void draw() const { cout << "Drawing Shape" << endl; } virtual ~Shape() {} }; class Circle : public Shape { public: void draw() const override { cout << "Drawing Circle" << endl; } }; class Square : public Shape { public: void draw() const override { cout << "Drawing Square" << endl; } }; class ShapeManager { public: static int shapeCount; static void addShape(Shape* shape) { shapes.push_back(shape); shapeCount++; } static void drawShapes() { for (const auto& shape : shapes) { shape->draw(); } } private: static vector shapes; }; int ShapeManager::shapeCount = 0; vector ShapeManager::shapes; int main() { Shape* circle = new Circle(); Shape* square = new Square(); ShapeManager::addShape(circle); ShapeManager::addShape(square); cout << "Total shapes: " << ShapeManager::shapeCount << endl; ShapeManager::drawShapes(); delete circle; delete square; return 0; } ``` ### 问题: 1. `ShapeManager`类中的静态成员变量`shapeCount`和`shapes`的作用是什么? 2. `Shape`类中的`draw`函数为什么要声明为虚函数? 3. 程序的输出是什么? ### 解答: 1. `ShapeManager`类中的静态成员变量`shapeCount`和`shapes`的作用是什么? shapeCount:作为vector向量容器的栈顶下标,记录入栈的shape的子类个数 shapes:作为存放Shapes的容器vector,被用于存放成员函数addShape中的shape子类参数。 2. `Shape`类中的`draw`函数为什么要声明为虚函数? 便于继承Shape类的Circle和Square重写并避免重复构造调用Shape构造函数 3. 程序的输出是什么? Total shapes: 2 Drawing Circle Drawing Square ### 解析: 1. **`ShapeManager`类中的静态成员变量`shapeCount`和`shapes`的作用是什么?** - 你的回答部分正确。 - `shapeCount`:用于记录添加到`ShapeManager`中的`Shape`对象的总数。 - `shapes`:是一个`vector`容器,用于存放所有添加到`ShapeManager`中的`Shape`对象的**指针**。 2. **`Shape`类中的`draw`函数为什么要声明为虚函数?** - 你的回答部分正确。 - `draw`函数声明为**虚函数是为了实现多态性**。这样,当通过基类指针调用`draw`函数时,会根据实际对象的类型调用相应的**派生**类的`draw`函数,而不是基类的`draw`函数。这允许`Circle`和`Square`类重写`draw`函数,并在**运行时动态绑定到正确的函数实现**。 3. **程序的输出是什么?** - 你的回答是正确的。 - 程序的实际输出如下: plaintext Copy ```plaintext Total shapes: 2 Drawing Circle Drawing Square ``` - 解释: - `ShapeManager::addShape(circle);`和`ShapeManager::addShape(square);`分别将`Circle`和`Square`对象添加到`ShapeManager`的`shapes`容器中,并增加`shapeCount`。 - `cout << "Total shapes: " << ShapeManager::shapeCount << endl;`输出`Total shapes: 2`。 - `ShapeManager::drawShapes();`遍历`shapes`容器,并调用每个`Shape`对象的`draw`函数。由于`draw`是虚函数,实际调用的是`Circle`和`Square`类的`draw`函数,输出`Drawing Circle`和`Drawing Square`。 你需要继续答题还是根据前面的答题情况开始分析你的知识掌握情况? 好的,以下是一个关于类模板(包括`template`应用和`auto`迭代)的程序阅读题: ## 题目4: 阅读以下C++代码,并回答问题: cpp Copy ```cpp #include #include using namespace std; template class Container { public: void add(const T& element) { elements.push_back(element); } void display() const { for (const auto& element : elements) { cout << element << " "; } cout << endl; } private: vector elements; }; int main() { Container intContainer; intContainer.add(1); intContainer.add(2); intContainer.add(3); intContainer.display(); Container stringContainer; stringContainer.add("Hello"); stringContainer.add("World"); stringContainer.display(); return 0; } ``` ### 问题: 1. `Container`类模板的作用是什么? 2. `auto`关键字在`display`函数中的作用是什么? 3. 程序的输出是什么? ### 解答: 1. `Container`类模板的作用是什么? 简化intContainer和stringContainer的类定义过程,便于书写 2. `auto`关键字在`display`函数中的作用是什么? 自动判别接受的参数类型,使多种类型的参数都能够调用函数 3. 程序的输出是什么? 1 2 3 Hello world ### 解析: 1. **`Container`类模板的作用是什么?** - 你的回答部分正确。 - `Container`类模板的作用是**创建一个通用的容器类**,可以存储任意类型的元素。通过使用模板参数`T`,`Container`类可以在实例化时指定具体的类型,如`int`或`string`,从而避**免为每种类型编写单独的容器类**。 2. **`auto`关键字在`display`函数中的作用是什么?** - 你的回答是正确的。 - `auto`关键字在`display`函数中的作用是自动推断变量的类型。在这个例子中,`auto`用于推断`for`循环中`element`的类型,使得代码更加**简洁和通用**。无论`Container`存储的是`int`还是`string`,`auto`都会自动推断出正确的类型。 3. **程序的输出是什么?** - 你的回答是正确的。 - 程序的实际输出如下: plaintext Copy ```plaintext 1 2 3 Hello World ``` - 解释: - `intContainer.add(1);`、`intContainer.add(2);`和`intContainer.add(3);`将整数1、2和3添加到`intContainer`中。 - `intContainer.display();`输出`1 2 3`。 - `stringContainer.add("Hello");`和`stringContainer.add("World");`将字符串"Hello"和"World"添加到`stringContainer`中。 - `stringContainer.display();`输出`Hello World`。 好的,以下是一个关于文件写入和异常类处理异常(包括文件写入和输出效果相同,继承标准异常类,`what`函数)的程序阅读题: ## 题目5: 阅读以下C++代码,并回答问题: cpp Copy ```cpp #include #include #include using namespace std; class FileException : public exception { public: FileException(const char* message) : msg(message) {} virtual const char* what() const noexcept override { return msg; } private: const char* msg; }; void writeFile(const string& filename, const string& content) { ofstream outFile(filename); if (!outFile) { throw FileException("Failed to open file for writing"); } outFile << content; outFile.close(); } void readFile(const string& filename) { ifstream inFile(filename); if (!inFile) { throw FileException("Failed to open file for reading"); } string line; while (getline(inFile, line)) { cout << line << endl; } inFile.close(); } int main() { string filename = "example.txt"; string content = "Hello, World!\nThis is a test file."; try { writeFile(filename, content); readFile(filename); } catch (const FileException& e) { cerr << "FileException caught: " << e.what() << endl; } catch (const exception& e) { cerr << "Exception caught: " << e.what() << endl; } return 0; } ``` ### 问题: 1. `FileException`类的作用是什么? 2. `writeFile`函数和`readFile`函数中如何处理文件操作异常? 3. 程序的输出是什么? ### 解答: 1. `FileException`类的作用是什么? 作为异常类,传递文件报错信息,且能正确通过编译,并在调用FileException类时终止程序运行 2. `writeFile`函数和`readFile`函数中如何处理文件操作异常? 用ofstream流和ifstream流读写文件,当无法正常读写时,用throw抛出异常类FileException,停止读写 3. 程序的输出是什么? Hello, World! This is a test file. ### 解析 ### 解析: 1. **`FileException`类的作用是什么?** - 你的回答部分正确。 - `FileException`类是一个自定义异常类,继承自标准库的`exception`类。它的作用是用于传递文件操作中的错误信息。当文件操作失败时,可以抛出`FileException`异常,并通过`what`函数返回错误信息。 2. **`writeFile`函数和`readFile`函数中如何处理文件操作异常?** - 你的回答是正确的。 - 在`writeFile`函数中,使用`ofstream`流对象进行文件写操作。如果文件无法打开(即`outFile`对象的状态为false),则抛出`FileException`异常,停止写操作。 - 在`readFile`函数中,使用`ifstream`流对象进行文件读操作。如果文件无法打开(即`inFile`对象的状态为false),则抛出`FileException`异常,停止读操作。 3. **程序的输出是什么?** - 你的回答是正确的。 - 程序的实际输出如下: plaintext Copy ```plaintext Hello, World! This is a test file. ``` - 解释: - `writeFile(filename, content);`将字符串`"Hello, World!\nThis is a test file."`写入文件`example.txt`中。 - `readFile(filename);`从文件`example.txt`中读取内容并输出到控制台。 - 因此,程序输出文件中的内容,即: plaintext Copy ```plaintext Hello, World! This is a test file. ``` 你需要继续答题还是根据前面的答题情况开始分析你的知识掌握情况? # 编程题 好的,以下是一个关于类的定义(包括带缺省参数的构造函数、普通成员函数和静态成员函数的使用)的编程题: ## 题目1: 请设计一个名为`Book`的类,要求如下: 1. **成员变量**: - `string title`:书名 - `string author`:作者 - `double price`:价格 2. **构造函数**: - 带缺省参数的构造函数,默认书名为"Unknown",作者为"Unknown",价格为0.0。 3. **普通成员函数**: - `void display() const`:显示书籍信息,包括书名、作者和价格。 - `void setPrice(double newPrice)`:设置书籍价格。 4. **静态成员函数**: - `static int getBookCount()`:返回当前创建的`Book`对象的数量。 ### 要求: 1. 在`main`函数中创建多个`Book`对象,调用相关成员函数,并输出书籍信息和当前`Book`对象的数量。 ### 示例代码框架: cpp Copy ```cpp #include #include using namespace std; class Book { public: // 带缺省参数的构造函数 Book(const string& title = "Unknown", const string& author = "Unknown", double price = 0.0) : title(title), author(author), price(price) { bookCount++; } // 普通成员函数 void display() const { cout << "Title: " << title << ", Author: " << author << ", Price: $" << price << endl; } void setPrice(double newPrice) { price = newPrice; } // 静态成员函数 static int getBookCount() { return bookCount; } private: string title; string author; double price; static int bookCount; // 静态成员变量 }; // 静态成员变量初始化 int Book::bookCount = 0; int main() { // 创建Book对象 Book book1; Book book2("1984", "George Orwell", 9.99); Book book3("To Kill a Mockingbird", "Harper Lee", 12.99); // 显示书籍信息 book1.display(); book2.display(); book3.display(); // 设置并显示新的价格 book1.setPrice(5.99); book1.display(); // 输出当前Book对象的数量 cout << "Total number of books: " << Book::getBookCount() << endl; return 0; } ``` ### 问题: 1. 请补全上述代码中的`Book`类定义。 2. 请在`main`函数中创建多个`Book`对象,调用相关成员函数,并输出书籍信息和当前`Book`对象的数量。 ### 解析: 1. **补全`Book`类定义**: - 成员变量: cpp Copy ```cpp private: string title; string author; double price; static int bookCount; // 静态成员变量 ``` - 带缺省参数的构造函数: cpp Copy ```cpp public: Book(const string& title = "Unknown", const string& author = "Unknown", double price = 0.0) : title(title), author(author), price(price) { bookCount++; } ``` - 普通成员函数: cpp Copy ```cpp public: void display() const { cout << "Title: " << title << ", Author: " << author << ", Price: $" << price << endl; } void setPrice(double newPrice) { price = newPrice; } ``` - 静态成员函数: cpp Copy ```cpp public: static int getBookCount() { return bookCount; } ``` - 静态成员变量初始化: cpp Copy ```cpp int Book::bookCount = 0; ``` 1. **在`main`函数中创建多个`Book`对象,调用相关成员函数,并输出书籍信息和当前`Book`对象的数量**: - 创建`Book`对象: cpp Copy ```cpp Book book1; Book book2("1984", "George Orwell", 9.99); Book book3("To Kill a Mockingbird", "Harper Lee", 12.99); ``` - 显示书籍信息: cpp Copy ```cpp book1.display(); book2.display(); book3.display(); ``` - 设置并显示新的价格: cpp Copy ```cpp book1.setPrice(5.99); book1.display(); ``` - 输出当前`Book`对象的数量: cpp Copy ```cpp cout << "Total number of books: " << Book::getBookCount() << endl; ``` ### ## 题目2:C++ 程序设计编程题 - 继承和多态 ### 要求 设计一个简单的程序,展示继承和多态的概念。具体要求如下: 1. **基类**:设计一个带有虚函数的基类 `Shape`。 2. **派生类**:从 `Shape` 类派生两个子类 `Circle` 和 `Rectangle`,并分别实现虚函数。 3. **非派生类(组合关系)**:设计一个 `Drawing` 类,包含一个 `Shape` 对象的指针,通过构造函数将 `Shape` 的具体对象(如 `Circle` 或 `Rectangle`)传递给 `Drawing` 类。 4. **构造函数初始化列表**:在各个类中使用构造函数初始化列表。 程序需展示以下内容: - 虚函数在派生类中的不同实现。 - 构造函数初始化列表的使用。 - 多态性,即通过基类指针调用派生类的虚函数。 ### 示例代码框架 ```cpp #include #include using namespace std; // 基类 Shape class Shape { public: // 带有虚函数的基类 virtual void draw() const = 0; // 纯虚函数 virtual ~Shape() {} // 虚析构函数 }; // 派生类 Circle class Circle : public Shape { public: Circle(double radius) : radius(radius) {} void draw() const override { cout << "Drawing a circle with radius: " << radius << endl; } private: double radius; }; // 派生类 Rectangle class Rectangle : public Shape { public: Rectangle(double width, double height) : width(width), height(height) {} void draw() const override { cout << "Drawing a rectangle with width: " << width << " and height: " << height << endl; } private: double width; double height; }; // 非派生类 Drawing class Drawing { public: Drawing(Shape* shape) : shape(shape) {} void drawShape() const { shape->draw(); } ~Drawing() { delete shape; } private: Shape* shape; }; int main() { // 创建 Circle 对象 Shape* circle = new Circle(5.0); // 创建 Drawing 对象并传递 Circle 对象 Drawing drawing1(circle); drawing1.drawShape(); // 输出:Drawing a circle with radius: 5.0 // 创建 Rectangle 对象 Shape* rectangle = new Rectangle(4.0, 6.0); // 创建 Drawing 对象并传递 Rectangle 对象 Drawing drawing2(rectangle); drawing2.drawShape(); // 输出:Drawing a rectangle with width: 4.0 and height: 6.0 return 0; } ``` ### 问题: 1. 请补全上述代码中的 `Shape`、`Circle`、`Rectangle` 和 `Drawing` 类定义。 2. 请在 `main` 函数中创建多个 `Shape` 对象,调用相关成员函数,并输出绘制的形状信息。 ### 解析: 1. **基类 Shape**: - `draw()` 是一个纯虚函数,这使得 `Shape` 类成为抽象基类,无法直接实例化。 - 虚析构函数确保在删除指向派生类对象的基类指针时,会正确调用派生类的析构函数。 2. **派生类 Circle 和 Rectangle**: - 这两个类分别从 `Shape` 类派生,并实现 `draw()` 函数。 - 使用构造函数初始化列表初始化成员变量 `radius`、`width` 和 `height`。 3. **非派生类 Drawing**: - `Drawing` 类包含一个指向 `Shape` 对象的指针。 - 在构造函数中,通过初始化列表将 `Shape` 指针传递给 `Drawing` 类。 - `drawShape()` 方法调用 `Shape` 对象的 `draw()` 方法,实现多态。 4. **main 函数**: - 创建 `Circle` 和 `Rectangle` 对象,并将它们的指针传递给 `Drawing` 类。 - 调用 `Drawing` 对象的 `drawShape()` 方法,展示多态性。 ## 题目3:C++ 程序设计编程题 - 运算符重载 设计一个简单的程序,展示运算符重载的概念。具体要求如下: 1. **类**:设计一个名为 `Vector` 的类,用于表示二维向量。 2. **成员变量**: - `double x`:表示向量的 x 坐标 - `double y`:表示向量的 y 坐标 3. **构造函数**: - 默认构造函数,初始化向量为 (0, 0)。 - 带参数的构造函数,初始化向量为给定的 x 和 y 坐标。 4. **运算符重载**: - 重载加法运算符 `+`,用于实现两个向量的加法。 - 重载减法运算符 `-`,用于实现两个向量的减法。 - 重载乘法运算符 `*`,用于实现向量与标量的乘法。 - 重载插入运算符 `<<`,用于输出向量的信息。 - 重载下标运算符 `[]`,用于访问向量的 x 或 y 坐标。 5. **普通成员函数**: - `void display() const`:显示向量的信息。 #### 示例代码框架: ```cpp #include using namespace std; class Vector { public: // 默认构造函数 Vector() : x(0), y(0) {} // 带参数的构造函数 Vector(double x, double y) : x(x), y(y) {} // 重载加法运算符 Vector operator+(const Vector& other) const { return Vector(x + other.x, y + other.y); } // 重载减法运算符 Vector operator-(const Vector& other) const { return Vector(x - other.x, y - other.y); } // 重载乘法运算符 Vector operator*(double scalar) const { return Vector(x * scalar, y * scalar); } // 重载插入运算符 friend ostream& operator<<(ostream& os, const Vector& vec) { os << "Vector(" << vec.x << ", " << vec.y << ")"; return os; } // 重载下标运算符 double& operator[](int index) { if (index == 0) return x; if (index == 1) return y; throw out_of_range("Index out of range"); } // 显示向量信息 void display() const { cout << "Vector(" << x << ", " << y << ")" << endl; } private: double x, y; }; int main() { // 创建 Vector 对象 Vector v1(3.0, 4.0); Vector v2(1.0, 2.0); // 显示向量信息 cout << "v1: " << v1 << endl; cout << "v2: " << v2 << endl; // 向量加法 Vector v3 = v1 + v2; cout << "v1 + v2: " << v3 << endl; // 向量减法 Vector v4 = v1 - v2; cout << "v1 - v2: " << v4 << endl; // 向量与标量乘法 Vector v5 = v1 * 2.0; cout << "v1 * 2.0: " << v5 << endl; // 使用下标运算符 cout << "v1[0]: " << v1[0] << endl; cout << "v1[1]: " << v1[1] << endl; // 显示所有向量信息 v1.display(); v2.display(); v3.display(); v4.display(); v5.display(); return 0; } ``` ### 问题: 1. 请补全上述代码中的 `Vector` 类定义。 2. 请在 `main` 函数中创建多个 `Vector` 对象,调用相关成员函数,并输出向量信息。 ### 解析: 1. **类 Vector**: - 包含两个成员变量 `x` 和 `y`,分别表示向量的 x 和 y 坐标。 - 默认构造函数和带参数的构造函数用于初始化向量。 - 重载加法运算符 `+` 实现两个向量的加法。 - 重载减法运算符 `-` 实现两个向量的减法。 - 重载乘法运算符 `*` 实现向量与标量的乘法。 - 重载插入运算符 `<<` 用于输出向量信息。 - 重载下标运算符 `[]` 用于访问向量的 x 或 y 坐标。 - `display()` 成员函数用于显示向量信息。 2. **main 函数**: - 创建多个 `Vector` 对象,并使用运算符重载进行向量加法、减法和标量乘法。 - 使用重载的插入运算符 `<<` 输出向量信息。 - 使用重载的下标运算符 `[]` 访问和输出向量的成员变量。 - 调用 `display()` 成员函数显示向量信息。