36 lines
640 B
C++
36 lines
640 B
C++
// 创建一个名为 Car 的类,具有成员变量 brand 和 speed,以及成员函数 void accelerate() 和 void brake() ,用于加速和刹车操作。
|
||
#include <iostream>
|
||
#include <string>
|
||
|
||
using namespace std;
|
||
|
||
class Car
|
||
{
|
||
public:
|
||
string brand;
|
||
int speed;
|
||
void accelerate()
|
||
{
|
||
this->speed += 1;
|
||
cout << "加速 1 码" << endl;
|
||
}
|
||
void brake()
|
||
{
|
||
if (this->speed > 0)
|
||
{
|
||
this->speed -= 1;
|
||
cout << "减速中" << endl;
|
||
}
|
||
else
|
||
{
|
||
cout << "车已经停下了" << endl;
|
||
}
|
||
}
|
||
};
|
||
|
||
int main()
|
||
{
|
||
|
||
return 0;
|
||
}
|