Elevator Dispatch Program

Source: Internet
Author: User

Description

This is a pair programming project, in fact, the first contact. Before all is oneself a person to write, want to realize what function to write what. But this time it touches the pair programming and discovers the importance of discussing with others. Two people to discuss, analyze user needs, improve the function. And two people can not discuss the same as a person looking for a bug when the anxiety, worry. At the same time, it is also the most important, the method of pairing programming will greatly improve the quality of the program.

First, the topic requirements:

Existing new office building, a total of 21 floors, a total of four elevators, all elevators basic parameters are shown in the following table:

Elevator number

Service Floors available

Maximum number of passengers

Maximum Load weight

1

All floors

10

Approx.

2

Single layer

10

Approx.

3

Double

20

Approx.

4

All floors

20

Kg

The terms of use are as follows:

1, the floor number is 0~20, of which No. 0 is the basement layer;

2. Elevators with floor restrictions are not docked in the response floor, such as a single double layer;

3, all elevators with unified button control

Please design and implement an elevator control program according to the above requirements, if there is a graphical display is better.

Second, demand analysis:

1, a total of 4 elevators, a single double-decker docking and all floors are docked.

2, the user in any layer request, distance from the nearest elevator to respond to passenger requirements.

3, at any time to show the status of each elevator and the number of layers.

4, judge the number of elevators, to prevent overweight. Elevator If overweight does not accept external requests, only accept elevator internal request.

Third, the function realization:

1, elevator data structure:

Each of these data roles is described in the comments

struct Elevator
{
int maxpeople;//lift Maximum load weight
int nowpeople;//Elevator currently loads 4 people
int iffloor;//is overloaded (full 1, under 0)
int servefloor;//Elevator Service Floor (all 3, single layer 1, double layer 0)
int outpeople[21];//The external person presses the elevator to request the floor (the array subscript represents the floor, and the numeric value indicates whether it is docked.) Stop 1, do not stop-1)
int inpeople[21];//Elevator Interior People press elevator request floor
int staut;//rise 1, drop-1, stop 0
int floor;//Elevator Current Floor
};

2. Initialization function

4 elevators are not in service at first. That is, outpeople[21]={-1}, inpeople[21]={-1}, the initial number of elevators in the nowpeople=0, according to the capacity of each elevator and the service floor and then respectively assigned value. Each elevator starting floor is different, consider the user request to be timely corresponding as far as possible to wait for less time considerations, the first elevator in 20, second in 9, third in 10, fourth in 1.

void Iint ()//each elevator initialization {for (int i=0; i < 4; i++) {for (int j = 0; J <; J + +) {A[i].inpeople[j] = -1;a[i].outpeople[j] =-1;} a[i].nowpeople = 0;a[i].iffloor = 0;} A[0].maxpeople = 10;a[0].servefloor = 3;a[0].staut = 0;a[0].floor = 20;a[1].maxpeople = 10;a[1].servefloor = 1;a[1].staut = 0;a[1].floor = 9;a[2].maxpeople = 20;a[2].servefloor = 0;a[2].staut = 0;a[2].floor = 10;a[3].maxpeople = 20;a[3].serveFl Oor = 3;a[3].staut = 0;a[3].floor = 1;}

Elevator Dispatch Program

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.