04.12.2013, 20:01. Просмотров 174. Ответов 0
Программа формируют библиотеку, в которой возможно добавление новых книг, удаление, очистка всей библиотеки и т.д. Проблема в чем - при добавлении книги, игнорируется первый пункт - допустим, это введение номера книги. =[ Остальные работают нормально.
Скрин ошибки прилагаю.
Место ошибки отмечено комментарием (хотя, думаю, сама ошибка не там).
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
| //Spiski
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
using namespace std;
struct BIBLIOTEKA
{
int Year;
int kolvo;
char Osobiy_nomer[30];
char FIO[30];
char Nazvanie[40];
};
struct Node
{
BIBLIOTEKA *Library;
Node *next;
};
Node * create(BIBLIOTEKA * Library)
{
Node *root=new Node;
root->Library=Library;
root->next=NULL;
return root;
}
void add(BIBLIOTEKA *Library, Node* root) //dobavlenie novogo elementa
{
while(root->next)
root=root->next;
root->next=new Node;
root->next->Library=Library;
root->next->next=NULL;
}
void printLIBRARY(BIBLIOTEKA *Library)
{
cout<<"Nomer => "<<Library->Osobiy_nomer<<endl;
cout<<"F.I.O => "<<Library->FIO<<endl;
cout<<"Nazvanie => "<<Library->Nazvanie<<endl;
cout<<"Year => "<<Library->Year<<endl;
cout<<"Kolvo=> "<<Library->kolvo<<endl;
cout<<endl;
}
BIBLIOTEKA * makeLIBRARY() //
{
BIBLIOTEKA *Library=new BIBLIOTEKA;
cout<<"Vvedite nomer: => "; //---------------Na etom meste oshibka!!!!!!!!!!!!!!!!!!!!!!------
cin.getline(Library->Osobiy_nomer,30);
cout<<"Vvedite FIO: => ";
cin.getline(Library->FIO,30);
cout<<"Nazv: => ";
cin.getline(Library->Nazvanie,40);
cout<<"Ya: => ";
cin>>Library->Year;
cout<<"Kol: => ";
cin>>Library->kolvo;
cout<<"\n\n ";
return Library;
}
int choice()
{
int answer;
cout<<"--------Menu--------"<<endl;
cout<<"1. Dobavit knigu"<<endl;
cout<<"2. Vivesti vse"<<endl;
cout<<"3. poisk i Udalit"<<endl;
cout<<"4. Oshistit vsyu"<<endl;
cout<<"5. Viiti"<<endl;
cout<<"--------------------\n\n"<<endl;
cout<<"\n\nvvedite number: ";
cin>>answer;
if(answer>=1 && answer<=5)
return answer;
else
return 0;
}
Node* poisk_i_udalenei(Node * str)
{
Node *last=str,*root = str;
char qwe[30];
char qw[30], q[1];
cout<<"Vvedite nomer knigi => "<<endl;
cin.getline(qwe,30);
while (root)
{
if (!strcmp(qwe,root->Library->Osobiy_nomer))
{
{
printLIBRARY(root->Library);
cout<<"Udalit zapis? (da/net) "<<endl;// ÓäГ*ëåГ*ГЁГҐ Г§Г*ГЇГЁГ±ГЁ
char c;
cin.get(c);
if (c=='da')
{
root->Library=NULL;
if(last==root) str=root->next;
else last->next=root->next;
}
while(cin.get(c) && c!='\n');
last = root;
root=root->next;
}
}
else if (strcmp(qwe,root->Library->Osobiy_nomer))
root=root->next;
}
cout<<"udaleno"<<endl;
return str;
}
int main()
{
setlocale(LC_ALL,"");
Node *root=NULL;
int ch;
while(1)
{
ch=choice();
if(ch==1)
{
cout<<endl;
if(root==NULL)
root=create(makeLIBRARY());
else
add(makeLIBRARY(),root);
}
else if(ch==2)
{
cout<<endl;
int i=0;
int N=0;
Node *proot=root;
while (root)
{
N++;
root=root->next;
}
BIBLIOTEKA *buf;
BIBLIOTEKA **pLibrary=new BIBLIOTEKA*[N];
root=proot;
while (root)
{
pLibrary[i]=root->Library;
root=root->next;
i++;
}
root=proot;
for (i=0;i<N;i++)
printLIBRARY(pLibrary[i]);
}
else if(ch==3)
{
root=poisk_i_udalenei(root);
}
else if(ch==4)
{
char e;
cout<<"Ochistit vse polya? (da\net) "<<endl;// ÓäГ*ëåГ*ГЁГҐ ГўГ±ГҐГµ Г§Г*ГЇГЁГ±ГҐГ©
cin.get(e);
if(e=='da')
{root=NULL;
cout<<"Ochisheno"<<endl;}
else if (e=='net') cout<<endl;
while(cin.get(e) && e!='\n');
}
else if(ch==5)
{
break;
cout<<endl;
}
}
return 0;
} |
|