Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<string.h>
- using namespace std;
- class BadInputException {
- public:
- void pecati() {
- cout<<"Bezbednosniot kod e vo losh format"<<endl;
- }
- };
- class Korisnik {
- protected:
- char ime[30];
- char lozinka[10];
- bool daliBezbednosen;
- static int T;
- public:
- Korisnik(char* ime,char *lozinka) {
- strcpy(this->ime,ime);
- strcpy(this->lozinka,lozinka);
- this->daliBezbednosen=false;
- }
- static void setT(int T) {
- Korisnik::T=T;
- }
- ~Korisnik() {}
- virtual int numerickaTezina() {
- int tezina=0;
- int i=0;
- while(lozinka[i]!='\0') {
- //if(isalpha(*lozinka))!!! ne mora da rabotis so pokazuvaci, gledam so niv gresis
- if(isalpha(lozinka[i]))//!!!vaka treba
- {
- tezina+=0;
- } else if(isdigit(lozinka[i])){///!!!
- tezina+=1;
- } else {
- tezina+=Korisnik::T;
- }
- i++;
- }
- return tezina;
- }
- bool getdaliBezbednosen() {
- return daliBezbednosen;
- }
- friend ostream &operator<<(ostream &out,Korisnik &k) {
- out<<k.numerickaTezina()<<":"<<k.ime<<" ****";
- return out;
- }
- char *getIme() {
- return ime;
- }
- };
- class SpecijalenKorisnik:public Korisnik {
- private:
- char *bezbednosenKod;
- public:
- SpecijalenKorisnik(char* ime,char *lozinka):Korisnik(ime,lozinka) {
- //this->bezbednosenKod=new char[strlen(bezbednosenKod)+1];!!! - tuka pravis random prostor za bezbednosen kod?
- //strcpy(this->bezbednosenKod,bezbednosenKod);//!!!nemas vlezen argument za da go pravis ova
- bezbednosenKod = new char[0];//!!!vaka treba
- daliBezbednosen =true;//!!!treba da go postavis na true
- }
- ~SpecijalenKorisnik() {
- delete [] bezbednosenKod;
- }
- int numerickaTezina() {
- return Korisnik::numerickaTezina()+strlen(bezbednosenKod);
- }
- SpecijalenKorisnik &operator+=(char *kod) {
- int i=0,flag=0;
- for(int i=0;i<strlen(kod);i++)//!!!vaka ti e polesno
- {
- if(isdigit(kod[i])) {
- flag=1;
- break;
- }
- }
- if(!flag) {
- throw BadInputException();
- } else {
- delete []bezbednosenKod; //!!!prvo izbrisi toa sto imas vo bezbednosen kod
- bezbednosenKod = new char [strlen(kod)+1];//!!!pa alociras prostor
- strcpy(this->bezbednosenKod,kod);
- return *this;
- }
- }
- };
- int Korisnik::T=3;
- class VebStranica {
- private:
- char adresa[30];
- Korisnik *korisnici[20];
- int broj;
- const static int MIN;
- public:
- VebStranica(const char *adresa, Korisnik** korisnici,int broj ) {
- strcpy(this->adresa,adresa);
- for (int i=0; i<broj; i++) {
- //ako korisnikot ima bezbednosen kod
- if (korisnici[i]->getdaliBezbednosen()) {
- this->korisnici[i]=new SpecijalenKorisnik(*dynamic_cast<SpecijalenKorisnik*>(korisnici[i]));
- } else this->korisnici[i]=new Korisnik(*korisnici[i]);
- }
- this->broj=broj;
- }
- ~VebStranica() {
- for (int i=0; i<broj; i++) delete korisnici[i];
- }
- void pecatiKorisnici() {
- cout<<"Na stranicata "<<adresa<<" slednite korisnici se najaveni so bezbedna lozinka:"<<endl;
- for(int i=0; i<broj; i++) {
- if(korisnici[i]->numerickaTezina()>=MIN) { //!!!dali e lozinkata bezbedna, a bezbedna e ako tezinata e pogolema od MIN
- cout<<*korisnici[i];
- }
- }
- }
- void postaviBezbednosenKod(char * korisnicko_ime, char *kod) {
- for(int i=0; i<broj; i++) {
- //korisnici[i]+=*kod;nemoze ova vaka , ne raboti so pokazuvaci +=
- SpecijalenKorisnik *s = dynamic_cast<SpecijalenKorisnik*>(korisnici[i]);
- if(s!=0)
- {
- if((strcmp(korisnici[i]->getIme(),korisnicko_ime))==0)
- *s+=kod;
- }
- }
- }
- };
- const 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 b) {
- b.pecati();
- strcat(kod,"123");
- strana.postaviBezbednosenKod(ime,kod);
- }
- }
- Korisnik::setT(2);
- strana.pecatiKorisnici();
- return 0;
- }
Add Comment
Please, Sign In to add comment