peHaBOT

Untitled

May 22nd, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.95 KB | None | 0 0
  1. //
  2. // main.cpp
  3. // students
  4. //
  5. // Created by Chojnacky Karol on 15.05.2018.
  6. // Copyright © 2018 Chojnacky Karol. All rights reserved.
  7. //
  8. #include <fstream>
  9. #include <iostream>
  10. using namespace std;
  11. string imie,nazwisko;
  12. fstream plik;
  13. int nr_albumu; //tworzymy liste
  14. struct student {
  15. string imie;
  16. string nazwisko;
  17. int nr_albumu;
  18. student *next;
  19. student();
  20. };
  21.  
  22. student::student(){
  23. next = 0;
  24. }
  25.  
  26. struct lista {
  27. student *first;
  28. void dodaj_studenta(string imie, string nazwisko, int nr_albumu);
  29. void usun_studenta(int nr);
  30. void wyswietl_studenta();
  31. void wyswietl_liste();
  32. lista();
  33. };
  34.  
  35. lista::lista(){
  36. first = 0;
  37. }
  38. lista *baza = new lista;
  39. void lista::dodaj_studenta(string imie, string nazwisko, int nr_albumu) {
  40. student *nowa = new student; // tworzy nowy element listy
  41.  
  42. // wypełniamy naszymi danymi
  43. nowa->imie = imie;
  44. nowa->nazwisko = nazwisko;
  45. nowa->nr_albumu = nr_albumu;
  46.  
  47. if (first==0) // sprawdzamy czy to pierwszy element listy
  48. {
  49. // jeżeli tak to nowy element jest teraz początkiem listy
  50. first = nowa;
  51. }
  52.  
  53. else
  54. {
  55. // w przeciwnym wypadku wędrujemy na koniec listy
  56. student *temp = first;
  57.  
  58. while (temp->next)
  59. {
  60. // znajdujemy wskaźnik na ostatni element
  61. temp = temp->next;
  62. }
  63.  
  64. temp->next = nowa; // ostatni element wskazuje na nasz nowy
  65. nowa->next = 0; // ostatni nie wskazuje na nic
  66. }
  67. }
  68.  
  69.  
  70. void lista::wyswietl_studenta() {
  71. // wskaznik na pierszy element listy
  72. student *temp = first;
  73.  
  74. // przewijamy wskazniki na nastepne elementy
  75. while (temp)
  76. {
  77. cout << "imie: " << temp->imie << " nazwisko: " << temp->nazwisko << endl;
  78. temp=temp->next;
  79. }
  80. }
  81. //~/Biurko/Studia/STUDIA - OWN/SII OWN/Programowanie/1 zajęcia/students/students
  82. void zapis(){
  83. plik.open("plik.txt", ios::out | ios::app);
  84. if(plik.good() == true)
  85. {
  86. plik << baza->first->nr_albumu << "\n";
  87. plik << baza->first->imie << "\n";
  88. plik << baza->first->nazwisko << "\n";
  89. plik.close();
  90. }
  91. return;
  92. }
  93.  
  94. void dodawanie(){
  95. //lista *root =
  96. cout << "DODAWANIE STUDENTA" << endl;
  97. cout << "Podaj imie studenta: "; cin >> imie;
  98. cout << "Podaj nazwisko studenta: "; cin >> nazwisko;
  99. cout << "Podaj numer albumu: "; cin >> nr_albumu;
  100. baza->dodaj_studenta(imie, nazwisko, nr_albumu);
  101. return zapis();
  102. }
  103.  
  104. void lista::wyswietl_liste()
  105. {
  106. // wskaznik na pierszy element listy
  107. student *temp = first;
  108.  
  109. // przewijamy wskazniki na nastepne elementy
  110. while (temp)
  111. {
  112. cout << "imie: " << temp->imie << " nazwisko: " << temp->nazwisko << " nr_albumu: " << temp->nr_albumu << endl;
  113. temp=temp->next;
  114. }
  115. }
  116.  
  117. void szukaj(){
  118. cout << baza->first->imie << ", " << baza->first->nazwisko << ", " << baza->first->nr_albumu << endl;
  119. return;
  120. }
  121.  
  122. void menu(){
  123.  
  124. int wybor;
  125. cout << "BAZA STUDENTÓW\n1. Dodaj studenta\n2. Szukaj student\n3. Edytuj dane studenta\n4. Usuń studenta z bazy\n5. Wyswietl całą bazę\n6. Zamknij program\n=> "; cin >> wybor;
  126. switch(wybor){
  127. case 1:
  128. dodawanie();
  129. return menu();
  130. break;
  131. case 2:
  132. szukaj();
  133. return menu();
  134. break;
  135. case 3:
  136.  
  137. break;
  138. case 4:
  139.  
  140. break;
  141. case 5:
  142. baza->wyswietl_liste();
  143. return menu();
  144. break;
  145. case 6:
  146. return;
  147. break;
  148. default:
  149. return ;
  150. break;
  151. }
  152. }
  153.  
  154. int main(int argc, const char * argv[]) {
  155. menu();
  156.  
  157.  
  158.  
  159.  
  160.  
  161.  
  162. return 0;
  163. }
Advertisement
Add Comment
Please, Sign In to add comment