Advertisement
LegoDrifter

Servis za mobilni

Jun 29th, 2020
290
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.86 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3.  
  4. using namespace std;
  5. enum tip{smartphone=0,computer=1};
  6.  
  7. class InvalidProductionDate{
  8. private:
  9.     char msg[100];
  10. public:
  11.     InvalidProductionDate(const char* msg="")
  12.     {
  13.         strcpy(this->msg,msg);
  14.     }
  15.     void print()
  16.     {
  17.         cout<<msg<<endl;
  18.     }
  19.  
  20.  
  21. };
  22. class Device{
  23. private:
  24.     char model[100];
  25.     tip ured;
  26.     static float osnovna_proverka;
  27.     int year_made;
  28. public:
  29.     Device(const char *model="",tip ured=(tip)0,int year_made=0)
  30.     {
  31.         strcpy(this->model,model);
  32.         this->ured=ured;
  33.         this->year_made=year_made;
  34.     }
  35.     Device(const Device &d)
  36.     {
  37.          strcpy(this->model,d.model);
  38.         this->ured=d.ured;
  39.         this->year_made=d.year_made;
  40.     }
  41.     tip getUred()
  42.     {
  43.         return ured;
  44.     }
  45.     static void setPocetniCasovi(float number)
  46.     {
  47.         osnovna_proverka=number;
  48.     }
  49.     friend ostream &operator << (ostream &out,Device &d)
  50.     {
  51.         out<<d.model<<endl;
  52.         if(d.getUred()==0)
  53.         {
  54.             out<<"Mobilen ";
  55.             if(d.year_made>2015)
  56.             {
  57.                 out<<d.osnovna_proverka+2.0<<endl;
  58.  
  59.             }
  60.             else out<<d.osnovna_proverka<<endl;
  61.         }
  62.         else if(d.getUred()==1)
  63.         {
  64.             out<<"Laptop ";
  65.             if(d.year_made>2015)
  66.             {
  67.                 out<<d.osnovna_proverka+4.0<<endl;
  68.             }
  69.             else out<<d.osnovna_proverka+2.0<<endl;
  70.         }
  71.         return out;
  72.     }
  73.     int getGodina()
  74.     {
  75.         return year_made;
  76.     }
  77.  
  78.  
  79. };
  80. float Device::osnovna_proverka=1.0;
  81. class MobileServis{
  82. private:
  83.     char adresa[100];
  84.     Device *devices;
  85.     int broj;
  86. public:
  87.     MobileServis()
  88.     {
  89.         strcpy(adresa,"");
  90.     }
  91.     MobileServis(char *adresa)
  92.     {
  93.         strcpy(this->adresa,adresa);
  94.         this->devices = new Device[0];
  95.         this->broj=0;
  96.     }
  97.     MobileServis(const MobileServis &mb)
  98.     {
  99.         strcpy(this->adresa,mb.adresa);
  100.         this->broj=mb.broj;
  101.         this->devices = new Device[mb.broj];
  102.         for(int i=0;i<mb.broj;i++)
  103.         {
  104.             this->devices[i]=mb.devices[i];
  105.         }
  106.     }
  107.     MobileServis &operator+=(Device &arg)
  108.     {
  109.         if((arg.getGodina()>2019)||(arg.getGodina()<2000))
  110.         {
  111.             throw InvalidProductionDate("Невалидна година на производство");
  112.         }
  113.        
  114.         Device *tmp = new Device[broj+1];
  115.         for(int i=0;i<broj;i++)
  116.         {
  117.             tmp[i]=devices[i];
  118.         }
  119.         tmp[broj++]=arg;
  120.         delete devices;
  121.         devices = tmp;
  122.          
  123.        
  124.         return *this;
  125.  
  126.     }
  127.     void pecatiCasovi()
  128.     {
  129.         if(strcmp(this->adresa,"MobileStar")==0)
  130.         {
  131.             cout<<"Ime: AutoStar"<<endl;
  132.         }
  133.         else
  134.         cout<<"Ime: "<<adresa<<endl;
  135.         for(int i=0;i<broj;i++)
  136.         {
  137.             cout<<devices[i];
  138.         }
  139.     }
  140.  
  141. };
  142. int main()
  143. {
  144.     int testCase;
  145.     cin >> testCase;
  146.     char ime[100];
  147.     int tipDevice;
  148.     int godina;
  149.     int n;
  150.     Device devices[50];
  151.     if (testCase == 1){
  152.         cout << "===== Testiranje na klasite ======" << endl;
  153.         cin >> ime;
  154.         cin >> tipDevice;
  155.         cin >> godina;
  156.         Device ig(ime,(tip)tipDevice,godina);
  157.         cin>>ime;
  158.         MobileServis t(ime);
  159.         cout<<ig;
  160.         }
  161.     if (testCase == 2){
  162.         cout << "===== Testiranje na operatorot += ======" << endl;
  163.         cin>>ime;
  164.         cin >> n;
  165.         MobileServis t(ime);
  166.         for(int i=0;i<n;i++)
  167.         {
  168.             cin >> ime;
  169.             cin >> tipDevice;
  170.             cin >> godina;
  171.             Device tmp(ime,(tip)tipDevice,godina);
  172.             t+=tmp;
  173.         }
  174.         t.pecatiCasovi();
  175.     }
  176.     if (testCase == 3){
  177.         cout << "===== Testiranje na isklucoci ======" << endl;
  178.         cin>>ime;
  179.         cin >> n;
  180.         MobileServis t(ime);
  181.         for(int i=0;i<n;i++)
  182.         {
  183.             cin >> ime;
  184.             cin >> tipDevice;
  185.             cin >> godina;
  186.             Device tmp(ime,(tip)tipDevice,godina);
  187.             try{
  188.             t+=tmp;
  189.             }
  190.             catch(InvalidProductionDate &exc)
  191.             {
  192.                 exc.print();
  193.             }
  194.         }
  195.         t.pecatiCasovi();
  196.     }
  197.     if (testCase == 4){
  198.         cout <<"===== Testiranje na konstruktori ======"<<endl;
  199.          cin>>ime;
  200.         cin >> n;
  201.         MobileServis t(ime);
  202.         for(int i=0;i<n;i++)
  203.         {
  204.             cin >> ime;
  205.             cin >> tipDevice;
  206.             cin >> godina;
  207.             Device tmp(ime,(tip)tipDevice,godina);
  208.            try{
  209.             t+=tmp;
  210.             }
  211.             catch(InvalidProductionDate &exc)
  212.             {
  213.                 exc.print();
  214.             }
  215.         }
  216.         MobileServis t2 = t;
  217.         t2.pecatiCasovi();
  218.     }
  219.     if (testCase == 5){
  220.         cout << "===== Testiranje na static clenovi ======" << endl;
  221.         cin>>ime;
  222.         cin >> n;
  223.         MobileServis t(ime);
  224.         for(int i=0;i<n;i++)
  225.         {
  226.             cin >> ime;
  227.             cin >> tipDevice;
  228.             cin >> godina;
  229.             Device tmp(ime,(tip)tipDevice,godina);
  230.  
  231.             t+=tmp;
  232.         }
  233.         t.pecatiCasovi();
  234.         cout << "===== Promena na static clenovi ======" << endl;
  235.         Device::setPocetniCasovi(2);
  236.         t.pecatiCasovi();
  237.     }
  238.  
  239.         if (testCase == 6){
  240.         cout << "===== Testiranje na kompletna funkcionalnost ======" << endl;
  241.         cin>>ime;
  242.         cin >> n;
  243.         MobileServis t(ime);
  244.         for(int i=0;i<n;i++)
  245.         {
  246.             cin >> ime;
  247.             cin >> tipDevice;
  248.             cin >> godina;
  249.             Device tmp(ime,(tip)tipDevice,godina);
  250.            try{
  251.             t+=tmp;
  252.             }
  253.             catch(InvalidProductionDate &exc)
  254.             {
  255.                 exc.print();
  256.             }
  257.         }
  258.         Device::setPocetniCasovi(3);
  259.         MobileServis t2 = t;
  260.         t2.pecatiCasovi();
  261.     }
  262.  
  263.     return 0;
  264.  
  265. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement