Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<cstring>
- using namespace std;
- enum tip{smartphone,computer};
- /*
- class InvalidDate{
- private:
- int date;
- public:
- InvalidDate(){}
- InvalidDate(int date){
- this->date=date;
- }
- void print(){
- cout<<"Device was made in "<<date<<endl;
- }
- };
- */
- class InvalidProductionDate{
- private:
- char error[100];
- public:
- InvalidProductionDate(){}
- InvalidProductionDate(char error[]){
- strcpy(this->error,error);
- }
- void print(){
- cout<<error<<endl;
- }
- };
- class Device{
- private:
- char model[100];
- tip tipUred;
- static float casovi;
- int godina;
- public:
- Device(){}
- Device(char model[],tip tipUred,int godina){
- strcpy(this->model,model);
- this->tipUred=tipUred;
- this->godina=godina;
- }
- static void setPocetniCasovi(int x){
- casovi=x;
- }
- /*
- bool operator==(Device &drugDevice){
- if((strcmp(this->model,drugDevice.model)==0)&&(this->godina==drugDevice.godina)){
- return true;
- }
- return false;
- }
- */
- friend ostream& operator<<(ostream &out,Device &objekt){
- out<<objekt.model<<endl;
- if(objekt.tipUred==0){
- out<<"Mobilen ";
- }else{
- out<<"Laptop ";
- }
- if(objekt.godina>2015&&objekt.tipUred==1){
- out<<casovi+4<<endl;
- }else if(objekt.godina>2015 || objekt.tipUred==1){
- out<<casovi+2<<endl;
- }else{
- out<<casovi<<endl;
- }
- return out;
- }
- int getGodina(){
- return godina;
- }
- ~Device(){}
- };
- float Device::casovi=1;
- class MobileServis{
- private:
- char adresa[100];
- Device *niza;
- int brojUredi;
- public:
- MobileServis(){
- niza=new Device[0];
- brojUredi=0;
- }
- MobileServis(char adresa[]){
- strcpy(this->adresa,adresa);
- niza=new Device[0];
- brojUredi=0;
- }
- //mobileservis+=device;
- MobileServis &operator+=(Device &novDevice){
- if(novDevice.getGodina()>2019 || novDevice.getGodina()<2000){
- throw InvalidProductionDate("Невалидна година на производство");
- }
- Device *tempNiza=new Device[brojUredi];
- for(int i=0;i<brojUredi;i++){
- tempNiza[i]=niza[i];
- }
- niza=new Device[brojUredi+1];
- for(int i=0;i<brojUredi;i++){
- niza[i]=tempNiza[i];
- }
- niza[brojUredi]=novDevice;
- brojUredi++;
- delete []tempNiza;
- return *this;
- }
- /*
- MobileServis &operator-=(Device &novUred){
- int flag=0;
- for(int i=0;i<brojUredi;i++){
- if(niza[i]==novUred){
- flag=1;
- break;
- }
- }
- if(flag==1){
- int brojac=0;
- Device *tempNiza=new Device[brojUredi];
- for(int i=0;i<brojUredi;i++){
- if(niza[i]==novUred){
- // ne praime nishto t.e. go skoknvame novUred objektot
- }else{
- tempNiza[brojac]=niza[i];
- brojac++;
- }
- }
- brojUredi--;
- niza=new Device[brojUredi];
- for(int i=0;i<brojUredi;i++){
- niza[i]=tempNiza[i];
- }
- delete []tempNiza;
- }
- return *this;
- }
- */
- void pecatiCasovi(){
- cout<<"Ime: "<<adresa<<endl;
- for(int i=0;i<brojUredi;i++){
- cout<<niza[i];
- }
- }
- ~MobileServis(){
- delete []niza;
- }
- };
- 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);
- try{
- t+=tmp;
- }catch(InvalidProductionDate &objekt){
- objekt.print();
- }
- }
- 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 &objekt){
- objekt.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 &objekt){
- objekt.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);
- try{
- t+=tmp;
- }catch(InvalidProductionDate &objekt){
- objekt.print();
- }
- }
- 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 &objekt){
- objekt.print();
- }
- }
- Device::setPocetniCasovi(3);
- MobileServis t2 = t;
- t2.pecatiCasovi();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment