- /*
- *Copyright (c) 2015,烟台大学计算机学院
- *All rights reserved.
- *文件名称:text.cpp
- *作者:李德彪
- *完成日期:2015年5月25日
- *版本号:v1.0
- *
- *问题描述: 阅读程序,写出运行结果
- *输入描述: 无
- *程序输出: 测试结果
- */
- #include <iostream>
- using namespace std;
- class Vehicle
- {
- public :
- void run()const{cout<<"run a vehicle."<<endl;}
- };
- class Car:public Vehicle
- {
- public :
- void run()const {cout<<"run a car."<<endl;}
- };
- class Airplane:public Vehicle
- {
- public:
- void run()const {cout<<"run a airplane."<<endl;}
- };
- int main()
- {
- cout<<"(a) 直接用对象访问成员函数:"<<endl;
- Vehicle v;
- v.run();
- Car car;
- Airplane airplane;
- car.run();
- airplane.run();
- cout<<"(b)用指向基类的指针访问成员函数:"<<endl;
- Vehicle *vp;
- vp=&car;
- vp->run();
- vp=&airplane;
- vp->run();
- return 0;
- }
第十三周项目54-交通工具类
最新推荐文章于 2023-12-02 17:32:36 发布