First, the topic requirements:
1, can get elevators and passengers on the floor;
2, according to the needs of passengers to reach the floor you want to arrive.
Second, design ideas:
1, through the user input can get passengers and elevators on the floor;
2, through the loop, the output elevator up/down the process of walking.
Third, the source code:
1 //Elevator Dispatching--Huia Bao2 //3 4#include"stdafx.h"5#include <iostream>6 using namespacestd;7 8 9 int_tmain ()Ten { One inta,b,c,m,i; Acout<<"*************************** Elevator Operation simulation System *******************************"<<Endl; -cout<<"Please enter the floor of the elevator:"; -Cin>>A; thecout<<Endl; -cout<<"Please enter your passenger floor:"; -Cin>>b; -cout<<Endl; + if(b>=2&&b<8) - { +cout<<"I'm sorry. Elevator 2-7 Floor Stop! "<<Endl; Acout<<"Please re-enter your passenger floor:"; atCin>>b; -cout<<Endl; - } -cout<<"Please select the direction of passenger ride:"<<Endl; -cout<<"upstream (1)"<<Endl; -cout<<"downlink (0)"<<Endl; inCin>>C; - if(c==1) to { + if(a<b) - { the for(i=a+1; i<=b;i++) * { $cout<<"the elevator is going up to the first"<<i<<"Storey Floor"<<Endl;Panax Notoginseng - } the } + Else A { the for(i=b-1; i>=a;i--) + { -cout<<"the elevator is descending to the first"<<i<<"Storey Floor"<<Endl; $ } $ } -cout<<'\a'<<"the elevator has reached the first"<<b<<"Floor, please enter the elevator. "<<endl;//' \a ' output a sound -cout<<"Please select the floor you want to go to:"; theCin>>m; - for(i=b+1; i<=m;i++)Wuyi { thecout<<"the elevator is going up to the first"<<i<<"Storey Floor"<<Endl; - } Wucout<<'\a'<<"Section"<<m<<"The floor is here!"<<Endl; - } About Else $ { - if(a<b) - { - for(i=a+1; i<=b;i++) A { +cout<<"the elevator is going up to the first"<<i<<"Storey Floor"<<Endl; the } - } $ Else the { the for(i=a-1; i>=b;i--) the { thecout<<"the elevator is descending to the first"<<i<<"Storey Floor"<<Endl; - } in } thecout<<'\a'<<"the elevator has reached the first"<<b<<"Floor, please enter the elevator. "<<Endl; thecout<<"Please select the floor you want to go to:"; AboutCin>>m; the if(m>1&&m<8) the { thecout<<"I'm sorry. The elevator is not on the 2-7 floor! "<<Endl; +cout<<"please go downstairs in 8, walk the stairs!"<<Endl; - for(i=b;i>=8; i--) the {Bayicout<<"the elevator is descending to the first"<<i<<"Storey Floor"<<Endl; the } thecout<<'\a'<<"Section"<<8<<"The floor has arrived, please take the stairs, thank you!"<<Endl; - } - Else the { the for(i=b;i>=m;i--) the { thecout<<"the elevator is descending to the first"<<i<<"Storey Floor"<<Endl; - } thecout<<'\a'<<"Section"<<m<<"The floor is here!"<<Endl; the } the }94 return 0; the}
Iv. Results of Operation:
Five, Experience:
This task is much later than the requested time, then thought of the problem, but there is no train of thought, think too much, want to achieve too many things. This time just to achieve a number of access to the floor, to achieve the process of elevator walk, the output to reach the elevator these functions.
This practice has a lot of feelings, seriously clear ideas, you can solve the problem.
Software Engineering class Assignment (vii) Continuation--overall design of elevator dispatching