UID250101性别保密经验 EP铁粒 粒回帖0主题精华在线时间 小时注册时间2022-1-27最后登录1970-1-1
|
#include<iostream>
using namespace std;
class tricycle
{
public:
int getspeed();
void setspeed();
void pedal();
void brake();
private:
int speed;
};
int tricycle::getspeed() {
return speed;
}
void tricycle::setspeed(int newspeed)
{ if (newspeed>=0)
{
speed=newspeed;
}
}
void tricycle::pedal()
{ setspeed(speed+1);
cout << "\npedaling;tricyclespeed" <<speed<< endl;
}
void tricycle::brake()
{
setspeed(speed-1);
cout << "speed" <<speed<< endl;}
int main()
{
tricycle zxc;
zxc.setspeed(0);
zxc.pedal();
zxc.pedal();
zxc.brake();
zxc.brake();
zxc.brake();
return 0;
}这代码哪有问题? |
|