Форум программистов, компьютерный форум CyberForum.ru

Исправить код - C++

Восстановить пароль Регистрация
 
Novichok_K_Z
0 / 0 / 0
Регистрация: 24.12.2013
Сообщений: 11
28.05.2014, 12:39     Исправить код #1
C++
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
//#include<iostream.h>
#include"time.h"
#include<string>
using namespace std;
const double price=0.0025;
const int N=3;
const int OK=1;
const int ERROR=0;
static int empty=N;
static int EMPTYQUEE=0;
typedef struct Car
{
    char num[5];
    time_t time_come;
    time_t time_leave;
}Car;
typedef struct SqStack
{
    Car *base;
    Car *top;
    int stacksize;
}SqStack;
typedef struct QNode
{
    Car data;
    struct Qnode *next;
}QNode;
typedef struct LinkQueue
{
    Qnode *front;
    Qnode *rear;
}LinkQueue;
 
void InitStack (SqStack &S)
{
    S.base=(Car*)malloc(N*sizeof(Car));
    if(!S.base)
    {
    cout<<"Allocation failure"<<endl;exit(0);
    }
    S.top=S.base;
    S.stacksize=N;
    }
    
    int push(sqStack &S,Car &e)
    {
        if(S.top-S.base==N)
        {
            return ERROR;
        }
        else
        {
            *S.top++=e;
            return OK;
        }
    }
    int pop1(SqStack &S,Car &e)
    {
        if(S.base==S.top)
        {
            return ERROR;
        }
        else
        {
            e=*--S.top;
            return OK;
        }
    }
    
    int pop(SqStack &S,Car &e)
    {
        if(s.base==S.top)
        {
            cout<<"No parking garage,the system is about to launch..."<<endl;
            exit(0);
            return ERROR;       }
    }
    else
    {
        e*=*--S.top;
        return OK;
    }
}
 
void InitQueue(LinkQueue &Q)
{
    Q.front=Q.rear=(QNode*)malloc(sizeof(QNode));
    if(!Q.front)exit(0);
    Q.front-.next=NULL;
    
}
 
void EnQueue(LinkQueue &Q,Car e)
{
    QNode *p=(QNode*)malloc(sizeof(QNode));
    if(!p) exit(0);
    p-.data=e;
    p->next=NULL;
    Q.rear-.next=p;
    Q>rear=p;
    
}
 
int DeQueue(linkQueue &Q,Car &e)
{
    if(Q.front==Q.rear)
    return ERROR;
    else
    {
        QNode *p=(QNode*)malloc(sizeof(QNode));
        p=Q.front-.next;
        e=p->data;
        Q.front->next=p->next;
        id(Q.rear==p)
        Q.rear=Q.front
        free(q);
        return OK;
        
    }
}
 
void parking(SqStack &pbData,LinkQueue &l);
void getCar(SqStack &p,SqStack &t,LinkQueue &l);
void display(SqStack &p,SqStack &t);
 
int main()
{
    
    SqStack park;
    InitStack(park);
    SqStack temppark;
    InitStack(temppark);
    LinkQueue lq;
    InitQueue(lq);
    int j=1;
    int i;
    cout<<"\t*****************************************************"<<endl;
    cout<<endl;
    cout<<endl;
    cout<<"\t*****************************************************"<<endl;
    while(j)
    {
        cout<<"*****Please select the action you want to perform: 1,Parking 2.Pick 3.View Garage information 0.Exit the System******"<<endl;
        cout<<"\t";
        cin>>i;
        if(!cin){
            cout<<"Warning:Please enter the correct code[0~~3]"<<endl;
            cin.clear();
            cin.ignore(1024,'\n');
        }else{
            switch(i)
            {
                case 0;
                    j=0;
                    break;
                case 1:
                    parking(park,lq);
                    break;
                case 2:
                    getCar(park,temppark,lq);
                    break;
                case 3:
                    display(park,temppark);
                    break;
                deafult;
                    cout<<"Warning:Please enter the correct code[0~~3]"<<endl;
                    break;                      
            }
        }
    }
    return 0;
 
 
void parking(SqStack &p,LinkQueue &l)
{
    Car car1;
    car1.time_leave=0;
    cout<<"Please enter your license plate number:";
    cin>>car1.num;
    car1.time_com=time(NULL);
    cout<<"Storage time is:"<<localtime(&car1.time_come)->tm_hour<<":"<<localtime(&car1.time_come)->tm_min<<":"<<localtime(&car1.time_come)->tm_sec<<endl;
    int n=push(p,car1);
    if(n)
    {
        cout<<"You have succesfully sopped the car into the parking lot,license plate number:"<<car1.num<<"Storage time:";
        cout<<"Storage time:"<<localtime(&car1.time_come)->tm_hour<<":"<<localtime(&car1.time_come)->tn_min<<":"<<localtime(&car.time_come)->tm_sec<<endl;
        empty---:
    }
    else
    {
        cout<<"Parking is full,we will send your car parked next to the sidewalk,if there is spare parking space,then we will immediately put it into the parking lot!(Parked on the sidewalk may charge!)"<<endl;
        EnQueue(1,car1);
        EMPTYQUEE++;
        cout<<"Your car has been parked in the sidewalk on the successful!"<<endl;
    }
}
 
void getCar(SqStack &p,SqStack &t,LinkQueue &l)
{
    Car car1,car2;
    int ii;
    cout<<"Enter your license plate number to take:";
    cin>>car2.num;
    int boo=1;
    while(boo)
    {
        int n=pop1(p,car1);
        for(ii=0,ii<5,ii++)
        {
            if(car1.num[ii]!=car2.num[ii])
            break;
        }
        if(n==0)
        {
            cout<<"This car does not seem to the any car into the garage!"<<endl;
            boo=0;
        }
        elseelse if(ii>=5)
        {
            car1.ti,e_leave=time(NULL);
            cout<<"Your license plate number:"<<car1.num<<"Stop inot the parking lot of time for:";
            cout<<localtime(&car1.time_come)->tm_hour<<":"<<localtime(&car.time_come)->tm_min<<":"<<localtime)&car.time_come)->tm_sec;
            cout<<"Now time is:";
            cout<<localtime(&car1.time_come)->tm_hour<<":"<<localtime(&car1.time_come)->tm_min<<":"<<localtime(&car1.time_come)->tm_sec;
            double pp=car1.time_leave-car1.time_come;
            cout<<"Parking fee is:"<<price*pp<<"Y"<<endl;
            boo=0;
            empty++;
        }
        else
        {
            pus(t,car1);
        }
    }
    
    int n=pop1(t,car1);
    while(n)
    {
        push(p,car1);
        n=pop(t,car1);
    }
    
    if(empty&&EMPTYQUEE)
    {
        n=DeQueue(l,car2);
        
        if(n)
        {
            cout<<"The parking lot has been vacant parking spaces,we will send your car license plate number of"<<car.num<<"Car into the parking lot!";
            car.time_come=time(NULL);
            EMPTYQUEE--;
            
            int flag=push(p,car2);
            if(flag)
            {
            cout<<"You parked on the sidewalk has successfully stopped the car into yard,"<<"License number is:"<<car2.num<<"Into the parking lot of the time:";
            cout<<localtime(&car1.time_come)->tm_hour<<":"<<localtime(&car1.time_come)->tm_min<<":"<<localtime(&car1.time_come)->tm_sec<<endl;
            empty--;    
            }
        }
        else 
        cout<<"Sorry,there is no car on the sidewalk!"<<endl;
    }
}
 
void display(SqStack &p,SqStack &t)
{
    int flag=1;
    Car car1;
    cout<<"The car is based on the output sequence has time to enter!"<<endl;
    while(flag)
    P
    flag=pop1(p,car1);
    if(flag)
    {
        push(t,car1);
    }
}
flag=1;
while(flag)
{
    flag=pop1(t,car1);
    long tt=2000000L;
    if(flag)
    {
        while(tt--);
        cout<<"license number:"<<car.num<<"Storage time is:";
        cout<<localtime(&car1.time_come)->tm_hour<<":"<<localtime(&car1.time_come)->tm_min<<":"<<localtime(&car1.time_come)->tm_sec<<endl;
        push(p,car1);
    }
}
if(empty==3)
cout<<"No parking garage"<<endl;
}
Similar
Эксперт
41792 / 34177 / 6122
Регистрация: 12.04.2006
Сообщений: 57,940
28.05.2014, 12:39     Исправить код
Посмотрите здесь:

C++ Исправить код
C++ Исправить небольшой код
исправить на код С C++
C++ Исправить код
исправить код C++
C++ Исправить код
C++ исправить код
C++ Исправить код

Искать еще темы с ответами

Или воспользуйтесь поиском по форуму:
После регистрации реклама в сообщениях будет скрыта и будут доступны все возможности форума.
Prgrm101
3 / 3 / 3
Регистрация: 08.04.2014
Сообщений: 20
28.05.2014, 14:55     Исправить код #2
Исправил синтаксические ошибки
C++
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
#include"time.h"
#include<string>
#include <iostream.h>
 
const double price=0.0025;
const int N=3;
const int OK=1;
const int ERROR=0;
static int empty=N;
static int EMPTYQUEE=0;
 
struct Car
{
char num[5];
time_t time_come;
time_t time_leave;
};
 
struct SqStack
{
Car *base;
Car *top;
int stacksize;
};
 
struct QNode
{
Car data;
QNode *next;
};
 
struct LinkQueue
{
QNode *front;
QNode *rear;
};
 
void InitStack (SqStack &S)
{
S.base=(Car*)malloc(N*sizeof(Car));
if(!S.base)
{
cout<<"Allocation failure"<<endl;exit(0);
}
S.top=S.base;
S.stacksize=N;
}
 
int push(SqStack &S,Car &e)
{
if(S.top-S.base==N)
{
return ERROR;
}
else
{
*S.top++=e;
return OK;
}
}
int pop1(SqStack &S,Car &e)
{
if(S.base==S.top)
{
return ERROR;
}
else
{
e=*--S.top;
return OK;
}
}
 
int pop(SqStack &S,Car &e)
{
if(S.base==S.top)
{
    cout<<"No parking garage,the system is about to launch..."<<endl;
    exit(0);
    return ERROR;
}
else
{
    e=*--S.top;
    return OK;
}
}
 
void InitQueue(LinkQueue &Q)
{
Q.front=Q.rear=(QNode*)malloc(sizeof(QNode));
if(!Q.front)exit(0);
Q.front->next=NULL;
}
 
void EnQueue(LinkQueue &Q,Car e)
{
QNode *p=(QNode*)malloc(sizeof(QNode));
if(!p) exit(0);
p->data=e;
p->next=NULL;
Q.rear->next=p;
Q.rear=p;
}
 
int DeQueue(LinkQueue &Q,Car &e)
{
if(Q.front==Q.rear)
return ERROR;
else
{
QNode *p=(QNode*)malloc(sizeof(QNode));
p=Q.front->next;
e=p->data;
Q.front->next=p->next;
if(Q.rear==p)
Q.rear=Q.front;
return OK;
}
}
 
void parking(SqStack &p,LinkQueue &l)
{
Car car1;
car1.time_leave=0;
cout<<"Please enter your license plate number:";
cin>>car1.num;
car1.time_come=time(NULL);
cout<<"Storage time is:"<<localtime(&car1.time_come)->tm_hour<<":"<<localtime(&car1.time_come)->tm_min<<":"<<localtime(&car1.time_come)->tm_sec<<endl;
int n=push(p,car1);
if(n)
{
cout<<"You have succesfully sopped the car into the parking lot,license plate number:"<<car1.num<<"Storage time:";
cout<<"Storage time:"<<localtime(&car1.time_come)->tm_hour<<":"<<localtime(&car1.time_come)->tm_min<<":"<<localtime(&car1.time_come)->tm_sec<<endl;
empty--;
}
else
{
cout<<"Parking is full,we will send your car parked next to the sidewalk,if there is spare parking space,then we will immediately put it into the parking lot!(Parked on the sidewalk may charge!)"<<endl;
EnQueue(l,car1);
EMPTYQUEE++;
cout<<"Your car has been parked in the sidewalk on the successful!"<<endl;
}
}
 
void getCar(SqStack &p,SqStack &t,LinkQueue &l)
{
Car car1,car2;
int ii;
cout<<"Enter your license plate number to take:";
cin>>car2.num;
int boo=1;
while(boo)
{
int n=pop1(p,car1);
for(ii=0;ii<5;ii++)
{
if(car1.num[ii]!=car2.num[ii])
break;
}
if(n==0)
{
cout<<"This car does not seem to the any car into the garage!"<<endl;
boo=0;
}
else if(ii>=5)
{
car1.time_leave=time(NULL);
cout<<"Your license plate number:"<<car1.num<<"Stop inot the parking lot of time for:";
cout<<localtime(&car1.time_come)->tm_hour<<":"<<localtime(&car1.time_come)->tm_min<<":"<<localtime(&car1.time_come)->tm_sec;
cout<<"Now time is:";
cout<<localtime(&car1.time_come)->tm_hour<<":"<<localtime(&car1.time_come)->tm_min<<":"<<localtime(&car1.time_come)->tm_sec;
double pp=car1.time_leave-car1.time_come;
cout<<"Parking fee is:"<<price*pp<<"Y"<<endl;
boo=0;
empty++;
}
else
{
push(t,car1);
}
}
 
int n=pop1(t,car1);
while(n)
{
push(p,car1);
n=pop(t,car1);
}
 
if(empty&&EMPTYQUEE)
{
n=DeQueue(l,car2);
 
if(n)
{
cout<<"The parking lot has been vacant parking spaces,we will send your car license plate number of"<<car1.num<<"Car into the parking lot!";
car1.time_come=time(NULL);
EMPTYQUEE--;
 
int flag=push(p,car2);
if(flag)
{
cout<<"You parked on the sidewalk has successfully stopped the car into yard,"<<"License number is:"<<car2.num<<"Into the parking lot of the time:";
cout<<localtime(&car1.time_come)->tm_hour<<":"<<localtime(&car1.time_come)->tm_min<<":"<<localtime(&car1.time_come)->tm_sec<<endl;
empty--;
}
}
else
cout<<"Sorry,there is no car on the sidewalk!"<<endl;
}
}
 
void display(SqStack &p,SqStack &t)
{
int flag=1;
Car car1;
cout<<"The car is based on the output sequence has time to enter!"<<endl;
while(flag)
{
flag=pop1(p,car1);
if(flag)
{
push(t,car1);
}
}
flag=1;
while(flag)
{
flag=pop1(t,car1);
long tt=2000000L;
if(flag)
{
while(tt--);
cout<<"license number:"<<car1.num<<"Storage time is:";
cout<<localtime(&car1.time_come)->tm_hour<<":"<<localtime(&car1.time_come)->tm_min<<":"<<localtime(&car1.time_come)->tm_sec<<endl;
push(p,car1);
}
}
if(empty==3)
cout<<"No parking garage"<<endl;
}
 
int main()
{
SqStack park;
InitStack(park);
SqStack temppark;
InitStack(temppark);
LinkQueue lq;
InitQueue(lq);
int j=1;
int i;
cout<<"***************************************************\n";
cout<<"***************************************************\n";
while(j)
{
cout<<"Please select the action you want to perform:\n 1.Parking\n 2.Pick 3.View Garage information\n 0.Exit the System"<<endl;
cin>>i;
if(!cin){
cout<<"\nWarning:Please enter the correct code[0~~3]"<<endl;
cin.clear();
cin.ignore(1024,'\n');
}
else
{
    switch(i)
    {
        case 0:
            j=0;
            break;
        case 1:
            parking(park,lq);
            break;
        case 2:
            getCar(park,temppark,lq);
            break;
        case 3:
            display(park,temppark);
            break;
        deafult:
            cout<<"Warning:Please enter the correct code[0~~3]"<<endl;
            break;
    }
}
}
return 0;
}
Yandex
Объявления
28.05.2014, 14:55     Исправить код
Ответ Создать тему
Опции темы

Текущее время: 13:22. Часовой пояс GMT +3.
КиберФорум - форум программистов, компьютерный форум, программирование
Powered by vBulletin® Version 3.8.9
Copyright ©2000 - 2016, vBulletin Solutions, Inc.
Рейтинг@Mail.ru