Guest User

Untitled

a guest
Apr 11th, 2016
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.68 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <iomanip>
  4.  
  5. using namespace std;
  6.  
  7. struct Pozycja {
  8. string typ;
  9. string tytul;
  10. string autor;
  11. int rok_wydania;
  12. int liczba_stron;
  13. int numer;
  14.  
  15. Pozycja *next;
  16. };
  17.  
  18. Pozycja *aktualny, *glowa, *ogon;
  19.  
  20. Pozycja *nowa_lista() {
  21. aktualny=NULL;
  22. glowa=NULL;
  23. char odp='t';
  24. string typ, tytul, autor;
  25. int rok_wydania, liczba_stron, nr, numer;
  26.  
  27. while (odp=='t' || odp=='T') {
  28. cout << "Wprowadz informacje o pozycji: \n";
  29. cout << "Podaj typ pozycji (artykul - 1/ksiazka - 2/inne - 3): \n";
  30. cin >> nr;
  31. while (nr==0 || nr>3){
  32. cout << "Podaj liczbe 1, 2 lub 3. \n";
  33. cin >> nr;
  34. }
  35. if (nr==1)
  36. typ="artykul";
  37. if (nr==2)
  38. typ="ksiazka";
  39. if (nr==3)
  40. typ="inne";
  41. std::cin.ignore();
  42. cout << "Podaj tytul: \n";
  43. getline(cin, tytul);
  44. cout << "Podaj autora: \n";
  45. getline(cin, autor);
  46. cout << "Podaj rok wydania: \n";
  47. cin >> rok_wydania;
  48. cout << "Podaj liczbe stron: \n";
  49. cin >> liczba_stron;
  50. cout << "Podaj mumer ISBN: \n";
  51. cin >> numer;
  52.  
  53. ogon=aktualny;
  54. aktualny=new Pozycja;
  55. aktualny->numer=numer;
  56. aktualny->typ=typ;
  57. aktualny->tytul=tytul;
  58. aktualny->autor=autor;
  59. aktualny->rok_wydania=rok_wydania;
  60. aktualny->liczba_stron=liczba_stron;
  61. aktualny->next=NULL;
  62.  
  63. if (ogon==NULL)
  64. glowa=aktualny;
  65. else
  66. ogon->next=aktualny;
  67.  
  68. cout << "\n" << "Aby dodac kolejna pozycje wprowadz \"t\" lub \"T\". W przeciwnym razie wprowadz cokolwiek. \n";
  69. cin >> odp;
  70. cout << endl << endl;
  71. std::cin.ignore();
  72. }
  73.  
  74. return glowa;
  75. }
  76.  
  77. void wyswietl(Pozycja *adres) {
  78.  
  79. while (adres!=NULL){
  80. cout << "Nr ISBN: \t" << adres->numer << "\n";
  81. cout << "Typ: \t" << adres->typ << "\n";
  82. cout << "Tytul: \t" << adres->tytul << "\n";
  83. cout << "Autor: \t" << adres->autor << "\n";
  84. cout << "Rok wydania: \t" << adres->rok_wydania << "\n";
  85. cout << "Liczba stron: \t" << adres->liczba_stron << endl << endl;
  86.  
  87. adres=adres->next;
  88. }
  89. }
  90.  
  91. Pozycja *dodaj_element (Pozycja *adres) {
  92. Pozycja *pom;
  93. char odp='t';
  94. string typ, tytul, autor;
  95. int rok_wydania, liczba_stron, nr, numer;
  96.  
  97. while (odp=='t' || odp=='T'){
  98. cout << "Wprowadz informacje o pozycji: \n";
  99. cout << "Podaj typ pozycji (artykul - 1/ksiazka - 2/inne - 3): \n";
  100. cin >> nr;
  101. while (nr==0 || nr>3){
  102. cout << "Podaj liczbe 1, 2 lub 3. \n";
  103. cin >> nr;
  104. }
  105. if (nr==1)
  106. typ="artykul";
  107. if (nr==2)
  108. typ="ksiazka";
  109. if (nr==3)
  110. typ="inne";
  111. std::cin.ignore();
  112. cout << "Podaj tytul: \n";
  113. getline(cin, tytul);
  114. cout << "Podaj autora: \n";
  115. getline(cin, autor);
  116. cout << "Podaj rok wydania: \n";
  117. cin >> rok_wydania;
  118. cout << "Podaj liczbe stron: \n";
  119. cin >> liczba_stron;
  120. cout << "Podaj mumer ISBN: \n";
  121. cin >> numer;
  122.  
  123. pom=new Pozycja;
  124. pom->numer=numer;
  125. pom->typ=typ;
  126. pom->tytul=tytul;
  127. pom->autor=autor;
  128. pom->rok_wydania=rok_wydania;
  129. pom->liczba_stron=liczba_stron;
  130.  
  131. if (adres==NULL){
  132. adres=pom;
  133. }
  134. else{
  135. Pozycja *pom1 = adres;
  136.  
  137. while (pom1->next!=NULL){
  138. pom1 = pom1->next;
  139. }
  140. pom1->next=pom;
  141. pom->next=NULL;
  142. }
  143.  
  144. cout << "\n" << "Aby dodac kolejna pozycje wprowadz \"t\" lub \"T\". W przeciwnym razie wprowadz cokolwiek. \n";
  145. cin >> odp;
  146. cout << endl << endl;
  147. std::cin.ignore();
  148. }
  149.  
  150. return adres;
  151. }
  152.  
  153. Pozycja *usun_element (Pozycja *adres) {
  154. Pozycja *pom=adres;
  155. int nr;
  156. cout << "Podaj numer ISBN pozycji do usuniecia: \n";
  157. cin >> nr;
  158. if(pom==NULL)
  159. return 0;
  160. else{
  161. if (pom->numer==nr){
  162. Pozycja *pom1=pom;
  163. pom=pom->next;
  164. delete pom1;
  165. }
  166. else{
  167. while(pom->next!=NULL){
  168. if (pom->next->numer==nr){
  169. Pozycja *pom1=pom->next;
  170. pom->next=pom->next->next;
  171. delete pom1;
  172. }
  173. else{
  174.  
  175. }
  176. }
  177. }
  178. }
  179. return pom;
  180. }
  181.  
  182.  
  183. void usuwanie_listy (Pozycja *&adres) {
  184. Pozycja *pom;
  185. while (adres!=NULL){
  186. pom=adres;
  187. adres=adres->next;
  188. }
  189. delete pom;
  190. }
  191.  
  192. int main()
  193. {
  194. Pozycja *glowa;
  195. glowa=nowa_lista();
  196. wyswietl(glowa);
  197. glowa=usun_element(glowa);
  198. glowa=dodaj_element(glowa);
  199. wyswietl(glowa);
  200. usuwanie_listy(glowa);
  201.  
  202. return 0;
  203. }
Advertisement
Add Comment
Please, Sign In to add comment