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){
- T = t;
- }
- virtual ~Korisnik(){}
- virtual Korisnik& operator+=(char *kod){
- return *this;
- }
- virtual int numerickaTezina(){
- int tez=0;
- for(int i=0; i<strlen(lozinka); i++){
- if(isdigit(lozinka[i]))tez++;
- else if(!isalpha(lozinka[i]))tez+=T;
- }
- return tez;
- }
- friend ostream& operator<<(ostream &o, Korisnik &k){
- return o << k.numerickaTezina() << ":" << k.ime << " ****" << endl;
- }
- char *getIme(){
- return ime;
- }
- bool getDaliBezbednosen(){
- return daliBezbednosen;
- }
- };
- int Korisnik::T=3;
- class SpecijalenKorisnik : public Korisnik{
- char *kod;
- public:
- SpecijalenKorisnik(char* ime,char * lozinka) : Korisnik(ime, lozinka){
- daliBezbednosen = true;
- }
- int numerickaTezina(){
- return Korisnik::numerickaTezina() + strlen(kod);
- }
- SpecijalenKorisnik& operator+=(char *k){
- bool TF = false;
- for(int i=0; i<strlen(k); i++){
- if(!isalpha(k[i]))TF=true;
- }
- try{
- if(!TF) throw BadInputException();
- }
- catch(BadInputException BIE){
- BIE.pecati();
- strcat(k, "123");
- }
- delete [] kod;
- kod = new char[strlen(k)+1];
- strcpy(kod, k);
- return *this;
- }
- friend ostream& operator<<(ostream &o, SpecijalenKorisnik &sk){
- return o << sk.numerickaTezina() << ":" << sk.ime << " ****" << endl;
- }
- };
- class VebStranica {
- private:
- char adresa[30];
- Korisnik *korisnici[20];
- int broj;
- static const int MIN = 5;
- public:
- VebStranica(char *naziv, 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 code.finki.ukim.mk slednite korisnici se najaveni so bezbedna lozinka:\n";
- for(int i=0; i<broj; i++){
- if(korisnici[i]->numerickaTezina()>=MIN){
- cout << *korisnici[i];
- }
- }
- }
- void postaviBezbednosenKod(char *ime, char *kod){
- /*for(int i=0; i<broj; i++){
- if(strcmp(ime, korisnici[i]->getIme())){
- bool tf = true;
- for(int j=0; j<strlen(kod); j++){
- if(!isalpha(kod[i])){
- tf = false;
- }
- if(tf){
- strcat(kod, "123");
- *korisnici[i]+=kod;
- throw BadInputException();
- }
- *korisnici[i]+=kod;
- }
- }
- }*/
- for(int i=0; i<broj; i++){
- if(!strcmp(ime, korisnici[i]->getIme())&&korisnici[i]->getDaliBezbednosen()){
- *dynamic_cast<SpecijalenKorisnik*>(korisnici[i])+=kod;
- }
- }
- }
- };
- 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;
- strana.postaviBezbednosenKod(ime,kod);
- }
- Korisnik::setT(2);
- strana.pecatiKorisnici();
- }
Advertisement
Add Comment
Please, Sign In to add comment