Pair programming-Elevator scheduling

Source: Internet
Author: User

Elevator Dispatch

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 procedure according to the above requirements.

Procedural ideas and Solutions

1. Floor Problems and Solutions: first define a structure, the elevator properties are defined in a structure so that later want to use the elevator properties, it is easily used in the structure of the body. After that the floor is considered. If you come up with 3 different buttons, I'm going to start by judging which one recently and then starting to run the elevator. So, the floor of this aspect I used the list to complete, with the list of benefits is that

Arrays are stored one by one in memory, that is, if the first element of the array is at address A, the second element of the array is at address a+1.

And the list is not, the list of each node does not have a relatively fixed position relationship. A node after address A is not necessarily a+1, but in other idle areas of memory, it presents a random state.

Once an array is explicitly declared, its size is fixed and cannot be expanded dynamically. The linked list can, however, dynamically generate nodes and add them to the existing list. This solves the problem of the elevator floor. The following are code and

struct elevator*create (struct elevator*head)//Create linked list
{
struct ELEVATOR*P1, *p2;
p1=p2= (struct elevator*) malloc (sizeof (struct elevator));
printf ("\t\t Please input floor * Enter continue input * Press-1 to end");
scanf ("%d", &p1->floor);
P1->pnext = NULL;
while (P1->floor >-1)
{
if (head== NULL)
head = p1;
Else
P2->pnext = p1;
P2 = p1;
P1 = (struct elevator*) malloc (sizeof (struct elevator));
printf ("\t\t Please enter floor, press-1 to end");
scanf ("%d", &p1->floor);
}
Free (p1); The application is not entered, so release
P1 = NULL; Make point to Empty
P2->pnext = NULL; To the end of the table, pointing to the empty
printf ("\t\t floor input end (end) \ n");
return head;
}

2. What needs to be resolved is that the lift is overloaded. The problem is relatively simple. The number of load required in the title, I to facilitate the 65kg per person to calculate the weight, so, in the program to add an if judgment on the way to the execution of the program code and the following

int Elevatorone ()//Elevator function
{
int a = 0;
struct elevator elevator1;
printf ("\t\t\t Welcome to use a lift system \ n");
printf ("\ t Please enter an elevator system using one * * If you want to exit the elevator system please press");
while (a=1)
{
scanf_s ("%d", &a);
if (a = = 1)
{
printf ("\t\t\t Please enter the number of people;");
scanf_s ("%d", &elevator1.outnumber);
if (Elevator1.outnumber > | | Elevator1.outnumber < 1)
{
printf ("\t\t elevator maximum capacity of 12 people, please understand \ \");

}
Else
{
printf ("\t\t tip * * Elevator provides 1-21-layer service **\n");
struct elevator *head;
head = NULL;
Head = Create (head);
printf (head);
printf ("\t\t if continue press 1 otherwise please press 0");
}
}
Else
Break
}
printf ("\t\t thanks to the use of a lift system");
printf ("\t\t if continue press 1 otherwise please press 0");
return 0;
}

3. Then the question requires 2nd and 3rd elevators are single-storey and double-deck elevators, so the elevator operation needs to determine whether the input is correct. The following are code and

void Printff (struct elevator*head)//Elevator third output function to determine whether the input is double-decker
{

struct elevator *three;
three = head;
printf ("\t\t elevator starts to run \ n");
while (three->floor%2==0)
{
Sleep (N);
printf ("\a");
printf ("\t\t arrives at the floor you entered%30d floor \ n", Three->floor);
printf ("If there is a request * Please press 1 otherwise please press 0");
int a = 0;
scanf_s ("%d", &a);
if (a = = 1)
{
Break
}
Else
{
printf ("\ n");
three = three->pnext;
}
}
printf ("\t\t you entered the wrong third elevator only provides double-decker services \ n");

4. If there is a person on the 1 floor to the 5 floor but on the way on the 3 floor someone to use the elevator? This problem I used a more stupid way is that elevator every floor I have a hint whether there is a request, if there is a request can be used halfway through the elevator, it is possible to enter the elevator system on the 3 floor. If not, continue to rise to the 5 floor. The code is as follows.

Photo with a small partner:

* My thoughts on this pair of programming *

At first, the teacher said that the homework to be a pair of programming, I refused, from the beginning of the start of the code is a person to write their own, suddenly let other people with the photo is a bit uncomfortable. At first we were not very good at what we thought. However, with the passage of time, slowly the outline of the program came out, we have more than two exchanges up. Give me the greatest feeling is that a person to write code found less than a few, two people can write from a broader view of the program, so that the program can be better accepted by most people, I think this is the teacher let us do team work. After all, people are social animals (although we are the program Ape ~ ~). Also, because we both limited strength on this programming is not very satisfied, did not make graphics out (mainly on the graphics of the ignorant AH ~ ~ ~ ~ ~ ~) ..... And there's no way to get four elevators running at the same time. Hope later through their own efforts to learn to make up for the lack of a better procedure.

Pair programming-Elevator scheduling

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.