Advertisement
Guest User

Untitled

a guest
Oct 26th, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.88 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include <string>
  4. using namespace std;
  5.  
  6. struct autor {
  7. string imie;
  8. string nazwisko;
  9. };
  10.  
  11. struct ksiazka {
  12. string tytul;
  13. string gatunek;
  14. string wydawnictwo;
  15. };
  16.  
  17. struct info {
  18. int strony;
  19. int rok;
  20. string rodzaj;
  21. };
  22.  
  23. //*************************************************************************
  24. void zapis(autor** a, int size);
  25. void zapis(ksiazka** b, int size);
  26. void zapis(info** c, int size);
  27. void odczyt(autor** a, int size);
  28. void odczyt(ksiazka** b, int size);
  29. void odczyt(info** c, int size);
  30. void ini_m(autor** &a, int size);
  31. void ini_m(ksiazka** &b, int size);
  32. void ini_m(info** &c, int size);
  33. void alloc_mem(autor** &a, int size);
  34. void alloc_mem(ksiazka** &b, int size);
  35. void alloc_mem(info** &c, int size);
  36. void delete_a(autor** &a, int size);
  37. void delete_a(ksiazka** &b, int size);
  38. void delete_a(info** &c, int size);
  39. //*************************************************************************
  40. int main() {
  41. autor** a = NULL;
  42. ksiazka** b = NULL;
  43. info** c = NULL;
  44. int size;
  45. cout << "Podaj wielkosc tablicy: ";
  46. cin >> size;
  47. cout << "\nWczytywanie danych o ksiazce!\n\n";
  48. alloc_mem(a, size);
  49. alloc_mem(b, size);
  50. alloc_mem(c, size);
  51. ini_m(a, size);
  52. zapis(a, size);
  53. ini_m(b, size);
  54. zapis(b, size);
  55. ini_m(c, size);
  56. zapis(c, size);
  57. cout << endl << "Odczyt:" << endl;
  58. odczyt(a, size);
  59. odczyt(b, size);
  60. odczyt(c, size);
  61. delete_a(a, size);
  62. delete_a(b, size);
  63. delete_a(c, size);
  64. getchar();
  65. getchar();
  66. return 0;
  67. }
  68. //*************************************************************************
  69. void zapis(autor** a, int size) {
  70. string imie, nazwisko;
  71. getchar();
  72. cout << "Imie autora: ";
  73. getline(cin, imie);
  74. cout << "Nazwisko autora: ";
  75. getline(cin, nazwisko);
  76. for (int i = 0; i < size; i++) {
  77. a[i]->imie = imie;
  78. a[i]->nazwisko = nazwisko;
  79. }
  80.  
  81. }
  82. //***
  83. void zapis(ksiazka** b, int size) {
  84. string tytul, gatunek, wydawnictwo;
  85. cout << "Tytul ksiazki: ";
  86. getline(cin, tytul);
  87. cout << "Gatunek: ";
  88. getline(cin, gatunek);
  89. cout << "Wydawnictwo: ";
  90. getline(cin, wydawnictwo);
  91. for (int i = 0; i < size; i++) {
  92. b[i]->tytul = tytul;
  93. b[i]->gatunek = gatunek;
  94. b[i]->wydawnictwo = wydawnictwo;
  95. }
  96. }
  97. //***
  98. void zapis(info** c, int size) {
  99. int strony, rok;
  100. string rodzaj;
  101. cout << "Rodzaj okladki: ";
  102. getline(cin, rodzaj);
  103. cout << "Ilosc stron: ";
  104. cin >> strony;
  105. cout << "Rok wydania: ";
  106. cin >> rok;
  107. for (int i = 0; i < size; i++) {
  108. c[i]->rodzaj = rodzaj;
  109. c[i]->strony = strony;
  110. c[i]->rok = rok;
  111. }
  112. }
  113. //***
  114. void odczyt(autor** a, int size) {
  115. for (int i = 0; i < size; i++) {
  116. cout << a[i]->imie << "\t" << a[i]->nazwisko << "\t";
  117. }
  118. }
  119. //***
  120. void odczyt(ksiazka** b, int size) {
  121. for (int i = 0; i < size; i++) {
  122. cout << b[i]->tytul << "\t" << b[i]->gatunek << "\t" << b[i]->wydawnictwo << "\t";
  123. }
  124. }
  125. //***
  126. void odczyt(info** c, int size) {
  127. for (int i = 0; i < size; i++) {
  128. cout << c[i]->rodzaj << "\t" << c[i]->strony << "\t" << c[i]->rok << "\t";
  129. }
  130. }
  131. //***
  132. void alloc_mem(autor** &a, int size) {
  133. a = new autor*[size];
  134. }
  135. //***
  136. void alloc_mem(ksiazka** &b, int size) {
  137. b = new ksiazka*[size];
  138. }
  139. //***
  140. void alloc_mem(info** &c, int size) {
  141. c = new info*[size];
  142. }
  143. //***
  144. void ini_m(autor** &a, int size) {
  145. for (int i = 0; i < size; i++) {
  146. a[i] = new autor;
  147. }
  148. }
  149. //***
  150. void ini_m(ksiazka** &b, int size) {
  151. for (int i = 0; i < size; i++) {
  152. b[i] = new ksiazka;
  153. }
  154. }
  155. //***
  156. void ini_m(info** &c, int size) {
  157. for (int i = 0; i < size; i++) {
  158. c[i] = new info;
  159. }
  160. }
  161. //***
  162. void delete_a(autor** &a, int size) {
  163. for (int i = 0; i<size; i++) {
  164. delete a[i];
  165. }
  166. delete[] a;
  167. }
  168. //***
  169. void delete_a(ksiazka** &b, int size) {
  170. for (int i = 0; i<size; i++) {
  171. delete b[i];
  172. }
  173. delete[] b;
  174. }
  175. //***
  176. void delete_a(info** &c, int size) {
  177. for (int i = 0; i<size; i++) {
  178. delete c[i];
  179. }
  180. delete[] c;
  181. }
  182. //***
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement