Guest User

Untitled

a guest
Feb 24th, 2021
25
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.32 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4.  
  5.  
  6.  
  7.  
  8. class Book{
  9.  
  10. private:
  11.  
  12. string name;
  13. int dateofCreation;
  14. int numberofPages;
  15. int numberofCreators;
  16.  
  17. public:
  18.  
  19. void setName(string name){
  20. this->name = name;
  21. }
  22.  
  23. void setDateofCreation(int date){
  24. this->dateofCreation = date;
  25. }
  26. void setNumberOfPages(int number){
  27. this->numberofPages = number;
  28. }
  29. void setNumberOfCreators(int number){
  30. this->numberofCreators = number;
  31. }
  32.  
  33.  
  34. string getName(){
  35. return name;
  36. }
  37. int getDateOfCreation(){
  38. return dateofCreation;
  39. }
  40. int getNumberOfPages(){
  41. return numberofPages;
  42. }
  43. int getNumberOfCreators(){
  44. return numberofCreators;
  45. }
  46.  
  47. };
  48.  
  49.  
  50. int find_free(Book*idk,int SIZE) {
  51. register int t;
  52.  
  53.  
  54. for (t = 0; idk[t].getName()[0] && t < SIZE; ++t);
  55.  
  56. if (t == SIZE) return -1;
  57. return t;
  58. }
  59.  
  60.  
  61.  
  62. void add_book(Book*idk, int SIZE){
  63. int slot;
  64. char s[80];
  65. int n = SIZE;
  66. slot = find_free(idk,n);
  67.  
  68. string ds;
  69. int date1;
  70. int date2;
  71. int date3;
  72.  
  73. if (slot == -1) {
  74. cout << ("\nСписоk заполнен")<<endl;
  75. return;
  76. }
  77. cout << ("Введите название книги");
  78. cin>>s;
  79. idk[slot].setName(s);
  80.  
  81. cout << ("Введите дату создания ");
  82. cin>>date1;
  83. idk[slot].setDateofCreation(date1);
  84. cout << ("Введите количество страничек ");
  85. cin>>date2;
  86. idk[slot].setNumberOfPages(date2);
  87. cout << ("Введите количество авторов : ");
  88. cin>>date3;
  89. idk[slot].setNumberOfCreators(date3);
  90.  
  91. }
  92.  
  93.  
  94. void init_list(Book*idk, int SIZE){
  95. register int t;
  96.  
  97. for (t = 0; t < SIZE; ++t) {
  98. idk[t].getName()[0] = '\0';
  99. }
  100. }
  101.  
  102.  
  103. int menu_select(Book*idk,int SIZE) {
  104. int c;
  105.  
  106. cout << ("1. Добавить книгу \n");
  107. cout << ("2. Удалить книгу\n");
  108. cout << ("3. Вывести информацию про книгу\n");
  109. cout << ("4. Добавить автора \n");
  110. cout << ("5. Вывод стричики \n");
  111. cout << ("6. Каталог стричок \n");
  112.  
  113. do {
  114. cout << ("\nВведите номер нужного пункта: ");
  115. cin >> c;
  116. } while (c < 0 || c > 9);
  117. return c;
  118. }
  119.  
  120.  
  121. void list(Book*idk, int SIZE)
  122. {
  123. register int t;
  124.  
  125. for(t=0; t<SIZE; ++t) {
  126. if(idk[t].getName()[0]) {
  127. cout<<"Имя: "<<(idk[t].getName())<<endl;
  128. cout<<"Дата создания: "<<(idk[t].getDateOfCreation())<<endl;
  129. cout<<"Количество создателей: "<<(idk[t].getNumberOfCreators())<<endl;
  130. cout<<"Количество страниц: "<<(idk[t].getNumberOfPages())<<endl;
  131. }
  132. }
  133. cout<<"\n""\n";
  134. }
  135.  
  136. int main(){
  137.  
  138. int n;
  139. cout<<"Введите размер"<<endl;
  140. cin>>n;
  141. Book *idk = new Book[n];
  142.  
  143.  
  144.  
  145.  
  146.  
  147. init_list(idk,n);
  148.  
  149. char choice;
  150.  
  151.  
  152. for (;;) {
  153. choice = menu_select(idk,n);
  154. switch (choice) {
  155. case 1:
  156. add_book(idk,n);
  157. break;
  158. case 3:
  159. list(idk,n);
  160. break;
  161.  
  162. case 7:
  163. exit(0);
  164.  
  165. }
  166. }
  167.  
  168. }
Advertisement
Add Comment
Please, Sign In to add comment