Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 1. #include <iostream>
- #include <cstring>
- #include <cctype>
- using namespace std;
- class Korisnik
- {
- public:
- char username[20];
- char password[20];
- bool code;
- static int T;
- public:
- Korisnik(char username[20]="", char password[20]="", bool code=false)
- {
- strcpy(this->username, username);
- strcpy(this->password, password);
- this->code = code;
- }
- static void setT(int tezina)
- {
- Korisnik::T = tezina;
- }
- char *getUsername(){return this->username;}
- virtual int presmetajTezina()
- {
- int n = strlen(this->password);
- int suma = 0;
- for(int i=0; i<n; i++)
- {
- char current = this->password[i];
- if((current >= 'a'&¤t <='z') || (current >= 'A' && current <='Z'))
- {
- suma += 0;
- }
- else if((current >= '0' && current <='9'))
- {
- suma += 1;
- }
- else
- {
- suma += Korisnik::T;
- }
- }
- return suma;
- }
- friend ostream& operator<<(ostream &out, Korisnik &k)
- {
- out << k.presmetajTezina() << ":" << k.username << " ****" << endl;
- return out;
- }
- ~Korisnik()
- {
- }
- };
- int Korisnik::T;
- class BadInputException
- {
- public:
- char *msg()
- {
- return "Bezbednosniot kod e vo losh format";
- }
- };
- class SpecijalenKorisnik : public Korisnik
- {
- public:
- char * securityCode;
- public:
- SpecijalenKorisnik(char username[20]="", char password[20]="", bool code=false, char *securityCode=""):Korisnik(username, password, code)
- {
- this->securityCode = new char[strlen(securityCode) + 1];
- strcpy(this->securityCode, securityCode);
- }
- SpecijalenKorisnik &operator+=(char *securityCode)
- {
- bool flag = true;
- int n = strlen(securityCode);
- for(int i=0;i<n;i++)
- {
- if(!isalpha(securityCode[i]))
- {
- flag = false;
- break;
- }
- }
- if(flag)
- {
- throw BadInputException();
- }
- delete this->securityCode;
- this->securityCode = new char[strlen(securityCode) + 1];
- strcpy(this->securityCode, securityCode);
- return *this;
- }
- int presmetajTezina()
- {
- int suma = Korisnik::presmetajTezina();
- return suma + strlen(securityCode);
- }
- friend ostream& operator<<(ostream &out, SpecijalenKorisnik &k)
- {
- out << k.presmetajTezina() << ":" << k.username << " ****" << endl;
- return out;
- }
- ~SpecijalenKorisnik()
- {
- delete this->securityCode;
- }
- };
- class VebStranica
- {
- private:
- char url[30];
- Korisnik *korisnici[20];
- int n;
- static int MIN;
- public:
- VebStranica(char url[30]="", Korisnik *korisnici[20]=NULL, int n=0)
- {
- strcpy(this->url, url);
- for(int i=0;i<n;i++)
- {
- SpecijalenKorisnik *sk = dynamic_cast<SpecijalenKorisnik *> (korisnici[i]);
- if(sk)
- this->korisnici[i] = new SpecijalenKorisnik(sk->username, sk->password, sk->code, sk->securityCode);
- else
- this->korisnici[i] = new Korisnik(korisnici[i]->username, korisnici[i]->password, korisnici[i]->code);
- }
- this->n = n;
- }
- bool bezbednaLozinka(Korisnik *k)
- {
- if(k->presmetajTezina() >= MIN)
- return true;
- return false;
- }
- void pecatiKorisnici()
- {
- cout << "Na stranicata " << this->url << " slednite korisnici se najaveni so bezbedna lozinka:" << endl;
- for(int i=0;i<this->n;i++)
- {
- if(bezbednaLozinka(this->korisnici[i]))
- cout << *(this->korisnici[i]);
- }
- }
- void postaviBezbednosenKod(char *username, char *code)
- {
- for(int i=0;i<this->n;i++)
- {
- if(strcmp(this->korisnici[i]->getUsername(), username)==0)
- {
- SpecijalenKorisnik *sk = dynamic_cast<SpecijalenKorisnik*>(korisnici[i]);
- if(sk)
- {
- *(sk)+=code;
- }
- }
- }
- }
- };
- int VebStranica::MIN = 5;
- int main()
- {
- Korisnik **niza;
- int n,m;
- char ime[30],kod[10],lozinka[10];
- bool daliBezbednosen;
- cin>>n;
- niza=new Korisnik*[n];
- for (int i=0; i<n; i++)
- {
- cin>>ime;
- cin>>lozinka;
- cin>>daliBezbednosen;
- if (!daliBezbednosen)
- {
- niza[i]=new Korisnik(ime,lozinka);
- }
- else
- niza[i]=new SpecijalenKorisnik(ime,lozinka);
- }
- VebStranica strana("code.finki.ukim.mk",niza,n);
- for (int i=0; i<n; i++) delete niza[i];
- delete [] niza;
- cin>>m;
- for (int i=0; i<m; i++)
- {
- cin>>ime>>kod;
- try
- {
- strana.postaviBezbednosenKod(ime,kod);
- }catch(BadInputException e)
- {
- cout << e.msg() << endl;
- strcat(kod, "123");
- strana.postaviBezbednosenKod(ime, kod);
- }
- }
- Korisnik::setT(2);
- //cout << "PECATI KORISNICI" << endl;
- strana.pecatiKorisnici();
- return 0;
- }
- 2. #include<iostream>
- #include<cstring>
- using namespace std;
- class IndexOutOfBoundException
- {
- public:
- void print()
- {
- cout<<"Ne moze da se vnesat uste dopolnitelni aktivnosti"<<endl;
- }
- };
- class UcesnikKurs
- {
- protected:
- char ime[20];
- int finalenIspit;
- bool daliAktivnosti;
- public:
- UcesnikKurs(char ime[20]="",int finalenIspit=0,bool daliAktivnosti=false)
- {
- strcpy(this->ime,ime);
- this->finalenIspit=finalenIspit;
- this->daliAktivnosti=daliAktivnosti;
- }
- friend ostream &operator<<(ostream &out,UcesnikKurs &u)
- {
- out<<u.ime<<" - "<<u.osvoeniPoeni()<<endl;
- return out;
- }
- virtual int osvoeniPoeni()
- {
- return this->finalenIspit;
- }
- bool getDaliAktivnosti()
- {
- return this->daliAktivnosti;
- }
- int getFinalenIspit()
- {
- return this->finalenIspit;
- }
- char *getIme()
- {
- return this->ime;
- }
- };
- class UcesnikKursDopolnitelen : public UcesnikKurs
- {
- private:
- int brAktivnosti;
- int *poeniAktivnosti;
- const static int M;
- public:
- int getBrAktivnosti()
- {
- return this->brAktivnosti;
- }
- int *getPoeniAktivnosti()
- {
- return this->poeniAktivnosti;
- }
- UcesnikKursDopolnitelen(char ime[20]="",int finalenIspit=0,bool daliAktivnosti=false,int brAktivnosti=0,int *poeniAktivnosti=0):UcesnikKurs(ime,finalenIspit,daliAktivnosti)
- {
- for(int i=0;i<brAktivnosti;i++)
- {
- this->poeniAktivnosti[i]=poeniAktivnosti[i];
- }
- this->brAktivnosti=brAktivnosti;
- }
- int osvoeniPoeni()
- {
- int suma=0;
- for(int i=0;i<this->brAktivnosti;i++)
- {
- suma+=poeniAktivnosti[i];
- }
- return this->finalenIspit*0.8+suma;
- }
- friend ostream &operator<<(ostream &out,UcesnikKursDopolnitelen &k)
- {
- out<<k.ime<<" - "<<k.osvoeniPoeni()<<endl;
- return out;
- }
- UcesnikKursDopolnitelen &operator+=(int p)
- {
- if(this->brAktivnosti>=M)
- throw IndexOutOfBoundException();
- int *tmp=new int[this->brAktivnosti+1];
- for(int i=0;i<this->brAktivnosti;i++)
- {
- tmp[i]=poeniAktivnosti[i];
- }
- delete [] this->poeniAktivnosti;
- poeniAktivnosti=tmp;
- poeniAktivnosti[brAktivnosti]=p;
- this->brAktivnosti++;
- return *this;
- }
- };
- const int UcesnikKursDopolnitelen::M=5;
- class Kurs
- {
- private:
- char ime[30];
- UcesnikKurs *ucesnici[10];
- int n;
- static int P;
- public:
- static void setP(int pp)
- {
- P=pp;
- }
- Kurs(char *ime, UcesnikKurs** ucesnici,int n )
- {
- strcpy(this->ime,ime);
- for (int i=0;i<n;i++)
- {
- UcesnikKursDopolnitelen *u=dynamic_cast<UcesnikKursDopolnitelen*>(ucesnici[i]);
- if (u){
- this->ucesnici[i]=new UcesnikKursDopolnitelen(*dynamic_cast<UcesnikKursDopolnitelen*>(ucesnici[i]));
- }
- else this->ucesnici[i]=new UcesnikKurs(*ucesnici[i]);
- }
- this->n=n;
- }
- void pecatiUcesnici()
- {
- cout<<"Na kursot "<<this->ime<<" polozeni se:"<<endl;
- for(int i=0;i<this->n;i++)
- {
- if(ucesnici[i]->osvoeniPoeni() >= P)
- cout<<*(ucesnici[i]);
- }
- }
- void dodadiPoeniDopolnitelnaAktivnost(char *name,int points)
- {
- for(int i=0;i<this->n;i++)
- {
- if(strcmp(ucesnici[i]->getIme(),name)==0)
- {
- UcesnikKursDopolnitelen *u=dynamic_cast<UcesnikKursDopolnitelen*>(ucesnici[i]);
- if(u)
- {
- *(u)+=points;
- }
- }
- }
- }
- };
- int Kurs::P=50;
- int main(){
- UcesnikKurs **niza;
- int n,m,poeni;
- char ime[10];
- bool daliDopolnitelnaAktivnost;
- cin>>n;
- niza=new UcesnikKurs*[n];
- for (int i=0;i<n;i++){
- cin>>ime;
- cin>>poeni;
- cin>>daliDopolnitelnaAktivnost;
- if (!daliDopolnitelnaAktivnost)
- niza[i]=new UcesnikKurs(ime,poeni);
- else
- niza[i]=new UcesnikKursDopolnitelen(ime,poeni);
- }
- Kurs programiranje("Programiranje",niza,n);
- for (int i=0;i<n;i++) delete niza[i];
- delete [] niza;
- cin>>m;
- for (int i=0;i<m;i++){
- cin>>ime>>poeni;
- try{
- programiranje.dodadiPoeniDopolnitelnaAktivnost(ime,poeni);
- }
- catch(IndexOutOfBoundException e)
- {
- e.print();
- programiranje.dodadiPoeniDopolnitelnaAktivnost(ime,poeni);
- }
- }
- Kurs::setP(60);
- programiranje.pecatiUcesnici();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement