Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- class SubjectsRec
- {
- public:
- int code;
- string name;
- string course;
- template <typename P>
- void io(bool print, P pointer, bool sub_only = false)
- {
- if (sub_only && cout << "\n\tPredmet: " << name) return;
- if (print &&
- cout << "\tSifra predmeta: " << code
- << "\tNaziv: " << name
- << "\tSmjer: " << course
- << "\tPokazivac na sljedeci element: 0x" << pointer << endl)
- return;
- cout << "\nSifra predmeta: ";
- cin >> code;
- cout << "Naziv: ";
- cin.ignore();
- getline(cin, name);
- cout << "Smjer: ";
- getline(cin, course);
- }
- };
- class Subjects
- {
- SubjectsRec subjects;
- Subjects* next;
- Subjects* previous;
- public:
- static int counter;
- Subjects()
- {
- next = NULL;
- previous = NULL;
- }
- void appendFront()
- {
- if (!this->next && cout << "\nLista je prazna,te se ne moze dodati element na pocetak!") return;
- subjects.io(0, 0);
- counter++;
- Subjects* node = new Subjects;
- Subjects* _next = next;
- node->subjects = subjects;
- node->previous = this;
- node->next = _next;
- this->next = node;
- _next->previous = node;
- }
- void appendBack()
- {
- subjects.io(0, 0, 0);
- counter++;
- Subjects* last = this;
- Subjects* node = new Subjects;
- while (last->next) last = last->next;
- node->subjects = subjects;
- node->previous = last;
- node->next = NULL;
- last->next = node;
- }
- void PrintList()
- {
- puts("\nIspis liste: ");
- for (Subjects* node = this->next; node; node = node->next)
- node->subjects.io(true, node->next);
- }
- bool Search(string course_id, int sub_id, bool bycode = false, bool bycode_print = false)
- {
- for (Subjects* node = this->next; node; node = node->next)
- {
- if (!bycode_print && node->subjects.course == course_id) node->subjects.io(true, NULL, true);
- if (!bycode_print && node->subjects.course == course_id) return true;
- if (bycode_print && node->subjects.code == sub_id) node->subjects.io(true, NULL, true);
- if ((bycode || bycode_print) && node->subjects.code == sub_id) return true;
- }
- return false;
- }
- }*SubjectsList = NULL;
- class EntryRec
- {
- public:
- int entry_code;
- int sub_code;
- string stud_id;
- string term;
- void io(bool print = false)
- {
- if (print &&
- cout << "\n\tSifra prijave: " << entry_code
- << "\tSifra predmeta: " << sub_code
- && SubjectsList->Search("", sub_code, 1, 1) && //ispis predmeta
- cout << "\tMaticni broj: " << stud_id
- << "\tRok: " << term << endl
- ) return;
- cout << "\nSifra prijave: ";
- cin >> entry_code;
- do cout << "Sifra predmeta: ";
- while (cin >> sub_code && !SubjectsList->Search("", sub_code, true));
- cout << "Maticni broj studenta: ";
- cin.ignore();
- getline(cin, stud_id);
- cout << "Rok: ";
- getline(cin, term);
- }
- };
- class Entry
- {
- public:
- EntryRec* entry_rec;
- Entry* next;
- static int counter;
- Entry()
- {
- entry_rec = new EntryRec;
- next = NULL;
- }
- void append()
- {
- entry_rec->io();
- counter++;
- Entry* last = this;
- Entry* node = new Entry;
- while (last->next) last = last->next;
- last->next = node;
- node->entry_rec->entry_code = entry_rec->entry_code;
- node->entry_rec->sub_code = entry_rec->sub_code;
- node->entry_rec->stud_id = entry_rec->stud_id;
- node->entry_rec->term = entry_rec->term;
- }
- void PrintEntries()
- {
- for (Entry* node = this->next; node; node = node->next)
- node->entry_rec->io(true);
- }
- }*EntryList = NULL;
- int Subjects::counter = 0;
- int Entry::counter = 0;
- short ListStatus(bool sub_list = true)
- {
- if (sub_list && !SubjectsList && cout << "\n\t0 - Glava liste predmeta nije alocirana") return 0;
- if (sub_list && SubjectsList && !Subjects::counter && cout << "\n\t1 - Lista predmeta je prazna\n") return 1;
- if (sub_list && SubjectsList && Subjects::counter && printf("\n\t2 - Lista predmeta sadrzi %i element/a\n", Subjects::counter)) return 2;
- if (!EntryList && cout << "\n\t0 - Glava liste prijava nije alocirana\n") return 0;
- if (EntryList && !Entry::counter && cout << "\n\t0 - Lista prijava je prazna\n") return 1;
- if (Entry::counter && printf("\n\t2 - Lista prijava sadrzi %i element/a\n", Entry::counter)) return 2;
- }
- int main()
- {
- short choice;
- short subs_state;
- short entry_state;
- string buffer;
- infinite_loop:
- puts("\n1. Alokacija glave liste predmeta/Upis predmeta na kraj liste predmeta i ispis liste");
- puts("2. Popis predmeta zadanog smjera/Unos na pocetak liste predmeta");
- puts("3. Unos u listu prijava/Ispis liste prijava za sve predmete");
- puts("9. Izlaz\n");
- cout << "Izbor: ";
- cin >> choice;
- switch (choice)
- {
- case 1:
- if (!ListStatus())
- {
- SubjectsList = new Subjects;
- cout << "\n\tGlava liste predmeta alocirana!" << endl;
- break;
- }
- SubjectsList->appendBack();
- SubjectsList->PrintList();
- break;
- case 2:
- if (!ListStatus()) break;
- buffer = "";
- cout << "Unesite smjer: ";
- cin.ignore();
- getline(cin, buffer);
- puts("Popis predmeta za zadani smjer: ");
- SubjectsList->Search(buffer, 0);
- cout << "\nPritisnite enter ako zelite dodati predmet na pocetak liste, 0 za povratak: ";
- if (cin.get() != '\n') break;
- SubjectsList->appendFront();
- SubjectsList->PrintList();
- break;
- case 3:
- subs_state = ListStatus();
- entry_state = ListStatus(false);
- if (subs_state != 2 && cout << "\n\tUnos prijava nije dopusten!") break;
- if (!entry_state)
- {
- EntryList = new Entry;
- puts("\tGlava liste prijava alocirana!");
- break;
- }
- EntryList->append();
- EntryList->PrintEntries();
- break;
- default:
- if (choice != 9) puts("\nNepostojeci izbor!\n");
- else return 0;
- }
- goto infinite_loop;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement