Advertisement
Guest User

Untitled

a guest
May 25th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdio.h>
  3. #include <Windows.h>
  4. #include <string.h>
  5. #define N 25
  6. using namespace std;
  7.  
  8.  
  9. struct book
  10. {
  11. char lastname[20];
  12. char firstname[20];
  13. char book[20];
  14. }x;
  15. void output(struct book x[])
  16. {
  17. cout << "\n\n\nФамилия Имя :\t \n"<<x->lastname<<" ";
  18. cout<<x->firstname<<"\n";
  19. cout << "название книги:\t\n"<<x->book;
  20. }
  21.  
  22. void input(struct book *x)
  23. {
  24. cin >> x->lastname >> x->firstname >> x->book;
  25. }
  26. int main ()
  27. {
  28. SetConsoleCP(1251);
  29. SetConsoleOutputCP(1251);
  30.  
  31. int n;
  32. int i;
  33. cin >> n;
  34. struct book x[N];
  35. cout<<"Введите фамилию, имя автора и название книги: \n";
  36. for (i=0;i<n;i++)
  37. {
  38. input(&x[i]);
  39. }
  40. int k=1;
  41. char key;
  42. do
  43. {
  44. printf("Хотите добавить запись?(y/n) :\n");
  45. scanf("%s", &key);
  46. //if (scanf("%s", &key) == 1)
  47. // key = -1;
  48. switch (key)
  49. {
  50. case 'y':
  51. if (n < N)
  52. {
  53. n++;
  54. for (i=n; i > 0; i--)
  55. {
  56. x[i] = x[i-1];
  57. } // îñâîáîäèòü ýëåìåíò a[0]
  58. printf("Введите данные :\n");
  59. input(&x[0]);
  60. cout<<n;
  61. }
  62.  
  63. else
  64. printf("\aOut of memory!\n");
  65. break;
  66. case 'n':
  67. cout<<n;
  68. k=0;
  69. break;
  70. default:
  71. printf("\aWrong operation number!\n");
  72. break;
  73. break;
  74. }} while (k);
  75. cout<<n;
  76. for (i=0;i<n;i++)
  77. {
  78. output(&x[i]);
  79. }
  80. return(0);
  81. system ("pause");
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement