Advertisement
LegoDrifter

Klub na popusti

Jun 29th, 2020
307
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 6.85 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3.  
  4. using namespace std;
  5.  
  6. enum tipC{basic=0,premium=1};
  7.  
  8. class NotValidYear{
  9. private:
  10.     char msg[100];
  11. public:
  12.     NotValidYear(const char *msg="")
  13.     {
  14.         strcpy(this->msg,msg);
  15.     }
  16.     void print()
  17.     {
  18.         cout<<msg<<endl;
  19.     }
  20.  
  21. };
  22.  
  23. class Chlen{
  24. private:
  25.     char ime[100];
  26.     tipC tip;
  27.     static int osnoven_popust;
  28.     const static int dopolnitelen_popust;
  29.     int godina;
  30. public:
  31.     Chlen(const char *ime="",tipC tip=(tipC)0,int godina=0)
  32.     {
  33.         strcpy(this->ime,ime);
  34.         this->tip=tip;
  35.         this->godina=godina;
  36.     }
  37.     Chlen(const Chlen &c)
  38.     {
  39.         strcpy(this->ime,c.ime);
  40.         this->tip=c.tip;
  41.         this->godina=c.godina;
  42.     }
  43.     static void setPopust1(int number)
  44.     {
  45.         osnoven_popust=number;
  46.     }
  47.     static int getPopust1()
  48.     {
  49.         return osnoven_popust;
  50.     }
  51.     static int getPopust2()
  52.     {
  53.         return dopolnitelen_popust;
  54.     }
  55.     tipC getType()
  56.     {
  57.         return tip;
  58.     }
  59.     friend ostream &operator <<(ostream &out,Chlen &c)
  60.     {
  61.         out<<c.ime<<endl;
  62.         if(c.getType()==0)
  63.         {
  64.             out<<"basic "<<c.godina<<" "<<c.osnoven_popust<<endl;
  65.         }
  66.         if(c.getType()==1)
  67.         {
  68.             out<<"premium "<<c.godina<<" "<<c.osnoven_popust+c.dopolnitelen_popust<<endl;
  69.         }
  70.         return out;
  71.     }
  72.     int getGodina()
  73.     {
  74.         return godina;
  75.     }
  76.  
  77. };
  78. int Chlen::osnoven_popust=10;
  79. const int Chlen::dopolnitelen_popust=15;
  80. class FINKI_club{
  81. private:
  82.     int osnovna_cena_clan;
  83.     Chlen *clenovi;
  84.     int number;
  85. public:
  86.     FINKI_club()
  87.     {
  88.         this->osnovna_cena_clan=0;
  89.  
  90.     }
  91.     FINKI_club(int osnovna_cena_clan)
  92.     {
  93.         this->osnovna_cena_clan=osnovna_cena_clan;
  94.         this->clenovi = new Chlen[0];
  95.         this->number=0;
  96.     }
  97.     FINKI_club(const FINKI_club &fc)
  98.     {
  99.         this->osnovna_cena_clan=fc.osnovna_cena_clan;
  100.         this->clenovi = new Chlen[fc.number];
  101.         this->number=fc.number;
  102.         for(int i=0;i<fc.number;i++)
  103.         {
  104.             this->clenovi[i]=fc.clenovi[i];
  105.         }
  106.     }
  107.     void setChlenovi(Chlen *novi,int n)
  108.     {
  109.         this->clenovi = new Chlen[n];
  110.         this->number=n;
  111.         for(int i=0;i<number;i++)
  112.         {
  113.             this->clenovi[i]=novi[i];
  114.         }
  115.     }
  116.     FINKI_club &operator-=(int year)
  117.     {
  118.         if(year<0)
  119.         {
  120.             throw NotValidYear("Vnesena e negativna vrednost za godinata!");
  121.         }
  122.         int brojac=0;
  123.         for(int i=0;i<number;i++)
  124.         {
  125.             if(clenovi[i].getGodina()==year)
  126.                 brojac++;
  127.         }
  128.         Chlen *tmp = new Chlen[brojac];
  129.         brojac=0;
  130.         for(int i=0;i<number;i++)
  131.         {
  132.             if(clenovi[i].getGodina()==year)
  133.             {
  134.                 tmp[brojac++]=clenovi[i];
  135.             }
  136.  
  137.         }
  138.         delete [] clenovi;
  139.         clenovi = tmp;
  140.         number = brojac;
  141.         return *this;
  142.     }
  143.     int getOsnovna()
  144.     {
  145.         return osnovna_cena_clan;
  146.     }
  147.     friend ostream &operator <<(ostream &out,FINKI_club &fc)
  148.     {
  149.         for(int i=0;i<fc.number;i++)
  150.         {
  151.             out<<fc.clenovi[i];
  152.         }
  153.         return out;
  154.     }
  155.     void naplatiChlenarina()
  156.     {
  157.         for(int i=0;i<number;i++)
  158.         {
  159.             cout<<clenovi[i];
  160.             if(clenovi[i].getType()==0)
  161.             {
  162.                 float popust = clenovi[i].getPopust1();
  163.                 cout<<osnovna_cena_clan-(osnovna_cena_clan*popust/100)<<endl;
  164.                
  165.             }
  166.             else if(clenovi[i].getType()==1)
  167.             {
  168.                 float popust = (clenovi[i].getPopust1()+clenovi[i].getPopust2());
  169.                 cout<<osnovna_cena_clan-(osnovna_cena_clan*popust/100)<<endl;
  170.                
  171.             }
  172.         }
  173.     }
  174.  
  175.  
  176.  
  177.  
  178.  
  179. };
  180. int main(){
  181.     int testCase;
  182.     cin >> testCase;
  183.  
  184.     char ime[100];
  185.     int tipChlen;
  186.     int popust;
  187.     int god;
  188.  
  189.  
  190.     if (testCase == 1){
  191.         cout << "===== Testiranje na klasata Chlen ======" << endl;
  192.         cin.get();
  193.         cin.getline(ime,100);
  194.         cin >> tipChlen;
  195.         cin >> god;
  196.         cout << "===== CONSTRUCTOR ======" << endl;
  197.         Chlen c(ime, (tipC) tipChlen, god);
  198.         cout << c;
  199.  
  200.     }
  201.  
  202.     if (testCase == 2){
  203.         cout << "===== Testiranje na static clenovi ======" << endl;
  204.         cin.get();
  205.         cin.getline(ime,100);
  206.         cin >> tipChlen;
  207.         cin >> god;
  208.         cout << "===== CONSTRUCTOR ======" << endl;
  209.         Chlen c(ime, (tipC) tipChlen, god);
  210.         cout << c;
  211.  
  212.         c.setPopust1(5);
  213.  
  214.         cout << c;
  215.     }
  216.  
  217.     if (testCase == 3){
  218.         cout << "===== Testiranje na klasata FINKI-club ======" << endl;
  219.         FINKI_club fc;
  220.         int n;
  221.         cin >> n;
  222.         Chlen chlen[100];
  223.         for(int i = 0; i < n; ++i) {
  224.             cin.get();
  225.             cin.getline(ime,100);
  226.             cin >> tipChlen;
  227.             cin >> god;
  228.             Chlen c(ime, (tipC) tipChlen, god);
  229.             chlen[i] = c;
  230.         }
  231.  
  232.         fc.setChlenovi(chlen, n);
  233.  
  234.         cout << fc <<endl;
  235.     }
  236.  
  237.     if (testCase == 4){
  238.         cout << "===== Testiranje na operatorot -= ======" << endl;
  239.         FINKI_club fc;
  240.         int n;
  241.         cin >> n;
  242.         Chlen chlen[100];
  243.         for(int i = 0; i < n; ++i) {
  244.             cin.get();
  245.             cin.getline(ime,100);
  246.             cin >> tipChlen;
  247.             cin >> god;
  248.             Chlen c(ime, (tipC) tipChlen, god);
  249.             chlen[i] = c;
  250.         }
  251.  
  252.         fc.setChlenovi(chlen, n);
  253.         cout << "OPERATOR -=" << endl;
  254.         int godina;
  255.         cin >> godina;
  256.         fc-=godina;
  257.  
  258.         cout << fc;
  259.     }
  260.  
  261.     if (testCase == 5){
  262.         cout << "===== Testiranje na operatorot -= (so iskluchok) ======" << endl;
  263.         FINKI_club fc;
  264.         int n;
  265.         cin >> n;
  266.         Chlen chlen[100];
  267.         for(int i = 0; i < n; ++i) {
  268.             cin.get();
  269.             cin.getline(ime,100);
  270.             cin >> tipChlen;
  271.             cin >> god;
  272.             Chlen c(ime, (tipC) tipChlen, god);
  273.             chlen[i] = c;
  274.         }
  275.  
  276.         fc.setChlenovi(chlen, n);
  277.         cout << "OPERATOR -=" << endl;
  278.         int godina;
  279.         cin >> godina;
  280.         try{
  281.         fc-=godina;
  282.         }
  283.         catch(NotValidYear &exc)
  284.         {
  285.             exc.print();
  286.         }
  287.  
  288.         cout << fc;
  289.     }
  290.  
  291.     if (testCase == 6){
  292.         cout << "===== Testiranje na metodot naplatiChlenarina  ======" << endl << endl;
  293.         FINKI_club fc(1000);
  294.         int n;
  295.         cin >> n;
  296.         Chlen chlen[100];
  297.         for(int i = 0; i < n; ++i) {
  298.             cin.get();
  299.             cin.getline(ime,100);
  300.             cin >> tipChlen;
  301.             cin >> god;
  302.             Chlen c(ime, (tipC) tipChlen, god);
  303.             chlen[i] = c;
  304.         }
  305.  
  306.         fc.setChlenovi(chlen, n);
  307.  
  308.         cout << "Naplati chlenarina:" << endl;
  309.         fc.naplatiChlenarina();
  310.     }
  311.     return 0;
  312. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement