Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- #include <ctype.h>
- #include <string.h>
- #include <math.h>
- using namespace std;
- class Exception{
- public:
- void message()
- {
- cout<<"The game is already in the collection"<<endl;
- }
- };
- class Game
- {
- protected:
- char ime[101];
- double cena;
- bool rasprodazba;
- public:
- Game(char *ime="" , double cena=0 , bool rasprodazba=false)
- {
- strcpy(this->ime,ime);
- this->cena=cena;
- this->rasprodazba=rasprodazba;
- }
- friend ostream &operator<<(ostream &out , Game &g)
- {
- out<<"Game: "<<g.ime<<", regular price: $"<<g.cena;
- if(g.rasprodazba)
- {
- out<<",bought on sale"<<endl;
- }
- return out;
- }
- char *getIme()
- {
- return ime;
- }
- double getCena()
- {
- return cena;
- }
- bool getRasprodazba()
- {
- return rasprodazba;
- }
- friend istream &operator>>(istream &in , Game &g)
- {
- in.get();
- in.getline(g.ime,101);
- in>>g.cena;
- in>>g.rasprodazba;
- return in;
- }
- bool operator==(Game &g)
- {
- return strcmp(ime,g.ime);
- }
- virtual double getPrice()
- {
- if(rasprodazba==true)
- {
- return cena*0.3;
- }
- return cena*1.0;
- }
- };
- class SubscriptionGame:public Game
- {
- private:
- double nadomestok;
- int mesec;
- int godina;
- public:
- SubscriptionGame(char *ime="" , double cena=0 , bool rasprodazba=false, double nadomestok=0 , int mesec=0 , int godina=0):Game(ime,cena,rasprodazba)
- {
- this->nadomestok=nadomestok;
- this->mesec=mesec;
- this->godina=godina;
- }
- friend ostream &operator<<(ostream &out , SubscriptionGame &sg)
- {
- out<<"Game: "<<sg.ime<<", regular price: $"<<sg.cena;
- if(sg.rasprodazba==true)
- {
- out<<", bought on sale";
- }
- out<<", monthly fee: $"<<sg.nadomestok<<", purchased: "<<sg.mesec<<"-"<<sg.godina<<endl;
- return out;
- }
- double getNadomestok()
- {
- return nadomestok;
- }
- int getMesec()
- {
- return mesec;
- }
- int getGodina()
- {
- return godina;
- }
- friend istream &operator>>(istream &in , SubscriptionGame &sg)
- {
- in.get();
- in.getline(sg.ime,101);
- in>>sg.cena>>sg.rasprodazba>>sg.nadomestok>>sg.mesec>>sg.godina;
- return in;
- }
- double getPrice()
- {
- if(2018==godina)
- {
- int tempMesec=mesec;
- int brojac=0;
- while(tempMesec<5)
- {
- brojac++;
- tempMesec++;
- }
- return (brojac*nadomestok)+cena;
- }
- else
- {
- int brojac=1;
- int tempMesec=mesec;
- int tempGodina=godina;
- while(tempMesec<=12)
- {
- if(tempMesec==12)
- {
- tempGodina+=1;
- if(tempGodina!=2018)
- {
- tempMesec=1;
- }
- else
- {
- tempMesec=1;
- while(tempMesec<5)
- {
- brojac++;
- tempMesec++;
- }
- return(brojac*nadomestok)+cena;
- }
- }
- brojac++;
- tempMesec++;
- }
- }
- }
- };
- class User
- {
- private:
- char ime[101];
- Game **igri;
- int n;
- public:
- User(const char *ime="")
- {
- strcpy(this->ime,ime);
- igri=new Game*[0];
- n=0;
- }
- User(const User &u)
- {
- strcpy(ime,u.ime);
- n=u.n;
- for(int i=0;i<n;i++)
- {
- igri[i]=u.igri[i];
- }
- }
- User &operator=(const User &u)
- {
- if(this!=&u)
- {
- strcpy(ime,u.ime);
- n=u.n;
- delete[]igri;
- for(int i=0;i<n;i++)
- {
- igri[i]=u.igri[i];
- }
- }
- return *this;
- }
- ~User()
- {
- delete[]igri;
- }
- User &operator+=(Game &g)
- {
- for(int i=0;i<n;i++)
- {
- if(((*igri[i])==g)==0)
- throw Exception();
- }
- Game **temp=new Game*[n+1];
- for(int i=0;i<n;i++)
- {
- temp[i]=igri[i];
- }
- temp[n++]=&g;
- delete[]igri;
- igri=temp;
- return *this;
- }
- double total_spent()
- {
- double total=0;
- for(int i=0;i<n;i++)
- {
- total+=igri[i]->getPrice();
- }
- return total;
- }
- friend ostream &operator<<(ostream &out , User &u)
- {
- out<<endl;
- out<<"User: "<<u.ime<<endl;
- for(int i=0;i<u.n;i++)
- {
- out<<"- Game: "<<u.igri[i]->getIme()<<", regular price: $"<<u.igri[i]->getCena();
- if(u.igri[i]->getRasprodazba()==true)
- out<<", bought on sale";
- }
- int i;
- SubscriptionGame *temp=dynamic_cast<SubscriptionGame*>(u.igri[i]);
- {
- if(temp!=0)
- {
- out<<", monthly fee: $"<<temp->getNadomestok()<<", purchased: "<<temp->getMesec()<<"-"<<temp->getGodina()<<endl;
- }
- out<<endl;
- }
- return out;
- }
- };
Add Comment
Please, Sign In to add comment