Guest User

Untitled

a guest
May 25th, 2018
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 8.11 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <cstring>
  4.  
  5. using namespace std;
  6.  
  7. #if !defined( _RIESENIE_H_ )
  8. #define _RIESENIE_H_
  9.  
  10. //1.uloha
  11. class OSOBA {
  12.     char *priezvisko;
  13.     char *meno;
  14.     char *login;
  15.     bool otvorene;
  16.     friend class UCITEL;
  17.     char *heslo;
  18.   protected:
  19.     bool jePrihlaseny() {return otvorene;};
  20.     const string getPassword() {return heslo;};
  21.     void setPassword(const string &passw);
  22.     const string kodovanieHesla(const string &password);
  23.   public:
  24.     OSOBA(const string &login0, const string &heslo0);
  25.     ~OSOBA();
  26.     bool setName(const string &meno0, const string &priezvisko0);
  27.     const string getName();
  28.     const string getMail();
  29.     bool prihlasenie(const string &login0, const string &heslo0);
  30. //2.uloha
  31.     OSOBA(const OSOBA &o);
  32. };
  33. class STUDENT : public OSOBA {
  34.     string odbor;
  35.     int rok;
  36.   public:
  37.     STUDENT(const string &login0, const string &heslo0);
  38.     STUDENT(const STUDENT &student);
  39.     bool zmenHeslo(const string &oldH, const string &newH, const string &newH2);
  40.     bool vlozOdbor(const string &odbor0, int rok0);
  41.     const string studijnyOdbor();
  42.     const int rocnik();
  43. };
  44. //3.uloha
  45. class UCITEL {
  46.     int pocet;
  47.     string *zoznam;
  48.     string meno;
  49.   public:
  50.     UCITEL(const string &meno0);
  51.     UCITEL(const UCITEL &ucitel);
  52.     ~UCITEL();
  53.     const string menoUcitela() { return meno; };
  54.     bool vlozPredmet(const string &predmet0);
  55.     const string zoznamPredmetov();
  56.     bool zmenHesloStudenta(STUDENT &student
  57.       , const string &newHeslo, const string &newHeslo2);
  58. };
  59. //4.uloha
  60. class PREDMET {
  61.     string nazov;
  62.     STUDENT **studenti;
  63.     int pocet;
  64.     int maxPocet;
  65.     int rocnik;
  66.     string odbor;
  67.   public:
  68.     PREDMET(const string &nazov0, const string &odbor0, int rocnik0, int maxPocet0);
  69.     ~PREDMET();
  70.     bool prihlasenieNaPredmet(STUDENT &student);
  71.     const int pocetPrijatych();
  72.     const string zoznamStudentov();
  73. //5.uloha
  74.     PREDMET(const PREDMET &predmet0);
  75.     bool vylucStudenta(const string &meno);
  76. };
  77. #endif
  78.  
  79. bool DUMMY_BOOL = true;
  80. int DUMMY_INT = 0;
  81. string DUMMY_STRING = "";
  82.  
  83. //1.uloha
  84. OSOBA::OSOBA(const string &login0, const string &heslo0)
  85.   : priezvisko(NULL), meno(NULL), login(NULL), otvorene(false), heslo(NULL)
  86.  {
  87.   if (login0.length() > 0) {
  88.       login = new char[login0.length()+1];
  89.      strcpy(login, login0.c_str());
  90.   }
  91.   else {
  92.     login = new char[20];
  93.     strcpy(login, "PrazdnyLogin");
  94.   }
  95.   setPassword(heslo0);
  96.   priezvisko = new char[10];
  97.   strcpy(priezvisko, "Nezadane");
  98.   meno = new char[10];
  99.   strcpy(meno, "Nezadane");
  100. }
  101. OSOBA::~OSOBA() {
  102.   if (login[0] != '\0') {
  103.       login = NULL;
  104.       delete [] login;
  105.       heslo = NULL;
  106.       delete [] heslo;
  107.       meno = NULL;
  108.       delete [] meno;
  109.       priezvisko = NULL;
  110.       delete [] priezvisko;
  111.   }
  112. }
  113. const string OSOBA::kodovanieHesla(const string &password) {
  114.   return DUMMY_STRING;
  115. }
  116. void OSOBA::setPassword(const string &passw) {
  117.   heslo = new char[passw.length()+1];
  118.   strcpy(heslo,passw.c_str());
  119. }
  120. bool OSOBA::setName(const string &meno0, const string &priezvisko0) {
  121.   if (!otvorene) {
  122.       return false;
  123.   }
  124.   meno = NULL;
  125.   meno = new char[meno0.length()+1];
  126.   priezvisko = NULL;
  127.   priezvisko = new char[priezvisko0.length()+1];
  128.   if (meno0.length() > 0) {
  129.       strcpy(meno, meno0.c_str());
  130.   }
  131.   else {
  132.       strcpy(meno, "Nezadane");
  133.   }
  134.   if (priezvisko0.length() > 0) {
  135.       strcpy(priezvisko, priezvisko0.c_str());
  136.   }
  137.   else {
  138.       strcpy(priezvisko, "Nezadane");
  139.   }
  140.   return true;
  141. }
  142. const string OSOBA::getName() {
  143.   string celeMeno;
  144.   celeMeno = priezvisko;
  145.   celeMeno += " ";
  146.   celeMeno += meno;
  147.   return (celeMeno);
  148. }
  149. const string OSOBA::getMail() {
  150.     string mail;
  151.     mail = priezvisko;
  152.     mail += ".";
  153.     mail += meno;
  154.     mail += "@fmfi.uk.sk";
  155.     return (mail);
  156. }
  157. bool OSOBA::prihlasenie(const string &login0, const string &heslo0) {
  158.   if (login == login0 && heslo == heslo0) {
  159.       otvorene = true;
  160.   }
  161.   else {
  162.       otvorene = false;
  163.   }
  164.   return otvorene;
  165. }
  166. //2.uloha
  167. int dlzkaRetazca(const char *r) {
  168.   int dlzka = 0;
  169.   while (r[dlzka] != '\0') {
  170.       dlzka++;
  171.   }
  172.   return dlzka;
  173. }
  174. OSOBA::OSOBA(const OSOBA &o)
  175.  : priezvisko(NULL), meno(NULL), login(NULL), otvorene(o.otvorene), heslo(NULL)
  176. {
  177.   login = new char[dlzkaRetazca(o.login)+1];
  178.   strcpy(login, o.login);
  179.   heslo = new char[dlzkaRetazca(o.heslo)+1];
  180.   strcpy(heslo, o.heslo);
  181.   setName(o.meno,o.priezvisko);
  182. }
  183.  
  184. STUDENT::STUDENT(const string &login0, const string &heslo0)
  185.   :OSOBA(login0, heslo0),odbor(""),rok(0)
  186. {
  187. }
  188. STUDENT::STUDENT(const STUDENT &student)
  189.   : OSOBA(student), odbor(student.odbor), rok(student.rok)
  190. {
  191. }
  192. bool STUDENT::zmenHeslo(const string &oldH, const string &newH, const string &newH2) {
  193.   if ((jePrihlaseny()) && (newH == newH2) && (oldH == getPassword())) {
  194.       setPassword(newH.c_str());
  195.       return true;
  196.   }
  197.   return false;
  198. }
  199. bool STUDENT::vlozOdbor(const string &odbor0, int rok0) {
  200.   if ((jePrihlaseny()) && (odbor0 != "") && (rok0 > 0) && (rok0 < 6)) {
  201.       odbor = odbor0;
  202.       rok = rok0;
  203.       return true;
  204.   }
  205.   return false;
  206. }
  207. const string STUDENT::studijnyOdbor() {
  208.   return odbor;
  209. }
  210. const int STUDENT::rocnik() {
  211.   return rok;
  212. }
  213. //3.uloha
  214. UCITEL::UCITEL(const string &meno0)
  215.   :pocet(0),zoznam(NULL),meno(meno0)
  216. {
  217.     zoznam = new string [10];
  218. };
  219. UCITEL::UCITEL(const UCITEL &ucitel)
  220.   :pocet(ucitel.pocet),zoznam(NULL),meno(ucitel.meno)
  221. {
  222.     zoznam = new string [10];
  223.     for (int i = 0; i < pocet; i++) {
  224.         zoznam[i] = ucitel.zoznam[i];
  225.     }
  226. }
  227. UCITEL::~UCITEL(){
  228.     if (zoznam != NULL) {
  229.         delete [] zoznam;
  230.     }
  231. };
  232. const string UCITEL::zoznamPredmetov(){
  233.   if (pocet == 0) {
  234.       return "Ziadne predmety";
  235.   }
  236.   string predmety = zoznam[0];
  237.   for (int i = 1; i < pocet; i++) {
  238.       predmety += ", ";
  239.       predmety += zoznam[i];
  240.   }
  241.   return predmety;
  242. };
  243. bool UCITEL::vlozPredmet(const string &predmet) {
  244.   if (predmet == "" || pocet == 10) {
  245.       return false;
  246.   }
  247.   zoznam[pocet] = predmet;
  248.   pocet++;
  249.   return true;
  250. }
  251. bool UCITEL::zmenHesloStudenta(STUDENT &student, const string &newHeslo, const string &newHeslo2){
  252.   if (newHeslo == newHeslo2) {
  253.       strcpy(student.heslo, newHeslo.c_str());
  254.       return true;
  255.   }
  256.   return false;
  257. }
  258. //4.uloha
  259. PREDMET::PREDMET(const string &nazov0, const string &odbor0, int rocnik0, int maxPocet0)
  260.  : nazov(nazov0), studenti(NULL), pocet(0), maxPocet(maxPocet0), rocnik(rocnik0), odbor(odbor0)
  261. {
  262.     studenti = new STUDENT*[maxPocet];
  263. }
  264. PREDMET::~PREDMET() {
  265.   if (studenti != NULL) {
  266.       delete [] studenti;
  267.   }
  268. }
  269. bool PREDMET::prihlasenieNaPredmet(STUDENT &student) {
  270.   if (pocet == maxPocet) {
  271.       return false;
  272.   }
  273.   for (int i = 0; i < pocet; i++) {
  274.       if (studenti[i][0].getName() == student.getName()) {
  275.           return false;
  276.       }
  277.   }
  278.   if ( (student.studijnyOdbor()  != odbor) || (student.rocnik() < rocnik) ){
  279.       return false;
  280.   }
  281.   studenti[pocet] = NULL;
  282.   studenti[pocet] = new STUDENT(student);
  283.   pocet++;
  284.   return true;
  285. }
  286. const int PREDMET::pocetPrijatych() {
  287.     return pocet;
  288. }
  289. const string PREDMET::zoznamStudentov() {
  290.   if (pocet == 0) {
  291.       return "";
  292.   }
  293.   string zoznamS = studenti[0][0].getName();
  294.   for (int i = 1; i < pocet; i++){
  295.      zoznamS += ", ";
  296.      zoznamS += studenti[i][0].getName();
  297.   }
  298.   return zoznamS;
  299. }
  300. //5.uloha
  301. PREDMET::PREDMET(const PREDMET &predmet0)
  302.  :nazov(predmet0.nazov),studenti(NULL),pocet(0),maxPocet(predmet0.maxPocet),rocnik(predmet0.rocnik),odbor(predmet0.odbor)
  303. {
  304.     studenti = new STUDENT*[maxPocet];
  305.     for (int i = 0; i < predmet0.pocet; i++) {
  306.         prihlasenieNaPredmet(predmet0.studenti[i][0]);
  307.     }
  308. }
  309. bool PREDMET::vylucStudenta(const string &meno) {
  310.    if ((pocet == 1) && (meno == studenti[0][0].getName())) {
  311.        studenti[0] = NULL;
  312.        pocet--;
  313.        return true;
  314.    }
  315.    bool posuvam = false;
  316.    for (int i = 0; i < pocet; i++){
  317.       if ((posuvam) && (i == pocet-1)) {
  318.           studenti[i-1] = NULL;
  319.           studenti[i-1] = studenti[i];
  320.           studenti[i] = NULL;
  321.           pocet--;
  322.           return true;
  323.       }
  324.       if (posuvam) {
  325.           studenti[i-1] = NULL;
  326.           studenti[i-1] = studenti[i];
  327.       }
  328.       else if (studenti[i][0].getName() == meno) {
  329.           posuvam = true;
  330.       }
  331.    }
  332.   return false;
  333. }
Add Comment
Please, Sign In to add comment