qfedu-cpp-level/day2/homework/h7.cpp

36 lines
640 B
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// 创建一个名为 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;
}