{:10_254:}有没有什么途径可以补上啊 小甲鱼分享的代码好多bug!!!
#include <iostream>
#include <Windows.h>
#define FULL_GAS 85
class Car
{
public:
std::string color;
std::string engine;
unsigned int gas_tank;
unsigned int wheel;
void setColor(std::string col);
void setEngine(std::string eng);
void setWheel(unsigned int whe);
void fill_tank(int liter);
int running(void);
void warning(void);
};
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(int liter)
{
gas_tank += liter;
}
int Car::running(void)
{
std::cout << "Speed = 120\n";
gas_tank--;
std::cout << "Gas remaining " << 100 * gas_tank / FULL_GAS << "%" << "\n";
return gas_tank;
}
void Car::warning(void)
{
std::cout << "WARNING!!" << " Gas remaining " << 100 * gas_tank / FULL_GAS << "%!! \n";
}
int main()
{
char i;
Car mycar;
mycar.setColor("WHITE");
mycar.setEngine("V8");
mycar.setWheel(4);
mycar.gas_tank = FULL_GAS;
unsigned int gas_tank;
while (gas_tank = mycar.running())
{
if (gas_tank <= 0)
{
std::cout << "The fuel has run out! The car stops!!\n";
break;
}
if (gas_tank < 10)
{
mycar.warning();
std::cout << "Do you need to fill the fuel? (Y/N)\n";
std::cin >> i;
if ('Y'==i || 'y'==i)
{
mycar.fill_tank(FULL_GAS - gas_tank);
}
}
}
return 0;
}
页:
1
[2]