#include <iostream> #include <windows.h> #include <string.h> using std::cout; using std::cin; using std::endl; struct s_books { int data; char book_name[40]; char avtor[30]; char ganre[30]; int price; int reiting; int ID; }books; void add (s_books *&book, int &size) { s_books *temp = new s_books[++size]; for(int i = 0; i < size - 1; i++) { temp[i].data=book[i].data; strcpy_s(temp[i].book_name,book[i].book_name); strcpy_s(temp[i].avtor,book[i].avtor); strcpy_s(temp[i].ganre,book[i].ganre); temp[i].price=book[i].price; temp[i].reiting=book[i].reiting; temp[i].ID=book[i].ID; } cout<<"Год издания: "; cin>>temp[size - 1].data; cout<<"Название: "; cin>>temp[size - 1].book_name; cout<<"Автор: "; cin>>temp[size - 1].avtor; cout<<"Жанр: "; cin>>temp[size - 1].ganre; cout<<"Цена: "; cin>>temp[size - 1].price; cout<<"Рейтинг: "; cin>>temp[size - 1].reiting; cout<<"Код: "; cin>>temp[size - 1].ID; delete[] book; book = new s_books[size]; for(int i = 0; i < size; i++) { book[i].data = temp[i].data; strcpy_s(book[i].book_name,temp[i].book_name); strcpy_s(book[i].avtor,temp[i].avtor); strcpy_s(book[i].ganre,temp[i].ganre); book[i].price = temp[i].price; book[i].reiting = temp[i].reiting; book[i].ID = temp[i].ID; } delete[] temp; } void del (s_books *&book, int &size) { } void All_kat(s_books *book, int size) { for(int i=0;i<size;i++) { cout<<book[i].data<<" "<<book[i].book_name<<" "<<book[i].avtor<<" "<<book[i].ganre<<" "<<book[i].price<<" "<<book[i].reiting<<" "<<book[i].ID<<endl; } } void main() { SetConsoleOutputCP(1251); SetConsoleCP(1251); const int const_size=5; s_books books[const_size]={1971,"Гидравлика","Башта Т.М.","Гидравлика",45,5,1, 1983,"Черчение","Боголюбов С.К.","Черчение",50,2,2, 1987,"Машиностроительное черчение","Мерзон Э.Д.","Черчение",45,1,3, 1975,"Объемные насосы","Васильцов Э.А.","Гидравлика",45,3,4, 1996,"Хранители Кодекса Люцифера","Дюбель Р.П.","Детектив",70,4,5, }; int size=5; s_books *book; book=new s_books[size]; for (int i = 0; i < size; i++ ) { book[i]=*&books[i]; } while(1) { cout<<"\n------------------------------------"<<endl; cout<<"\n1-Добавить\t2-Все категори\t3-Удалить\t0-Выход"<<endl; cout<<"\nВыберите действие из команд главного меню "; int key; cin>>key; if(key>3){break;} if(key==1) { cout<<"\nВведите данные книги"<<endl; add(book,size); } if(key==2) { cout<<"\nВсе книги"<<endl; All_kat(book,size); } if(key==3) { cout<<"\nВведите данные книги"<<endl; del(book,size); } if(key==0){break;break;} } } |