📄 电梯控制.cpp
字号:
#include"iostream.h"
const int maxfloor=15;
class elevator
{
private:
int currentfloor;
public:
elevator(int=1);
void request(int);
};
elevator::elevator(int cfloor)
{
currentfloor=cfloor;
}
void elevator::request(int newfloor)
{
if(newfloor<1||newfloor>maxfloor||newfloor==currentfloor);
else if(newfloor>currentfloor)
{
cout<<"\nstarting at floor"<<currentfloor<<endl;
while(newfloor>currentfloor)
{
currentfloor++;
cout<<"Going up-now at floor"<<currentfloor<<endl;
}
cout<<"Stopping at floor"<<currentfloor<<endl;
}
else
{
cout<<"\nStarting at floor"<<currentfloor<<endl;
while(newfloor<currentfloor)
{
currentfloor--;
cout<<"Going down-now at floor"<<currentfloor<<endl;
}
cout<<"stopping at floor"<<currentfloor<<endl;
}
return;
}
int main()
{
int aimfloor;
char ans='y';
elevator a;
while(ans!='n')
{
cout<<"你想去几楼?请输入楼层(1-15)";
cin>>aimfloor;
a.request(aimfloor);
cout<<"你继续吗?(y or n)"<<endl;
cin>>ans;
}
cout<<"谢谢使用!";
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -