-
Notifications
You must be signed in to change notification settings - Fork 0
/
Elevator.cpp
130 lines (124 loc) · 3.21 KB
/
Elevator.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#include "stdafx.h"
#include <iostream>
#include <cstdlib>
#include <string>
#include <fstream>
using namespace std;
const int FLOOR_MAX = 6;
const int FLOOR_MIN = 1;
const int PASS_MAX = 10;
const int PASS_MIN = 0;
const int WEIGHT_MAX = 250;
const int WEIGHT_MIN = 0;
int PASS_NUM=0;
int GOAL_FLOOR=1;
int Current_FLOOR=0;
int PASS_WEIGHT=1;
int WHOLE_WEIGHT=0;
int Get_PASSWeight();
int Get_PASSGoal();
int Get_Current_FLOOR();
int GOAL_LENGTH;
bool Calc_Values(int PASS_NUM,int PASS_WEIGHT);
//int Move(int Current_FLOR,int GOAL_FLOR[10],int GOAL_LEGNTH,int PASS_NUM);
int main()
{
cout<<"==========================================================="<<"\n";
cout<<"ELEVATOR PROJECT WITH WEIGHT LIMIT CODED BY @NICOTEENE";
cout<<"\n==========================================================="<<"\n";
int i=0;
int GOAL_FLO[10];
Current_FLOOR = Get_Current_FLOOR();
while(GOAL_FLOOR !=0 || PASS_WEIGHT !=0)
{
GOAL_FLOOR = Get_PASSGoal();
PASS_WEIGHT = Get_PASSWeight();
WHOLE_WEIGHT += PASS_WEIGHT;
PASS_NUM+=1;
GOAL_FLO[i]=GOAL_FLOOR;
i++;
//cout<<"Goal Floor is"<<GOAL_FLOOR;
}
//cout<<"\n out of while";
int GOAL_LEGNTH = i-1;
PASS_NUM --;
cout<<"\n Number OF Passengers is : "<<PASS_NUM<<"\n";
cout<<"\n Whole Weight is "<<WHOLE_WEIGHT<<"\n";
for(int i=0;i<GOAL_LEGNTH;i++) //sort
{
for(int j=0;j<GOAL_LEGNTH-1;j++)
{
if(GOAL_FLO[j+1]>GOAL_FLO[j])
{
int temp=GOAL_FLO[j];
GOAL_FLO[j]=GOAL_FLO[j+1];
GOAL_FLO[j+1]=temp;
}
}
}
bool calc = Calc_Values(PASS_NUM,WHOLE_WEIGHT);
//cout<<"\n calc is : "<<calc;
//cin.get();
if(calc==1)
{
cout<<"\n Values Before Start => CurrentFloor : "<<Current_FLOOR<<" , PASS NUMBER : "<<PASS_NUM;
{
for(int i = 0 ; i<=GOAL_LEGNTH;i++)
{
if (Current_FLOOR>GOAL_FLO[i])
{
Current_FLOOR-=1;
cout<<"\n Going Down <= Now We Are In Floor "<<Current_FLOOR<<"\n";
}
if (Current_FLOOR<GOAL_FLO[i])
{
Current_FLOOR+=1;
cout<<"\n Going Up => Now We Are In Floor "<<Current_FLOOR<<"\n";
}
if (Current_FLOOR==GOAL_FLO[i])
{
cout<<"\n Time To Get Out , Passenger!We Are arrived To Floor "<<Current_FLOOR<<"\n";
PASS_NUM-=1;
cout<<"\n Passengers Are "<<PASS_NUM<<" Persons"<<"\n";
}}}
}
cout<<"\n Its Done !!";
while(1){ }
}
int Get_Current_FLOOR()
{
cout<<" Please Enter Current Floor *NumberBelow6 : ";
cin>>Current_FLOOR;
if(Current_FLOOR>=0 && Current_FLOOR<=6)
return Current_FLOOR;
else
cout<<"\n Invalid Current Floor";
while(1){ }
};
int Get_PASSGoal()
{
cout<<" Please Enter Passenger Goal Floor *ToStopEnter0 *NumbersBelow6: ";
cin>>GOAL_FLOOR;
if(GOAL_FLOOR>0&&GOAL_FLOOR<=6)
return GOAL_FLOOR;
else
return 0;
}
int Get_PASSWeight()
{
cout<<" Please Enter Passenger Weight *ToStopEnter0 : ";
cin>>PASS_WEIGHT;
if(PASS_WEIGHT>0)
return PASS_WEIGHT;
else
return 0;
}
bool Calc_Values(int PASS_NUM,int PASS_WEIGHT)
{
if(PASS_NUM>PASS_MAX || PASS_WEIGHT>WEIGHT_MAX)
{
cout<<"\n Passenger Numbers OR Passengers Weight is Overload";
return false;
}
else
{return true;}}