0 / 0 / 0
Регистрация: 08.03.2016
Сообщений: 1
|
|
1
|
Составить программу, которая содержит текущую информацию о книгах
08.03.2016, 19:06. Показов 446. Ответов 0
Вот код программы. Проблема с 3 пунктом меню. Необходимо удалить данные выбранной книги. затем вернуться в меню и просмотреть оставшиеся. И как сделать так чтобы отображались записи о книгах, упорядочкнные по году выпуска.
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
| #include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <windows.h>
using namespace std;
struct LIBRARY
{
char nomer[30];
char FIO[30];
char nazvanie[40];
int Year;
int kolvo;
};
struct STR
{
LIBRARY *Library;
STR *next;
};
STR * create(LIBRARY * Library)
{
STR *root=new STR;
root->Library=Library;
root->next=NULL;
return root;
}
void add(LIBRARY *Library, STR* root)
{
while(root->next)
root=root->next;
root->next=new STR;
root->next->Library=Library;
root->next->next=NULL;
}
void printLIBRARY(LIBRARY *Library)
{
cout<<"Nomer => "<<Library->nomer<<endl;
cout<<"FIO => "<<Library->FIO<<endl;
cout<<"Nazvanie => "<<Library->nazvanie<<endl;
cout<<"Year => "<<Library->Year<<endl;
cout<<"Kolvo => "<<Library->kolvo<<endl;
cout<<endl;
}
LIBRARY * makeLIBRARY()
{
cout<<"Enter book data:"<<endl;
LIBRARY *Library=new LIBRARY;
fflush(stdin);
cout<<"Enter book nomer: => ";
cin.getline(Library->nomer,30);
cout<<"Enter Author's FIO: => ";
cin.getline(Library->FIO,30);
cout<<"Enter book name: => ";
cin.getline(Library->nazvanie,40);
cout<<"Enter made year: => ";
cin>>Library->Year;
cout<<"Enter count of books: => ";
cin>>Library->kolvo;
return Library;
}
int choice()
{
int answer;
getch();
system("cls");
cout<<"Main menu"<<endl;
cout<<"1. Add new books to the list"<<endl;
cout<<"2. Print LIBRARY at list"<<endl;
cout<<"3. Search and delete"<<endl;
cout<<"4. EXIT"<<endl;
cout<<"Enter your choice: ";
cin>>answer;
fflush(stdin);
if(answer>=1 && answer<=4)
return answer;
else
return 0;
}
int main()
{
STR *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;
STR *proot=root;
while (root)
{
N++;
root=root->next;
}
LIBRARY *buf;
LIBRARY **pLibrary=new LIBRARY*[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)
{
char qwe[30];
char qw[30], q[1];
cout<<"Enter nomer of book => "<<endl;
cin.getline(qwe,30);
while (root)
{
if (!strcmp(qwe,root->Library->nomer))
{
{
printLIBRARY(root->Library);
cout<<"Do you want clear this entries? (y/n) "<<endl;
cin.getline(q,1);
if (!strcmp(q,"y"))
{
root->Library=NULL;
}
root=root->next;
}
}
else if (strcmp(qwe,root->Library->nomer))
root=root->next;
}
cout<<endl;
}
else if(ch==4)
{
break;
cout<<endl;
}
}
return 0;
} |
|
0
|