MeehoweCK

Untitled

Mar 27th, 2020
279
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 11.86 KB | None | 0 0
  1. // main.cpp
  2. #include <iostream>
  3. #include "Lista.h"
  4. #include "Zadania.h"
  5.  
  6. using namespace std;
  7.  
  8. void menu(Lista_studentow* lista, Zadania* lista_zadan)
  9. {
  10.     int opcja1;
  11.  
  12.     do
  13.     {
  14.         cout << endl << "----------------------------" << endl;
  15.         cout<<"\t\t***** DZIENNIK ZAJEC ***** "<<endl;
  16.         cout << endl << "----------------------------" << endl;
  17.         cout<<"Wybierz opcje z ponizszych : "<<endl;
  18.         cout<<"\t[1] LISTA STUDENTOW "<<endl;
  19.         cout<<"\t[2] DODANIE DANYCH STUDENTOW "<<endl;
  20.         cout<<"\t[3] DODANIE NOTATKI ODNOSNIE PRACY STUDENTA "<<endl;
  21.         cout<<"\t[4] DODAJ OCENE STUDENTA "<<endl;
  22.         cout<<"\t[5] WYSZUKAJ STUDENTA "<<endl;
  23.         cout<<"\t[6] WYPISZ LISTE ZADAN " << endl;
  24.         cout<<"\t[7] EXIT "<<endl;
  25.         cin>>opcja1;
  26.  
  27.         switch(opcja1)
  28.         {
  29.         case 1:
  30.             lista->wypisz_liste();
  31.             break;
  32.         case 2:
  33.             lista->dodawanie();
  34.             break;
  35.         case 3:
  36.             //jakasfunkcja3()
  37.             break;
  38.         case 4:
  39.             //jakasfunkcja4()
  40.             break;
  41.         case 5:
  42.             szukanie_studenta(lista);
  43.             break;
  44.         case 6:
  45.             lista_zadan->wypisz_liste();
  46.             break;
  47.         case 7:
  48.             cout<<"Koniec programu!"<<endl;
  49.             break;
  50.         default:
  51.             cout << endl << "----------------------------" << endl;
  52.             cout<<"\t\t***** DZIENNIK ZAJEC ***** "<<endl;
  53.             cout << endl << "----------------------------" << endl;
  54.             cout<<"Wybierz opcje z ponizszych : "<<endl;
  55.             cout<<"\t[1] LISTA STUDENTOW "<<endl;
  56.             cout<<"\t[2] DODANIE DANYCH STUDENTOW "<<endl;
  57.             cout<<"\t[3] DODANIE NOTATKI ODNOSNIE PRACY STUDENTA "<<endl;
  58.             cout<<"\t[4] DODAJ OCENE STUDENTA "<<endl;
  59.             cout<<"\t[5] WYSZUKAJ STUDENTA "<<endl;
  60.             cout<<"\t[6] WYPISZ LISTE ZADAN " << endl;
  61.             cout<<"\t[7] EXIT "<<endl;
  62.             cin>>opcja1;
  63.  
  64.         }
  65.     }
  66.     while(opcja1 != 7);
  67. }
  68.  
  69. int main()
  70. {
  71.     Lista_studentow lista;        // tworzymy pust¹ listê
  72.     lista.wczytaj_z_pliku();
  73.     Zadania zadania;
  74.     zadania.wczytaj_z_pliku();
  75.     menu(&lista, &zadania);
  76.  
  77.     return 0;
  78. }
  79.  
  80. /*Student *ReadStudentsList()
  81. {
  82.     Student *curr=NULL, *temp=NULL, *head=NULL;
  83.     cout<<"Wpisz imie, nazwisko a nastepnie numer pesel !"<<endl;
  84.     cout<<"Aby zakoñczyæ wype³nianie wpisz '!' na klawiaturze !"<<endl;
  85.     string name_;
  86.     cin>>name_;
  87.  
  88.     while(name_ != '!') //tutaj jakoœ ten warunek musze
  89.         //zmienic ale nie mam pomyslow
  90.     {
  91.         curr = new Student;
  92.         curr->name = name_;
  93.  
  94.         if(head == NULL)
  95.             head = curr;
  96.         else
  97.         {
  98.             temp->next = curr;
  99.         }
  100.         temp = curr;
  101.     }
  102.     return curr;
  103. }
  104.  
  105. void PrintStudent(Student *curr)
  106. {
  107.     cout << curr->name << endl;
  108. }
  109.  
  110. void PrintStudentsList(Student *curr)
  111. {
  112.     while(curr != NULL)
  113.     {
  114.         void PrintStudent();   //funkcja dla pojedynczego studenta
  115.         curr = curr->next;
  116.     }
  117.     cout<<endl<<endl;
  118. }
  119. void DeleteList(Student *curr)
  120. {
  121.     while( curr != NULL)
  122.     {
  123.         Student *pom = curr;
  124.         curr = curr->next;
  125.         delete pom;
  126.     }
  127. }
  128.  
  129. int ReadFromFile(string FileName)
  130. {
  131.     ifstream plik;
  132.     plik.open("text.txt");
  133.     if(plik.good())
  134.  
  135.  
  136.  
  137.         else
  138.         {
  139.             cout<<"Pliku nie udalo sie otworzyc !"<<endl;
  140.             return 0;
  141.         }
  142.  
  143.  
  144.     plik.close();
  145. }*/
  146.  
  147. // Head.h
  148. #ifndef HEAD_H
  149. #define HEAD_H
  150.  
  151. #include <iostream>
  152. //#include "Student.h"
  153.  
  154. using namespace std;
  155.  
  156. class Lista_studentow;
  157. class Zadania;
  158. class Student;
  159. class Zadanie;
  160.  
  161. string poziom(int);
  162. void szukanie_studenta(Lista_studentow*);
  163.  
  164. #endif // HEAD_H
  165.  
  166. // Funkcje.cpp
  167. #include <string>
  168. #include "Head.h"
  169. #include "Lista.h"
  170.  
  171. using namespace std;
  172.  
  173. string poziom(int p)
  174. {
  175.     switch(p)
  176.     {
  177.     case 1:
  178.         return "bardzo latwy";
  179.     case 2:
  180.         return "latwy";
  181.     case 3:
  182.         return "sredni";
  183.     case 4:
  184.         return "trudny";
  185.     case 5:
  186.         return "bardzo trudny";
  187.     }
  188. }
  189.  
  190. void szukanie_studenta(Lista_studentow* lista)
  191. {
  192.     int numer;
  193.     cout << "Podaj numer indeksu: ";
  194.     cin >> numer;
  195.     Student* szukany = lista->znajdz_studenta(numer);
  196.     if(szukany == nullptr)
  197.     {
  198.         cout << "Nie znaleziono studenta\n";
  199.         return;
  200.     }
  201.     szukany->wypisz_dane();
  202. }
  203.  
  204. // Lista.h
  205. #ifndef LISTA_H
  206. #define LISTA_H
  207.  
  208. #include "Head.h"
  209. #include "Student.h"
  210.  
  211. class Lista_studentow
  212. {
  213.     public:
  214.         Lista_studentow();        // konstruktor domyœlny
  215.         ~Lista_studentow();
  216.         void wczytaj_z_pliku();
  217.         void dodaj(string, string, int);
  218.         void dodawanie();
  219.         void wypisz_liste();
  220.         void kasuj_ostatni();
  221.         Student* znajdz_studenta(int);
  222.     private:
  223.         Student* head;
  224. };
  225.  
  226. #endif // LISTA_H
  227.  
  228. // Lista.cpp
  229. #include <fstream>
  230. #include "Lista.h"
  231. #include "Student.h"
  232.  
  233. using namespace std;
  234.  
  235. /*class Lista_studentow
  236. {
  237.     public:
  238.         Lista_studentow();        // konstruktor domyœlny
  239.         ~Lista_studentow();
  240.         void wczytaj_z_pliku();
  241.         void dodaj(string, string, int);
  242.         void dodawanie();
  243.         void wypisz_liste();
  244.         void kasuj_ostatni();
  245.         Student* znajdz_studenta(int);
  246.     private:
  247.         Student* head;
  248. };*/
  249.  
  250. Lista_studentow::Lista_studentow() : head(nullptr)
  251. {
  252. }
  253.  
  254.  
  255. Lista_studentow::~Lista_studentow()
  256. {
  257.     while(head)
  258.         kasuj_ostatni();
  259.     cout << "Lista usunieta\n";
  260. }
  261.  
  262. void Lista_studentow::kasuj_ostatni()
  263. {
  264.     Student* temp = head;
  265.     if(temp)
  266.     {
  267.         if(temp->next)
  268.         {
  269.             while(temp->next->next )
  270.                 temp = temp->next;
  271.             delete temp->next;
  272.             temp->next = nullptr;
  273.         }
  274.         else
  275.         {
  276.             delete temp;
  277.             head = nullptr;
  278.         }
  279.     }
  280. }
  281.  
  282. void Lista_studentow::wczytaj_z_pliku()
  283. {
  284.     ifstream plik;
  285.     string imie, nazwisko;
  286.     int pesel;
  287.     plik.open("lista.txt");
  288.     if(plik.fail())
  289.     {
  290.         cout << "Nie udalo sie wczytac pliku.\n";
  291.         return;
  292.     }
  293.     while(!plik.eof())
  294.     {
  295.         plik >> imie >> nazwisko >> pesel;
  296.         dodaj(imie, nazwisko, pesel);
  297.     }
  298.     cout << "Lista wczytana prawidlowo\n";
  299.     plik.close();
  300. }
  301.  
  302. void Lista_studentow::dodawanie()
  303. {
  304.     cout << "Podaj dane studenta (imie, nazwisko, nr indeksu): ";
  305.     string imie, nazwisko;
  306.     int pesel;
  307.     cin >> imie >> nazwisko >> pesel;
  308.     dodaj(imie, nazwisko, pesel);
  309. }
  310.  
  311. void Lista_studentow::dodaj(string imie, string nazwisko, int pesel)
  312. {
  313.     Student* nowy = new Student(imie, nazwisko, pesel);
  314.  
  315.     if(head == nullptr)
  316.         head = nowy;
  317.  
  318.     else
  319.     {
  320.         Student* temp = head;
  321.  
  322.         while(temp->next)
  323.             temp = temp->next;
  324.         temp->next = nowy;
  325.         nowy->next = nullptr;
  326.     }
  327. }
  328.  
  329. void Lista_studentow::wypisz_liste()
  330. {
  331.     Student* temp = head;
  332.     while(temp != nullptr)
  333.     {
  334.         cout << temp->Name << " " << temp->LastName << " " << temp->dane << endl;
  335.         temp = temp->next;
  336.     }
  337. }
  338.  
  339. Student* Lista_studentow::znajdz_studenta(int numer)
  340. {
  341.     Student* temp = head;
  342.     while(temp->dane != numer)
  343.     {
  344.         if(temp->next == nullptr)
  345.             return nullptr;
  346.         else
  347.             temp = temp->next;
  348.     }
  349.     return temp;
  350. }
  351.  
  352. // Zadania.h
  353. #ifndef ZADANIA_H
  354. #define ZADANIA_H
  355.  
  356. #include "Head.h"
  357.  
  358. class Zadania
  359. {
  360.     public:
  361.         Zadania();
  362.         ~Zadania();
  363.         void wczytaj_z_pliku();
  364.         void dodaj(string, int);
  365.         void dodawanie();
  366.         void wypisz_liste();
  367.         void kasuj_ostatni();
  368.     private:
  369.         Zadanie* head;
  370. };
  371.  
  372. #endif // ZADANIA_H
  373.  
  374. // Zadania.cpp
  375. #include <iostream>
  376. #include <fstream>
  377. //#include "Head.h"
  378. #include "Zadania.h"
  379. #include "Zadanie.h"
  380.  
  381. using namespace std;
  382.  
  383. /*class Zadania
  384. {
  385.     public:
  386.         Zadania();
  387.         ~Zadania();
  388.         void wczytaj_z_pliku();
  389.         void dodaj(string, int);
  390.         void dodawanie();
  391.         void wypisz_liste();
  392.         void kasuj_ostatni();
  393.     private:
  394.         Zadanie* head;
  395. };*/
  396.  
  397. Zadania::Zadania() : head(nullptr)
  398. {
  399. }
  400.  
  401.  
  402. Zadania::~Zadania()
  403. {
  404.     while(head)
  405.         kasuj_ostatni();
  406.     cout << "Lista usunieta\n";
  407. }
  408.  
  409. void Zadania::kasuj_ostatni()
  410. {
  411.     Zadanie* temp = head;
  412.     if(temp)
  413.     {
  414.         if(temp->next)
  415.         {
  416.             while(temp->next->next )
  417.                 temp = temp->next;
  418.             delete temp->next;
  419.             temp->next = nullptr;
  420.         }
  421.         else
  422.         {
  423.             delete temp;
  424.             head = nullptr;
  425.         }
  426.     }
  427. }
  428.  
  429. void Zadania::wczytaj_z_pliku()
  430. {
  431.     ifstream plik;
  432.     string pytanie;
  433.     int level;
  434.     plik.open("zadania.txt");
  435.     if(plik.fail())
  436.     {
  437.         cout << "Nie udalo sie wczytac pliku.\n";
  438.         return;
  439.     }
  440.     while(!plik.eof())
  441.     {
  442.         getline(plik, pytanie);
  443.         level = static_cast<int>(pytanie[pytanie.size() - 1] - 48);
  444.         pytanie.erase(pytanie.size() - 2, 2);
  445.         dodaj(pytanie, level);
  446.     }
  447.     cout << "Lista wczytana prawidlowo\n";
  448.     plik.close();
  449. }
  450.  
  451. void Zadania::dodawanie()
  452. {
  453.     cout << "Podaj nazwe zadania i jego poziom trudnosci (w skali 1-5): ";
  454.     string tresc;
  455.     int poziom;
  456.     dodaj(tresc, poziom);
  457. }
  458.  
  459. void Zadania::dodaj(string tresc, int poziom)
  460. {
  461.     Zadanie* nowy = new Zadanie(tresc, poziom);
  462.     nowy->next = nullptr;
  463.  
  464.     if(head == nullptr)
  465.         head = nowy;
  466.  
  467.     else
  468.     {
  469.         Zadanie* temp = head;
  470.  
  471.         while(temp->next)
  472.             temp = temp->next;
  473.         temp->next = nowy;
  474.         nowy->next = nullptr;
  475.     }
  476. }
  477.  
  478. void Zadania::wypisz_liste()
  479. {
  480.     Zadanie* temp = head;
  481.     while(temp != nullptr)
  482.     {
  483.         cout << temp->nazwa << " (poziom trudnosci: " << poziom(temp->poziom_trudnosci) << ")" << endl;
  484.         temp = temp->next;
  485.     }
  486. }
  487.  
  488. // Student.h
  489. #ifndef STUDENT_H
  490. #define STUDENT_H
  491.  
  492. #include <iostream>
  493. #include "Head.h"
  494.  
  495. using namespace std;
  496.  
  497. class Student
  498. {
  499.     friend class Lista_studentow;
  500.     string Name;
  501.     string LastName;
  502.     int dane;              //dane to numer pesel
  503.     Student *next;
  504. public:
  505.     Student(string, string, int);
  506.     void wypisz_dane();
  507.     void wypisz_zadania();
  508. };
  509.  
  510. #endif // STUDENT_H
  511.  
  512. // Student.cpp
  513. #include "Student.h"
  514.  
  515. /*class Student
  516. {
  517.     friend class Lista_studentow;
  518.     string Name;
  519.     string LastName;
  520.     int dane;              //dane to numer pesel
  521.     Student *next;
  522. public:
  523.     Student(string, string, int);
  524.     void wypisz_dane();
  525.     void wypisz_zadania();
  526. };*/
  527.  
  528. Student::Student(string name, string lastname, int pesel) : Name(name), LastName(lastname), dane(pesel), next(nullptr)
  529. {
  530.  
  531. }
  532.  
  533. void Student::wypisz_dane()
  534. {
  535.     cout << Name << " " << LastName << ", nr indeksu: " << dane << endl;
  536.     cout << "Lista zadan:\n";
  537.     wypisz_zadania();               // metoda wypisująca wszystkie zadania przypisane do danego studenta
  538.     cout << "Wybierz co chcesz zrobic:\n";
  539.     cout << "\t1. przypisz zadanie\n";
  540.     cout << "\t2. dodaj ocene\n";
  541. }
  542.  
  543. void Student::wypisz_zadania()
  544. {
  545.     cout << "(wypisuje zadania studenta)\n";
  546. }
  547.  
  548. // Zadanie.h
  549. #ifndef ZADANIE_H
  550. #define ZADANIE_H
  551.  
  552. #include <iostream>
  553. #include "Student.h"
  554.  
  555. using namespace std;
  556.  
  557. class Zadanie
  558. {
  559.     friend class Zadania;
  560.     string nazwa;
  561.     int poziom_trudnosci;
  562.     Student* studenci;
  563.     Zadanie* next;
  564. public:
  565.     Zadanie(string, int);
  566. };
  567.  
  568. #endif // ZADANIE_H
  569.  
  570. // Zadanie.cpp
  571. #include "Zadanie.h"
  572.  
  573. /*class Zadanie
  574. {
  575.     string nazwa;
  576.     int poziom_trudnosci;
  577.     Student* studenci;
  578.     Zadanie* next;
  579. public:
  580.     Zadanie(string, int);
  581. };*/
  582.  
  583. Zadanie::Zadanie(string tresc, int level) : nazwa(tresc), poziom_trudnosci(level), next(nullptr)
  584. {
  585.  
  586. }
Advertisement
Add Comment
Please, Sign In to add comment