第十四周上机任务---程序阅读,理解函数
2013-05-31 11:06
288 查看
/* * 程序的版权和版本声明部分 * Copyright (c)2012, 烟台大学计算机学院学生 * All rightsreserved. * 作者: 耿娜 * 完成日期: 2013年 5 月 31 日 * 版本号: 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; }
相关文章推荐
- 第十四周 程序阅读,理解虚函数与纯虚函数
- 第十四周项目6-阅读程序2(对a[i++]=的理解)
- 《第十三周任务一》写出程序的执行结果,并在上机时对照理解
- 第十四周上机实践项目1(2):阅读程序
- 将第十四周的阅读程序中的Vehicle类的定义修改为纯虚函数,找出main()函数中将使编译出错的行删除
- 2013级C++第12周程序阅读项目——理解函数
- 第十四周阅读程序(3):流成员函数put,putchar输出字符
- 第七周上机任务二--理解成员函数、友元函数和一般函数的区别 并会熟练使用它们
- 第十二周项目 1 阅读程序(理解函数的默认参数)
- 第十四周上机实践项目1(1):阅读程序
- 2013第七周上机任务【阅读程序并改错】
- 第十四周上机实践项目1(3):阅读程序
- 第十四周项目6-阅读程序1(对continue的理解)
- C02-程序设计基础提高班(C++)第10周上机任务-类和对象之二
- 第十四周阅读程序2
- 第三周上机任务--任务四--编写基于对象的程序--求三个长方柱的体积(改进版)
- 2013 第十四周上机任务 项目一 动物的叫声
- 第十四周上机任务项目3
- 第十四周上机任务(数组大折腾)!!!
- 《理解 ES6》阅读整理:函数(Functions)(六)Purpose of Functions