Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- using namespace std;
- enum tipC{basic=0,premium=1};
- class NotValidYear{
- private:
- char msg[100];
- public:
- NotValidYear(const char *msg="")
- {
- strcpy(this->msg,msg);
- }
- void print()
- {
- cout<<msg<<endl;
- }
- };
- class Chlen{
- private:
- char ime[100];
- tipC tip;
- static int osnoven_popust;
- const static int dopolnitelen_popust;
- int godina;
- public:
- Chlen(const char *ime="",tipC tip=(tipC)0,int godina=0)
- {
- strcpy(this->ime,ime);
- this->tip=tip;
- this->godina=godina;
- }
- Chlen(const Chlen &c)
- {
- strcpy(this->ime,c.ime);
- this->tip=c.tip;
- this->godina=c.godina;
- }
- static void setPopust1(int number)
- {
- osnoven_popust=number;
- }
- static int getPopust1()
- {
- return osnoven_popust;
- }
- static int getPopust2()
- {
- return dopolnitelen_popust;
- }
- tipC getType()
- {
- return tip;
- }
- friend ostream &operator <<(ostream &out,Chlen &c)
- {
- out<<c.ime<<endl;
- if(c.getType()==0)
- {
- out<<"basic "<<c.godina<<" "<<c.osnoven_popust<<endl;
- }
- if(c.getType()==1)
- {
- out<<"premium "<<c.godina<<" "<<c.osnoven_popust+c.dopolnitelen_popust<<endl;
- }
- return out;
- }
- int getGodina()
- {
- return godina;
- }
- };
- int Chlen::osnoven_popust=10;
- const int Chlen::dopolnitelen_popust=15;
- class FINKI_club{
- private:
- int osnovna_cena_clan;
- Chlen *clenovi;
- int number;
- public:
- FINKI_club()
- {
- this->osnovna_cena_clan=0;
- }
- FINKI_club(int osnovna_cena_clan)
- {
- this->osnovna_cena_clan=osnovna_cena_clan;
- this->clenovi = new Chlen[0];
- this->number=0;
- }
- FINKI_club(const FINKI_club &fc)
- {
- this->osnovna_cena_clan=fc.osnovna_cena_clan;
- this->clenovi = new Chlen[fc.number];
- this->number=fc.number;
- for(int i=0;i<fc.number;i++)
- {
- this->clenovi[i]=fc.clenovi[i];
- }
- }
- void setChlenovi(Chlen *novi,int n)
- {
- this->clenovi = new Chlen[n];
- this->number=n;
- for(int i=0;i<number;i++)
- {
- this->clenovi[i]=novi[i];
- }
- }
- FINKI_club &operator-=(int year)
- {
- if(year<0)
- {
- throw NotValidYear("Vnesena e negativna vrednost za godinata!");
- }
- int brojac=0;
- for(int i=0;i<number;i++)
- {
- if(clenovi[i].getGodina()==year)
- brojac++;
- }
- Chlen *tmp = new Chlen[brojac];
- brojac=0;
- for(int i=0;i<number;i++)
- {
- if(clenovi[i].getGodina()==year)
- {
- tmp[brojac++]=clenovi[i];
- }
- }
- delete [] clenovi;
- clenovi = tmp;
- number = brojac;
- return *this;
- }
- int getOsnovna()
- {
- return osnovna_cena_clan;
- }
- friend ostream &operator <<(ostream &out,FINKI_club &fc)
- {
- for(int i=0;i<fc.number;i++)
- {
- out<<fc.clenovi[i];
- }
- return out;
- }
- void naplatiChlenarina()
- {
- for(int i=0;i<number;i++)
- {
- cout<<clenovi[i];
- if(clenovi[i].getType()==0)
- {
- float popust = clenovi[i].getPopust1();
- cout<<osnovna_cena_clan-(osnovna_cena_clan*popust/100)<<endl;
- }
- else if(clenovi[i].getType()==1)
- {
- float popust = (clenovi[i].getPopust1()+clenovi[i].getPopust2());
- cout<<osnovna_cena_clan-(osnovna_cena_clan*popust/100)<<endl;
- }
- }
- }
- };
- int main(){
- int testCase;
- cin >> testCase;
- char ime[100];
- int tipChlen;
- int popust;
- int god;
- if (testCase == 1){
- cout << "===== Testiranje na klasata Chlen ======" << endl;
- cin.get();
- cin.getline(ime,100);
- cin >> tipChlen;
- cin >> god;
- cout << "===== CONSTRUCTOR ======" << endl;
- Chlen c(ime, (tipC) tipChlen, god);
- cout << c;
- }
- if (testCase == 2){
- cout << "===== Testiranje na static clenovi ======" << endl;
- cin.get();
- cin.getline(ime,100);
- cin >> tipChlen;
- cin >> god;
- cout << "===== CONSTRUCTOR ======" << endl;
- Chlen c(ime, (tipC) tipChlen, god);
- cout << c;
- c.setPopust1(5);
- cout << c;
- }
- if (testCase == 3){
- cout << "===== Testiranje na klasata FINKI-club ======" << endl;
- FINKI_club fc;
- int n;
- cin >> n;
- Chlen chlen[100];
- for(int i = 0; i < n; ++i) {
- cin.get();
- cin.getline(ime,100);
- cin >> tipChlen;
- cin >> god;
- Chlen c(ime, (tipC) tipChlen, god);
- chlen[i] = c;
- }
- fc.setChlenovi(chlen, n);
- cout << fc <<endl;
- }
- if (testCase == 4){
- cout << "===== Testiranje na operatorot -= ======" << endl;
- FINKI_club fc;
- int n;
- cin >> n;
- Chlen chlen[100];
- for(int i = 0; i < n; ++i) {
- cin.get();
- cin.getline(ime,100);
- cin >> tipChlen;
- cin >> god;
- Chlen c(ime, (tipC) tipChlen, god);
- chlen[i] = c;
- }
- fc.setChlenovi(chlen, n);
- cout << "OPERATOR -=" << endl;
- int godina;
- cin >> godina;
- fc-=godina;
- cout << fc;
- }
- if (testCase == 5){
- cout << "===== Testiranje na operatorot -= (so iskluchok) ======" << endl;
- FINKI_club fc;
- int n;
- cin >> n;
- Chlen chlen[100];
- for(int i = 0; i < n; ++i) {
- cin.get();
- cin.getline(ime,100);
- cin >> tipChlen;
- cin >> god;
- Chlen c(ime, (tipC) tipChlen, god);
- chlen[i] = c;
- }
- fc.setChlenovi(chlen, n);
- cout << "OPERATOR -=" << endl;
- int godina;
- cin >> godina;
- try{
- fc-=godina;
- }
- catch(NotValidYear &exc)
- {
- exc.print();
- }
- cout << fc;
- }
- if (testCase == 6){
- cout << "===== Testiranje na metodot naplatiChlenarina ======" << endl << endl;
- FINKI_club fc(1000);
- int n;
- cin >> n;
- Chlen chlen[100];
- for(int i = 0; i < n; ++i) {
- cin.get();
- cin.getline(ime,100);
- cin >> tipChlen;
- cin >> god;
- Chlen c(ime, (tipC) tipChlen, god);
- chlen[i] = c;
- }
- fc.setChlenovi(chlen, n);
- cout << "Naplati chlenarina:" << endl;
- fc.naplatiChlenarina();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement