您的位置:首页 > 汽车 > 时评 > 小程序模板指令_建立网站第一步_一个具体网站的seo优化方案_莆田百度推广开户

小程序模板指令_建立网站第一步_一个具体网站的seo优化方案_莆田百度推广开户

2025/1/7 11:50:15 来源:https://blog.csdn.net/A_New_World/article/details/144869352  浏览:    关键词:小程序模板指令_建立网站第一步_一个具体网站的seo优化方案_莆田百度推广开户
小程序模板指令_建立网站第一步_一个具体网站的seo优化方案_莆田百度推广开户

// 发动机类
class Engine {
public:void start() {std::cout << "Engine started." << std::endl;}
};
// 身份证类
class IDCard {
public:std::string idNumber;
};
// 抽象类车
class Vehicle {
public:virtual void drive() = 0;  // 纯虚函数,使类成为抽象类
};
// 小汽车类,实现车类
class SmallCar : public Vehicle {
private:Engine engine;public:void drive() override {engine.start();std::cout << "Small car is driving." << std::endl;}
};
// SUV类,继承小汽车类
class SUV : public SmallCar {
public:void drive() override {std::cout << "SUV is driving to the mountains." << std::endl;}
};
// 自行车类,实现车类
class Bicycle : public Vehicle {
public:void drive() override {std::cout << "Bicycle is riding." << std::endl;}
};
// 班级类
class Class {
private:std::vector<Student*> students;  // 聚合学生类public:void addStudent(Student* student) {students.push_back(student);}
};
// 学生类
class Student {
private:IDCard idCard;Class* classObj;  // 聚合班级类public:Student(Class* class_) : classObj(class_) {}void goToSchool(Bicycle* bicycle) {  // 依赖自行车类std::cout << "Student is going to school by bicycle." << std::endl;bicycle->drive();}
};

完整代码
 

#include <iostream>
#include <vector>// 发动机类
class Engine {
public:void start() {std::cout << "Engine started." << std::endl;}
};// 身份证类
class IDCard {
public:std::string idNumber;
};// 抽象类车
class Vehicle {
public:virtual void drive() = 0;  // 纯虚函数,使类成为抽象类
};// 小汽车类,实现车类
class SmallCar : public Vehicle {
private:Engine engine;public:void drive() override {engine.start();std::cout << "Small car is driving." << std::endl;}
};// SUV类,继承小汽车类
class SUV : public SmallCar {
public:void drive() override {std::cout << "SUV is driving to the mountains." << std::endl;}
};// 自行车类,实现车类
class Bicycle : public Vehicle {
public:void drive() override {std::cout << "Bicycle is riding." << std::endl;}
};// 班级类
class Class {
private:std::vector<Student*> students;  // 聚合学生类public:void addStudent(Student* student) {students.push_back(student);}
};// 学生类
class Student {
private:IDCard idCard;Class* classObj;  // 聚合班级类public:Student(Class* class_) : classObj(class_) {}void goToSchool(Bicycle* bicycle) {  // 依赖自行车类std::cout << "Student is going to school by bicycle." << std::endl;bicycle->drive();}
};int main() {// 创建班级对象Class schoolClass;// 创建学生对象并关联班级Student student1(&schoolClass);// 创建自行车对象Bicycle bicycle;// 学生骑自行车上学student1.goToSchool(&bicycle);// 创建小汽车对象并驾驶SmallCar smallCar;smallCar.drive();// 创建 SUV 对象并驾驶SUV suv;suv.drive();return 0;
}

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com