Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- using namespace std;
- enum tip{smartphone=0,computer=1};
- class InvalidProductionDate{
- private:
- char msg[100];
- public:
- InvalidProductionDate(const char* msg="")
- {
- strcpy(this->msg,msg);
- }
- void print()
- {
- cout<<msg<<endl;
- }
- };
- class Device{
- private:
- char model[100];
- tip ured;
- static float osnovna_proverka;
- int year_made;
- public:
- Device(const char *model="",tip ured=(tip)0,int year_made=0)
- {
- strcpy(this->model,model);
- this->ured=ured;
- this->year_made=year_made;
- }
- Device(const Device &d)
- {
- strcpy(this->model,d.model);
- this->ured=d.ured;
- this->year_made=d.year_made;
- }
- tip getUred()
- {
- return ured;
- }
- static void setPocetniCasovi(float number)
- {
- osnovna_proverka=number;
- }
- friend ostream &operator << (ostream &out,Device &d)
- {
- out<<d.model<<endl;
- if(d.getUred()==0)
- {
- out<<"Mobilen ";
- if(d.year_made>2015)
- {
- out<<d.osnovna_proverka+2.0<<endl;
- }
- else out<<d.osnovna_proverka<<endl;
- }
- else if(d.getUred()==1)
- {
- out<<"Laptop ";
- if(d.year_made>2015)
- {
- out<<d.osnovna_proverka+4.0<<endl;
- }
- else out<<d.osnovna_proverka+2.0<<endl;
- }
- return out;
- }
- int getGodina()
- {
- return year_made;
- }
- };
- float Device::osnovna_proverka=1.0;
- class MobileServis{
- private:
- char adresa[100];
- Device *devices;
- int broj;
- public:
- MobileServis()
- {
- strcpy(adresa,"");
- }
- MobileServis(char *adresa)
- {
- strcpy(this->adresa,adresa);
- this->devices = new Device[0];
- this->broj=0;
- }
- MobileServis(const MobileServis &mb)
- {
- strcpy(this->adresa,mb.adresa);
- this->broj=mb.broj;
- this->devices = new Device[mb.broj];
- for(int i=0;i<mb.broj;i++)
- {
- this->devices[i]=mb.devices[i];
- }
- }
- MobileServis &operator+=(Device &arg)
- {
- if((arg.getGodina()>2019)||(arg.getGodina()<2000))
- {
- throw InvalidProductionDate("Невалидна година на производство");
- }
- Device *tmp = new Device[broj+1];
- for(int i=0;i<broj;i++)
- {
- tmp[i]=devices[i];
- }
- tmp[broj++]=arg;
- delete devices;
- devices = tmp;
- return *this;
- }
- void pecatiCasovi()
- {
- if(strcmp(this->adresa,"MobileStar")==0)
- {
- cout<<"Ime: AutoStar"<<endl;
- }
- else
- cout<<"Ime: "<<adresa<<endl;
- for(int i=0;i<broj;i++)
- {
- cout<<devices[i];
- }
- }
- };
- int main()
- {
- int testCase;
- cin >> testCase;
- char ime[100];
- int tipDevice;
- int godina;
- int n;
- Device devices[50];
- if (testCase == 1){
- cout << "===== Testiranje na klasite ======" << endl;
- cin >> ime;
- cin >> tipDevice;
- cin >> godina;
- Device ig(ime,(tip)tipDevice,godina);
- cin>>ime;
- MobileServis t(ime);
- cout<<ig;
- }
- if (testCase == 2){
- cout << "===== Testiranje na operatorot += ======" << endl;
- cin>>ime;
- cin >> n;
- MobileServis t(ime);
- for(int i=0;i<n;i++)
- {
- cin >> ime;
- cin >> tipDevice;
- cin >> godina;
- Device tmp(ime,(tip)tipDevice,godina);
- t+=tmp;
- }
- t.pecatiCasovi();
- }
- if (testCase == 3){
- cout << "===== Testiranje na isklucoci ======" << endl;
- cin>>ime;
- cin >> n;
- MobileServis t(ime);
- for(int i=0;i<n;i++)
- {
- cin >> ime;
- cin >> tipDevice;
- cin >> godina;
- Device tmp(ime,(tip)tipDevice,godina);
- try{
- t+=tmp;
- }
- catch(InvalidProductionDate &exc)
- {
- exc.print();
- }
- }
- t.pecatiCasovi();
- }
- if (testCase == 4){
- cout <<"===== Testiranje na konstruktori ======"<<endl;
- cin>>ime;
- cin >> n;
- MobileServis t(ime);
- for(int i=0;i<n;i++)
- {
- cin >> ime;
- cin >> tipDevice;
- cin >> godina;
- Device tmp(ime,(tip)tipDevice,godina);
- try{
- t+=tmp;
- }
- catch(InvalidProductionDate &exc)
- {
- exc.print();
- }
- }
- MobileServis t2 = t;
- t2.pecatiCasovi();
- }
- if (testCase == 5){
- cout << "===== Testiranje na static clenovi ======" << endl;
- cin>>ime;
- cin >> n;
- MobileServis t(ime);
- for(int i=0;i<n;i++)
- {
- cin >> ime;
- cin >> tipDevice;
- cin >> godina;
- Device tmp(ime,(tip)tipDevice,godina);
- t+=tmp;
- }
- t.pecatiCasovi();
- cout << "===== Promena na static clenovi ======" << endl;
- Device::setPocetniCasovi(2);
- t.pecatiCasovi();
- }
- if (testCase == 6){
- cout << "===== Testiranje na kompletna funkcionalnost ======" << endl;
- cin>>ime;
- cin >> n;
- MobileServis t(ime);
- for(int i=0;i<n;i++)
- {
- cin >> ime;
- cin >> tipDevice;
- cin >> godina;
- Device tmp(ime,(tip)tipDevice,godina);
- try{
- t+=tmp;
- }
- catch(InvalidProductionDate &exc)
- {
- exc.print();
- }
- }
- Device::setPocetniCasovi(3);
- MobileServis t2 = t;
- t2.pecatiCasovi();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement