zoukankan      html  css  js  c++  java
  • 我们来造一辆车

      1: //w我们来造一辆车 
    
      2: 
    
      3: #include <iostream>
    
      4: #define FULL_GAS SS 
    
      5: using namespace std;
    
      6: class Car{
    
      7: 	public: //这里是冒号 不是分号 
    
      8: 	string color;
    
      9: 	string engime; //引擎 
    
     10: 	float gas_tank;//油的状态 
    
     11: 	unsigned int  Wheel;
    
     12: 	
    
     13: 	void fill_tank(int liter);
    
     14: 	//方法的声明:方法是‘加油’	,参数是公升
    
     15: 	void running(void); 
    
     16: 	void setColor(string col);
    
     17: 	void setEngine(string eng);
    
     18: 	void setWheel(unsigned int whe);
    
     19: 	void warning(void);
    
     20: };
    
     21: 
    
     22: void  Car::setColor(string col)
    
     23: {
    
     24: 	color = col;
    
     25: }
    
     26: void Car::setWheel(unsigned int whe)
    
     27: {
    
     28: 	wheel = whe;
    
     29: }
    
     30: 
    
     31: 
    
     32: void Car::fill_tank(float liter)
    
     33: {
    
     34: 	gas_tank + =liter;
    
     35: }
    
     36: 
    
     37: int Car::running(void)
    
     38: {
    
     39: 	cout<"我正在以120的时速往前移动,,越过拿高山"<<endl;
    
     40: 	gas_tank--;
    
     41: 	cout<<"当前还剩"<<100*gas_tank/FULL_GAS<<"%"<<"油量!\n"<<endl;	
    
     42: }
    
     43: //这辆车还是存在一些bug,你能发现并debug它吗 
    
     44: int main(int argc, char *argv[])
    
     45: {	
    
     46: 	char i;
    
     47: 	Car mycar;
    
     48: 	mycar.setColor("WHITE");
    
     49: 	mycar.setEngine("V8");
    
     50: 	mycar.setWheel(4);
    
     51:     
    
     52: 	mycar.gas_tank = FULL_GAS;
    
     53: 	
    
     54: 	while(mycar.running(void))
    
     55: 	{
    
     56: 		if(mycar.running()<10)
    
     57: 		{
    
     58: 			mycar.warning();
    
     59: 			cout<<"请问是否需要加满油在行驶?"<<endl;
    
     60: 			cin>>i;
    
     61: 			if('Y'==i || 'y'==i)
    
     62: 			{
    
     63: 			  mycar.fill_tank(FULL_GAS);	
    
     64: 			}
    
     65: 		}
    
     66: 	}	
    
     67: 	
    
     68: 	
    
     69: 	return 0;
    
     70: }

    image

  • 相关阅读:
    destoon短信接口修改方法
    关于微信公众平台模拟登录
    PHP中基本符号及使用方法
    day03-集合
    day02-字符串、字典
    day02-购物车程序练习
    day02-模块、数据类型、三元运算、列表、元组
    day01-if else、while、for、continue、break
    day01-变量、字符编码、交互输入
    通过chrome识别手机端app元素--Chrome:inspector
  • 原文地址:https://www.cnblogs.com/yoyov5123/p/2937941.html
Copyright © 2011-2022 走看看