Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // main.cpp
- #include <iostream>
- #include "Lista.h"
- #include "Zadania.h"
- using namespace std;
- void menu(Lista_studentow* lista, Zadania* lista_zadan)
- {
- int opcja1;
- do
- {
- cout << endl << "----------------------------" << endl;
- cout<<"\t\t***** DZIENNIK ZAJEC ***** "<<endl;
- cout << endl << "----------------------------" << endl;
- cout<<"Wybierz opcje z ponizszych : "<<endl;
- cout<<"\t[1] LISTA STUDENTOW "<<endl;
- cout<<"\t[2] DODANIE DANYCH STUDENTOW "<<endl;
- cout<<"\t[3] DODANIE NOTATKI ODNOSNIE PRACY STUDENTA "<<endl;
- cout<<"\t[4] DODAJ OCENE STUDENTA "<<endl;
- cout<<"\t[5] WYSZUKAJ STUDENTA "<<endl;
- cout<<"\t[6] WYPISZ LISTE ZADAN " << endl;
- cout<<"\t[7] EXIT "<<endl;
- cin>>opcja1;
- switch(opcja1)
- {
- case 1:
- lista->wypisz_liste();
- break;
- case 2:
- lista->dodawanie();
- break;
- case 3:
- //jakasfunkcja3()
- break;
- case 4:
- //jakasfunkcja4()
- break;
- case 5:
- szukanie_studenta(lista);
- break;
- case 6:
- lista_zadan->wypisz_liste();
- break;
- case 7:
- cout<<"Koniec programu!"<<endl;
- break;
- default:
- cout << endl << "----------------------------" << endl;
- cout<<"\t\t***** DZIENNIK ZAJEC ***** "<<endl;
- cout << endl << "----------------------------" << endl;
- cout<<"Wybierz opcje z ponizszych : "<<endl;
- cout<<"\t[1] LISTA STUDENTOW "<<endl;
- cout<<"\t[2] DODANIE DANYCH STUDENTOW "<<endl;
- cout<<"\t[3] DODANIE NOTATKI ODNOSNIE PRACY STUDENTA "<<endl;
- cout<<"\t[4] DODAJ OCENE STUDENTA "<<endl;
- cout<<"\t[5] WYSZUKAJ STUDENTA "<<endl;
- cout<<"\t[6] WYPISZ LISTE ZADAN " << endl;
- cout<<"\t[7] EXIT "<<endl;
- cin>>opcja1;
- }
- }
- while(opcja1 != 7);
- }
- int main()
- {
- Lista_studentow lista; // tworzymy pust¹ listê
- lista.wczytaj_z_pliku();
- Zadania zadania;
- zadania.wczytaj_z_pliku();
- menu(&lista, &zadania);
- return 0;
- }
- /*Student *ReadStudentsList()
- {
- Student *curr=NULL, *temp=NULL, *head=NULL;
- cout<<"Wpisz imie, nazwisko a nastepnie numer pesel !"<<endl;
- cout<<"Aby zakoñczyæ wype³nianie wpisz '!' na klawiaturze !"<<endl;
- string name_;
- cin>>name_;
- while(name_ != '!') //tutaj jakoœ ten warunek musze
- //zmienic ale nie mam pomyslow
- {
- curr = new Student;
- curr->name = name_;
- if(head == NULL)
- head = curr;
- else
- {
- temp->next = curr;
- }
- temp = curr;
- }
- return curr;
- }
- void PrintStudent(Student *curr)
- {
- cout << curr->name << endl;
- }
- void PrintStudentsList(Student *curr)
- {
- while(curr != NULL)
- {
- void PrintStudent(); //funkcja dla pojedynczego studenta
- curr = curr->next;
- }
- cout<<endl<<endl;
- }
- void DeleteList(Student *curr)
- {
- while( curr != NULL)
- {
- Student *pom = curr;
- curr = curr->next;
- delete pom;
- }
- }
- int ReadFromFile(string FileName)
- {
- ifstream plik;
- plik.open("text.txt");
- if(plik.good())
- else
- {
- cout<<"Pliku nie udalo sie otworzyc !"<<endl;
- return 0;
- }
- plik.close();
- }*/
- // Head.h
- #ifndef HEAD_H
- #define HEAD_H
- #include <iostream>
- //#include "Student.h"
- using namespace std;
- class Lista_studentow;
- class Zadania;
- class Student;
- class Zadanie;
- string poziom(int);
- void szukanie_studenta(Lista_studentow*);
- #endif // HEAD_H
- // Funkcje.cpp
- #include <string>
- #include "Head.h"
- #include "Lista.h"
- using namespace std;
- string poziom(int p)
- {
- switch(p)
- {
- case 1:
- return "bardzo latwy";
- case 2:
- return "latwy";
- case 3:
- return "sredni";
- case 4:
- return "trudny";
- case 5:
- return "bardzo trudny";
- }
- }
- void szukanie_studenta(Lista_studentow* lista)
- {
- int numer;
- cout << "Podaj numer indeksu: ";
- cin >> numer;
- Student* szukany = lista->znajdz_studenta(numer);
- if(szukany == nullptr)
- {
- cout << "Nie znaleziono studenta\n";
- return;
- }
- szukany->wypisz_dane();
- }
- // Lista.h
- #ifndef LISTA_H
- #define LISTA_H
- #include "Head.h"
- #include "Student.h"
- class Lista_studentow
- {
- public:
- Lista_studentow(); // konstruktor domyœlny
- ~Lista_studentow();
- void wczytaj_z_pliku();
- void dodaj(string, string, int);
- void dodawanie();
- void wypisz_liste();
- void kasuj_ostatni();
- Student* znajdz_studenta(int);
- private:
- Student* head;
- };
- #endif // LISTA_H
- // Lista.cpp
- #include <fstream>
- #include "Lista.h"
- #include "Student.h"
- using namespace std;
- /*class Lista_studentow
- {
- public:
- Lista_studentow(); // konstruktor domyœlny
- ~Lista_studentow();
- void wczytaj_z_pliku();
- void dodaj(string, string, int);
- void dodawanie();
- void wypisz_liste();
- void kasuj_ostatni();
- Student* znajdz_studenta(int);
- private:
- Student* head;
- };*/
- Lista_studentow::Lista_studentow() : head(nullptr)
- {
- }
- Lista_studentow::~Lista_studentow()
- {
- while(head)
- kasuj_ostatni();
- cout << "Lista usunieta\n";
- }
- void Lista_studentow::kasuj_ostatni()
- {
- Student* temp = head;
- if(temp)
- {
- if(temp->next)
- {
- while(temp->next->next )
- temp = temp->next;
- delete temp->next;
- temp->next = nullptr;
- }
- else
- {
- delete temp;
- head = nullptr;
- }
- }
- }
- void Lista_studentow::wczytaj_z_pliku()
- {
- ifstream plik;
- string imie, nazwisko;
- int pesel;
- plik.open("lista.txt");
- if(plik.fail())
- {
- cout << "Nie udalo sie wczytac pliku.\n";
- return;
- }
- while(!plik.eof())
- {
- plik >> imie >> nazwisko >> pesel;
- dodaj(imie, nazwisko, pesel);
- }
- cout << "Lista wczytana prawidlowo\n";
- plik.close();
- }
- void Lista_studentow::dodawanie()
- {
- cout << "Podaj dane studenta (imie, nazwisko, nr indeksu): ";
- string imie, nazwisko;
- int pesel;
- cin >> imie >> nazwisko >> pesel;
- dodaj(imie, nazwisko, pesel);
- }
- void Lista_studentow::dodaj(string imie, string nazwisko, int pesel)
- {
- Student* nowy = new Student(imie, nazwisko, pesel);
- if(head == nullptr)
- head = nowy;
- else
- {
- Student* temp = head;
- while(temp->next)
- temp = temp->next;
- temp->next = nowy;
- nowy->next = nullptr;
- }
- }
- void Lista_studentow::wypisz_liste()
- {
- Student* temp = head;
- while(temp != nullptr)
- {
- cout << temp->Name << " " << temp->LastName << " " << temp->dane << endl;
- temp = temp->next;
- }
- }
- Student* Lista_studentow::znajdz_studenta(int numer)
- {
- Student* temp = head;
- while(temp->dane != numer)
- {
- if(temp->next == nullptr)
- return nullptr;
- else
- temp = temp->next;
- }
- return temp;
- }
- // Zadania.h
- #ifndef ZADANIA_H
- #define ZADANIA_H
- #include "Head.h"
- class Zadania
- {
- public:
- Zadania();
- ~Zadania();
- void wczytaj_z_pliku();
- void dodaj(string, int);
- void dodawanie();
- void wypisz_liste();
- void kasuj_ostatni();
- private:
- Zadanie* head;
- };
- #endif // ZADANIA_H
- // Zadania.cpp
- #include <iostream>
- #include <fstream>
- //#include "Head.h"
- #include "Zadania.h"
- #include "Zadanie.h"
- using namespace std;
- /*class Zadania
- {
- public:
- Zadania();
- ~Zadania();
- void wczytaj_z_pliku();
- void dodaj(string, int);
- void dodawanie();
- void wypisz_liste();
- void kasuj_ostatni();
- private:
- Zadanie* head;
- };*/
- Zadania::Zadania() : head(nullptr)
- {
- }
- Zadania::~Zadania()
- {
- while(head)
- kasuj_ostatni();
- cout << "Lista usunieta\n";
- }
- void Zadania::kasuj_ostatni()
- {
- Zadanie* temp = head;
- if(temp)
- {
- if(temp->next)
- {
- while(temp->next->next )
- temp = temp->next;
- delete temp->next;
- temp->next = nullptr;
- }
- else
- {
- delete temp;
- head = nullptr;
- }
- }
- }
- void Zadania::wczytaj_z_pliku()
- {
- ifstream plik;
- string pytanie;
- int level;
- plik.open("zadania.txt");
- if(plik.fail())
- {
- cout << "Nie udalo sie wczytac pliku.\n";
- return;
- }
- while(!plik.eof())
- {
- getline(plik, pytanie);
- level = static_cast<int>(pytanie[pytanie.size() - 1] - 48);
- pytanie.erase(pytanie.size() - 2, 2);
- dodaj(pytanie, level);
- }
- cout << "Lista wczytana prawidlowo\n";
- plik.close();
- }
- void Zadania::dodawanie()
- {
- cout << "Podaj nazwe zadania i jego poziom trudnosci (w skali 1-5): ";
- string tresc;
- int poziom;
- dodaj(tresc, poziom);
- }
- void Zadania::dodaj(string tresc, int poziom)
- {
- Zadanie* nowy = new Zadanie(tresc, poziom);
- nowy->next = nullptr;
- if(head == nullptr)
- head = nowy;
- else
- {
- Zadanie* temp = head;
- while(temp->next)
- temp = temp->next;
- temp->next = nowy;
- nowy->next = nullptr;
- }
- }
- void Zadania::wypisz_liste()
- {
- Zadanie* temp = head;
- while(temp != nullptr)
- {
- cout << temp->nazwa << " (poziom trudnosci: " << poziom(temp->poziom_trudnosci) << ")" << endl;
- temp = temp->next;
- }
- }
- // Student.h
- #ifndef STUDENT_H
- #define STUDENT_H
- #include <iostream>
- #include "Head.h"
- using namespace std;
- class Student
- {
- friend class Lista_studentow;
- string Name;
- string LastName;
- int dane; //dane to numer pesel
- Student *next;
- public:
- Student(string, string, int);
- void wypisz_dane();
- void wypisz_zadania();
- };
- #endif // STUDENT_H
- // Student.cpp
- #include "Student.h"
- /*class Student
- {
- friend class Lista_studentow;
- string Name;
- string LastName;
- int dane; //dane to numer pesel
- Student *next;
- public:
- Student(string, string, int);
- void wypisz_dane();
- void wypisz_zadania();
- };*/
- Student::Student(string name, string lastname, int pesel) : Name(name), LastName(lastname), dane(pesel), next(nullptr)
- {
- }
- void Student::wypisz_dane()
- {
- cout << Name << " " << LastName << ", nr indeksu: " << dane << endl;
- cout << "Lista zadan:\n";
- wypisz_zadania(); // metoda wypisująca wszystkie zadania przypisane do danego studenta
- cout << "Wybierz co chcesz zrobic:\n";
- cout << "\t1. przypisz zadanie\n";
- cout << "\t2. dodaj ocene\n";
- }
- void Student::wypisz_zadania()
- {
- cout << "(wypisuje zadania studenta)\n";
- }
- // Zadanie.h
- #ifndef ZADANIE_H
- #define ZADANIE_H
- #include <iostream>
- #include "Student.h"
- using namespace std;
- class Zadanie
- {
- friend class Zadania;
- string nazwa;
- int poziom_trudnosci;
- Student* studenci;
- Zadanie* next;
- public:
- Zadanie(string, int);
- };
- #endif // ZADANIE_H
- // Zadanie.cpp
- #include "Zadanie.h"
- /*class Zadanie
- {
- string nazwa;
- int poziom_trudnosci;
- Student* studenci;
- Zadanie* next;
- public:
- Zadanie(string, int);
- };*/
- Zadanie::Zadanie(string tresc, int level) : nazwa(tresc), poziom_trudnosci(level), next(nullptr)
- {
- }
Advertisement
Add Comment
Please, Sign In to add comment