Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <cstring>
- using namespace std;
- #if !defined( _RIESENIE_H_ )
- #define _RIESENIE_H_
- //1.uloha
- class OSOBA {
- char *priezvisko;
- char *meno;
- char *login;
- bool otvorene;
- friend class UCITEL;
- char *heslo;
- protected:
- bool jePrihlaseny() {return otvorene;};
- const string getPassword() {return heslo;};
- void setPassword(const string &passw);
- const string kodovanieHesla(const string &password);
- public:
- OSOBA(const string &login0, const string &heslo0);
- ~OSOBA();
- bool setName(const string &meno0, const string &priezvisko0);
- const string getName();
- const string getMail();
- bool prihlasenie(const string &login0, const string &heslo0);
- //2.uloha
- OSOBA(const OSOBA &o);
- };
- class STUDENT : public OSOBA {
- string odbor;
- int rok;
- public:
- STUDENT(const string &login0, const string &heslo0);
- STUDENT(const STUDENT &student);
- bool zmenHeslo(const string &oldH, const string &newH, const string &newH2);
- bool vlozOdbor(const string &odbor0, int rok0);
- const string studijnyOdbor();
- const int rocnik();
- };
- //3.uloha
- class UCITEL {
- int pocet;
- string *zoznam;
- string meno;
- public:
- UCITEL(const string &meno0);
- UCITEL(const UCITEL &ucitel);
- ~UCITEL();
- const string menoUcitela() { return meno; };
- bool vlozPredmet(const string &predmet0);
- const string zoznamPredmetov();
- bool zmenHesloStudenta(STUDENT &student
- , const string &newHeslo, const string &newHeslo2);
- };
- //4.uloha
- class PREDMET {
- string nazov;
- STUDENT **studenti;
- int pocet;
- int maxPocet;
- int rocnik;
- string odbor;
- public:
- PREDMET(const string &nazov0, const string &odbor0, int rocnik0, int maxPocet0);
- ~PREDMET();
- bool prihlasenieNaPredmet(STUDENT &student);
- const int pocetPrijatych();
- const string zoznamStudentov();
- //5.uloha
- PREDMET(const PREDMET &predmet0);
- bool vylucStudenta(const string &meno);
- };
- #endif
- bool DUMMY_BOOL = true;
- int DUMMY_INT = 0;
- string DUMMY_STRING = "";
- //1.uloha
- OSOBA::OSOBA(const string &login0, const string &heslo0)
- : priezvisko(NULL), meno(NULL), login(NULL), otvorene(false), heslo(NULL)
- {
- if (login0.length() > 0) {
- login = new char[login0.length()+1];
- strcpy(login, login0.c_str());
- }
- else {
- login = new char[20];
- strcpy(login, "PrazdnyLogin");
- }
- setPassword(heslo0);
- priezvisko = new char[10];
- strcpy(priezvisko, "Nezadane");
- meno = new char[10];
- strcpy(meno, "Nezadane");
- }
- OSOBA::~OSOBA() {
- if (login[0] != '\0') {
- login = NULL;
- delete [] login;
- heslo = NULL;
- delete [] heslo;
- meno = NULL;
- delete [] meno;
- priezvisko = NULL;
- delete [] priezvisko;
- }
- }
- const string OSOBA::kodovanieHesla(const string &password) {
- return DUMMY_STRING;
- }
- void OSOBA::setPassword(const string &passw) {
- heslo = new char[passw.length()+1];
- strcpy(heslo,passw.c_str());
- }
- bool OSOBA::setName(const string &meno0, const string &priezvisko0) {
- if (!otvorene) {
- return false;
- }
- meno = NULL;
- meno = new char[meno0.length()+1];
- priezvisko = NULL;
- priezvisko = new char[priezvisko0.length()+1];
- if (meno0.length() > 0) {
- strcpy(meno, meno0.c_str());
- }
- else {
- strcpy(meno, "Nezadane");
- }
- if (priezvisko0.length() > 0) {
- strcpy(priezvisko, priezvisko0.c_str());
- }
- else {
- strcpy(priezvisko, "Nezadane");
- }
- return true;
- }
- const string OSOBA::getName() {
- string celeMeno;
- celeMeno = priezvisko;
- celeMeno += " ";
- celeMeno += meno;
- return (celeMeno);
- }
- const string OSOBA::getMail() {
- string mail;
- mail = priezvisko;
- mail += ".";
- mail += meno;
- mail += "@fmfi.uk.sk";
- return (mail);
- }
- bool OSOBA::prihlasenie(const string &login0, const string &heslo0) {
- if (login == login0 && heslo == heslo0) {
- otvorene = true;
- }
- else {
- otvorene = false;
- }
- return otvorene;
- }
- //2.uloha
- int dlzkaRetazca(const char *r) {
- int dlzka = 0;
- while (r[dlzka] != '\0') {
- dlzka++;
- }
- return dlzka;
- }
- OSOBA::OSOBA(const OSOBA &o)
- : priezvisko(NULL), meno(NULL), login(NULL), otvorene(o.otvorene), heslo(NULL)
- {
- login = new char[dlzkaRetazca(o.login)+1];
- strcpy(login, o.login);
- heslo = new char[dlzkaRetazca(o.heslo)+1];
- strcpy(heslo, o.heslo);
- setName(o.meno,o.priezvisko);
- }
- STUDENT::STUDENT(const string &login0, const string &heslo0)
- :OSOBA(login0, heslo0),odbor(""),rok(0)
- {
- }
- STUDENT::STUDENT(const STUDENT &student)
- : OSOBA(student), odbor(student.odbor), rok(student.rok)
- {
- }
- bool STUDENT::zmenHeslo(const string &oldH, const string &newH, const string &newH2) {
- if ((jePrihlaseny()) && (newH == newH2) && (oldH == getPassword())) {
- setPassword(newH.c_str());
- return true;
- }
- return false;
- }
- bool STUDENT::vlozOdbor(const string &odbor0, int rok0) {
- if ((jePrihlaseny()) && (odbor0 != "") && (rok0 > 0) && (rok0 < 6)) {
- odbor = odbor0;
- rok = rok0;
- return true;
- }
- return false;
- }
- const string STUDENT::studijnyOdbor() {
- return odbor;
- }
- const int STUDENT::rocnik() {
- return rok;
- }
- //3.uloha
- UCITEL::UCITEL(const string &meno0)
- :pocet(0),zoznam(NULL),meno(meno0)
- {
- zoznam = new string [10];
- };
- UCITEL::UCITEL(const UCITEL &ucitel)
- :pocet(ucitel.pocet),zoznam(NULL),meno(ucitel.meno)
- {
- zoznam = new string [10];
- for (int i = 0; i < pocet; i++) {
- zoznam[i] = ucitel.zoznam[i];
- }
- }
- UCITEL::~UCITEL(){
- if (zoznam != NULL) {
- delete [] zoznam;
- }
- };
- const string UCITEL::zoznamPredmetov(){
- if (pocet == 0) {
- return "Ziadne predmety";
- }
- string predmety = zoznam[0];
- for (int i = 1; i < pocet; i++) {
- predmety += ", ";
- predmety += zoznam[i];
- }
- return predmety;
- };
- bool UCITEL::vlozPredmet(const string &predmet) {
- if (predmet == "" || pocet == 10) {
- return false;
- }
- zoznam[pocet] = predmet;
- pocet++;
- return true;
- }
- bool UCITEL::zmenHesloStudenta(STUDENT &student, const string &newHeslo, const string &newHeslo2){
- if (newHeslo == newHeslo2) {
- strcpy(student.heslo, newHeslo.c_str());
- return true;
- }
- return false;
- }
- //4.uloha
- PREDMET::PREDMET(const string &nazov0, const string &odbor0, int rocnik0, int maxPocet0)
- : nazov(nazov0), studenti(NULL), pocet(0), maxPocet(maxPocet0), rocnik(rocnik0), odbor(odbor0)
- {
- studenti = new STUDENT*[maxPocet];
- }
- PREDMET::~PREDMET() {
- if (studenti != NULL) {
- delete [] studenti;
- }
- }
- bool PREDMET::prihlasenieNaPredmet(STUDENT &student) {
- if (pocet == maxPocet) {
- return false;
- }
- for (int i = 0; i < pocet; i++) {
- if (studenti[i][0].getName() == student.getName()) {
- return false;
- }
- }
- if ( (student.studijnyOdbor() != odbor) || (student.rocnik() < rocnik) ){
- return false;
- }
- studenti[pocet] = NULL;
- studenti[pocet] = new STUDENT(student);
- pocet++;
- return true;
- }
- const int PREDMET::pocetPrijatych() {
- return pocet;
- }
- const string PREDMET::zoznamStudentov() {
- if (pocet == 0) {
- return "";
- }
- string zoznamS = studenti[0][0].getName();
- for (int i = 1; i < pocet; i++){
- zoznamS += ", ";
- zoznamS += studenti[i][0].getName();
- }
- return zoznamS;
- }
- //5.uloha
- PREDMET::PREDMET(const PREDMET &predmet0)
- :nazov(predmet0.nazov),studenti(NULL),pocet(0),maxPocet(predmet0.maxPocet),rocnik(predmet0.rocnik),odbor(predmet0.odbor)
- {
- studenti = new STUDENT*[maxPocet];
- for (int i = 0; i < predmet0.pocet; i++) {
- prihlasenieNaPredmet(predmet0.studenti[i][0]);
- }
- }
- bool PREDMET::vylucStudenta(const string &meno) {
- if ((pocet == 1) && (meno == studenti[0][0].getName())) {
- studenti[0] = NULL;
- pocet--;
- return true;
- }
- bool posuvam = false;
- for (int i = 0; i < pocet; i++){
- if ((posuvam) && (i == pocet-1)) {
- studenti[i-1] = NULL;
- studenti[i-1] = studenti[i];
- studenti[i] = NULL;
- pocet--;
- return true;
- }
- if (posuvam) {
- studenti[i-1] = NULL;
- studenti[i-1] = studenti[i];
- }
- else if (studenti[i][0].getName() == meno) {
- posuvam = true;
- }
- }
- return false;
- }
Add Comment
Please, Sign In to add comment