没有一点点防备,专业老师来了一次突击期中考试,题目倒是不难,可做的时候总是有点紧张,以至于刚写完红线不少,不过还好,完美通关,特在此贴上代码,请各位大神帮助指出不足之处,给小白指点指点,再次感谢(小白代码,可笑之处轻喷)。
题目:
定义一个父类Vehicle,包含一个私有变量name,一个函数run();
定义两个子类Car,Plane,各包含一个私有变量move(运行方式);
输出结果:Car is running through the wheel.
Plane is running through the wings.
(1).首先定义类文件和头文件
(2).Vehicle头文件代码
#pragma once
#include <iostream>
#include <string>
using namespace std;
class Vehicle {
private:
string name;
public:
Vehicle(string name);//含参数构造函数
~Vehicle();
public:
void set_name(string name);
string get_name();
public: