Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<string.h>
- using namespace std;
- class Karticka{
- protected:
- char smetka[16];
- int pin;
- bool povekjePin;
- static const int P;
- const void copy_obj(const Karticka ©){
- strcpy(this->smetka, copy.smetka);
- this->pin = copy.pin;
- }
- public:
- Karticka(const char* smetka, const int pin){
- strcpy(this->smetka,smetka);
- this->pin=pin;
- this->povekjePin=false;
- }
- Karticka(const Karticka ©){
- this->copy_obj(copy);
- }
- Karticka &operator=(const Karticka ©){
- if(this != ©)
- this->copy_obj(copy);
- return *this;
- }
- virtual ~Karticka(){}
- // дополниете ја класата
- virtual const int tezinaProbivanje(){
- int count = 0;
- int tmp = pin;
- while(tmp){
- count++;
- tmp /= 10;
- }
- return count;
- }
- friend ostream &operator << (ostream &os, Karticka &orig){
- os << orig.smetka << ": " << orig.tezinaProbivanje() << "\n";
- return os;
- }
- const bool getDopolnitelenPin(){
- return this->povekjePin;
- }
- const char * getSmetka(){
- return this->smetka;
- }
- };
- const int Karticka::P = 4;
- //вметнете го кодот за SpecijalnaKarticka
- class SpecijalnaKarticka : public Karticka{
- private:
- int * addPins;
- int noPins;
- const void copy_obj(const SpecijalnaKarticka ©){
- this->addPins = new int[copy.noPins + 1];
- for(int i=0; i<copy.noPins; i++)
- this->addPins[i] = copy.addPins[i];
- this->noPins = copy.noPins;
- }
- public:
- SpecijalnaKarticka(const char* smetka, const int pin) : Karticka(smetka, pin){
- this->addPins = new int[0];
- this->noPins = 0;
- this->povekjePin = true;
- }
- SpecijalnaKarticka(const SpecijalnaKarticka ©) : Karticka(copy){
- this->copy_obj(copy);
- }
- SpecijalnaKarticka &operator=(const SpecijalnaKarticka ©){
- if(this != ©){
- delete [] this->addPins;
- Karticka::operator=(copy);
- this->copy_obj(copy);
- }
- return *this;
- }
- ~SpecijalnaKarticka(){
- delete [] this->addPins;
- }
- const int tezinaProbivanje(){
- return Karticka::tezinaProbivanje() + this->noPins;
- }
- SpecijalnaKarticka &operator+=(int newPin){
- int * tmp = new int[this->noPins + 1];
- for(int i=0; i<this->noPins; i++)
- tmp[i] = this->addPins[i];
- tmp[this->noPins++] = newPin;
- delete [] this->addPins;
- this->addPins = tmp;
- return *this;
- }
- };
- class Banka {
- private:
- char naziv[30];
- Karticka *karticki[20];
- int broj;
- static int limit;
- public:
- Banka(const char *naziv, Karticka** karticki, const int broj ){
- strcpy(this->naziv,naziv);
- for (int i=0;i<broj;i++){
- //ako kartickata ima dopolnitelni pin kodovi
- if (karticki[i]->getDopolnitelenPin()){
- this->karticki[i]=new SpecijalnaKarticka(*dynamic_cast<SpecijalnaKarticka*>(karticki[i]));
- }
- else this->karticki[i]=new Karticka(*karticki[i]);
- }
- this->broj=broj;
- }
- ~Banka(){
- for (int i=0;i<broj;i++) delete karticki[i];
- }
- static void setLIMIT(const int newLimit){
- limit = newLimit;
- }
- //да се дополни класата
- const void pecatiKarticki(){
- cout << "Vo bankata " << this->naziv << " moze da se probijat kartickite:\n";
- for(int i=0; i<this->broj; i++){
- if(this->karticki[i]->tezinaProbivanje() <= limit)
- cout << *this->karticki[i];
- }
- }
- const void dodadiDopolnitelenPin(char * smetka, int novPin){
- for(int i=0; i<this->broj; i++){
- SpecijalnaKarticka * tmp = dynamic_cast<SpecijalnaKarticka *>(this->karticki[i]);
- if(tmp)
- if(!strcmp(this->karticki[i]->getSmetka(), smetka))
- *tmp += novPin;
- }
- }
- };
- int Banka::limit = 7;
- int main(){
- Karticka **niza;
- int n,m,pin;
- char smetka[16];
- bool daliDopolnitelniPin;
- cin>>n;
- niza=new Karticka*[n];
- for (int i=0;i<n;i++){
- cin>>smetka;
- cin>>pin;
- cin>>daliDopolnitelniPin;
- if (!daliDopolnitelniPin)
- niza[i]=new Karticka(smetka,pin);
- else
- niza[i]=new SpecijalnaKarticka(smetka,pin);
- }
- Banka komercijalna("Komercijalna",niza,n);
- for (int i=0;i<n;i++) delete niza[i];
- delete [] niza;
- cin>>m;
- for (int i=0;i<m;i++){
- cin>>smetka>>pin;
- komercijalna.dodadiDopolnitelenPin(smetka,pin);
- }
- Banka::setLIMIT(5);
- komercijalna.pecatiKarticki();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement