c++构造函数
来源:互联网 发布:html5动画制作软件 编辑:程序博客网 时间:2024/06/03 16:56
// ConsoleApplication5.cpp : 定义控制台应用程序的入口点。//// ConsoleApplication6.cpp : 定义控制台应用程序的入口点。//#include "stdafx.h"#include<iostream>#include<string>#define full_tank 85class Car{public:std::string color;std::string engine;unsigned int gas;unsigned int wheel; void setColor (std::string col);void setengine(std::string eng);void setwheel(unsigned int whe);void fill_tank(float liter);int runing(void);void warning(void);};void Car::Car(void){color = "while";engine = "v8";wheel = 4;gas = full_tank; //构造函数必须要与类名一致,就是对类的属性进行初始化。}void Car::setColor(std::string col){color = col;}void Car::setengine(std::string eng){engine = eng;}void Car::setwheel(unsigned int whe){wheel = whe;}void Car::fill_tank(float liter){gas+ = liter;}int Car::runing(void){char = i;std::cout << "我正在以1200000的时速往前移动。。。。你妹。。。\n";gas--;std::cout << "当前还剩" << 100 * gas / full_tank << "%" << "油量";if (gas < 10){std::cout << "请问要不要再来一瓶?(Y/N)";std::cin >> i;if ('Y' == i || 'y' == i){fill_tank(full_tank);}if (0 == gas){std::cout << "抛瞄了。。。。";return 1;}}return 0;}void Car::warning(void){std::cout << "WARNING!!" << "还剩" << 100 * gas / full_tank << "%" << "油量";}int main(){Car mycar;while (!mycar.runing()){;}return 0;}
阅读全文
0 0
- 【C++】拷贝构造函数
- C#:静态构造函数
- C++:拷贝构造函数
- explicit构造函数(C++)
- C++:关于构造函数
- C++-构造函数
- C++String构造函数
- c++-转换构造函数
- c++"拷贝构造函数
- C++: 拷贝构造函数
- object-c 构造函数
- C#构造函数
- objective-c 构造函数
- 【C++】构造函数
- 【C++】explicit构造函数
- 【C++】拷贝构造函数
- C++: 复制构造函数
- C++: 移动构造函数
- Linux下修改文件产生.swap文件错误
- python 列表操作
- Android第三方分享和登录之微信及QQ篇
- 商品列表
- javascript中boolean类型
- c++构造函数
- linux java 安装(升级)
- 梯度下降法、牛顿法、拟牛顿法、共轭梯度
- 计算机的原码,反码与补码
- springboot(十一):Spring boot中mongodb的使用
- Date和Calendar类的使用方法(二)
- checkbox全选
- pta_链表_递增的整数序列链表的插入_(插入创建操作)
- Python的namedtuple使用详解