第十三周项目54-交通工具类

  1. /* 
  2. *Copyright (c) 2015,烟台大学计算机学院 
  3. *All rights reserved. 
  4. *文件名称:text.cpp 
  5. *作者:李德彪
  6. *完成日期:2015年5月25日 
  7. *版本号:v1.0 
  8. * 
  9. *问题描述:  阅读程序,写出运行结果 
  10. *输入描述: 无 
  11. *程序输出:  测试结果 
  12. */  
  13. #include <iostream>  
  14.   
  15. using namespace std;  
  16. class Vehicle  
  17. {  
  18. public :  
  19.     void run()const{cout<<"run a vehicle."<<endl;}  
  20.   
  21. };  
  22. class Car:public Vehicle  
  23. {  
  24. public :  
  25.     void run()const {cout<<"run a car."<<endl;}  
  26. };  
  27. class Airplane:public Vehicle  
  28. {  
  29. public:  
  30.     void  run()const {cout<<"run a airplane."<<endl;}  
  31. };  
  32. int main()  
  33. {  
  34.     cout<<"(a) 直接用对象访问成员函数:"<<endl;  
  35.     Vehicle v;  
  36.     v.run();  
  37.     Car car;  
  38.     Airplane airplane;  
  39.     car.run();  
  40.     airplane.run();  
  41.     cout<<"(b)用指向基类的指针访问成员函数:"<<endl;  
  42.     Vehicle *vp;  
  43.     vp=&car;  
  44.     vp->run();  
  45.     vp=&airplane;  
  46.     vp->run();  
  47.     return 0;  
  48. }  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值