Advertisement
deko96

Umetnicki Dela

Sep 8th, 2015
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.15 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3. using namespace std;
  4.  
  5. class UmetnickoDelo {
  6. protected:
  7.     int godina;
  8.     char *avtor;
  9.     float cena;
  10. public:
  11.     UmetnickoDelo(char *avtor, int godina, float cena) {
  12.         try {
  13.             if(cena<0) throw 1;
  14.             this->avtor = new char [strlen(avtor) + 1];
  15.             strcpy(this->avtor, avtor);
  16.             this->godina=godina;
  17.         } catch(int) {
  18.             cout<<"Cenata ne smee da bide negativna. Faten e isklucok"<<endl;
  19.             this->cena=0;
  20.         }
  21.     }
  22.     virtual float cenaDelo()=0;
  23.     friend ostream& operator<< (ostream& o, UmetnickoDelo& ud) {
  24.         o<<"Avtor: "<<ud.avtor<<" godina: "<<ud.godina<<" cena: "<<ud.cenaDelo()<<endl;
  25.         return o;
  26.     }
  27.     UmetnickoDelo(const UmetnickoDelo& other) {
  28.         this->avtor = new char[strlen(other.avtor) + 1];
  29.         strcpy(avtor, other.avtor);
  30.         godina = other.godina;
  31.         cena = other.cena;
  32.     }
  33.  
  34.     UmetnickoDelo& operator=(const UmetnickoDelo& other) {
  35.         if (this != &other) {
  36.             delete [] avtor;
  37.             this->avtor = new char[strlen(other.avtor) + 1];
  38.             strcpy(avtor, other.avtor);
  39.             godina = other.godina;
  40.             cena = other.cena;
  41.         }
  42.         return *this;
  43.     }
  44.     virtual ~UmetnickoDelo() {
  45.         delete[] avtor;
  46.     }
  47. };
  48. bool operator>(UmetnickoDelo &u1, UmetnickoDelo &u2) {
  49.     return u1.cenaDelo()>u2.cenaDelo();
  50. }
  51. class MuzickoDelo: public UmetnickoDelo {
  52. private:
  53.     char zanr[30];
  54.     static double x;
  55. public:
  56.     MuzickoDelo(char *avtor, int godina, float cena, char *zanr): UmetnickoDelo(avtor, godina, cena) {
  57.         strcpy(this->zanr, zanr);
  58.     }
  59.     static double getX() {
  60.         return x;
  61.     }
  62.     static void setX (double x) {
  63.         MuzickoDelo::x = x;
  64.     }
  65.     float cenaDelo() {
  66.         if(godina<1700&&godina>=1600) {
  67.             return cena+(cena*x);
  68.         } else {
  69.             return cena;
  70.         }
  71.     }
  72. };
  73. double MuzickoDelo::x = 0.1;
  74.  
  75. class SlikarskoDelo: public UmetnickoDelo {
  76. private:
  77.     char tehnika[30];
  78.     int stepen;
  79. public:
  80.     SlikarskoDelo(char *avtor, int godina, float cena, char *tehnika, int stepen): UmetnickoDelo(avtor, godina, cena) {
  81.         strcpy(this->tehnika, tehnika);
  82.         this->stepen=stepen;
  83.     }
  84.     float cenaDelo() {
  85.         if(stepen) {
  86.             return cena*(1-(float)stepen/100);
  87.         } else {
  88.             return cena;
  89.         }
  90.     }
  91. };
  92.  
  93. float najskapoDelo(UmetnickoDelo** dela, int n) {
  94.     float max = dela[0]->cenaDelo();
  95.     int ind = 0;
  96.     for(int i = 1; i < n; i++) {
  97.         if(dela[i]->cenaDelo() > max) {
  98.             max = dela[i]->cenaDelo();
  99.             ind = i;
  100.         }
  101.     }
  102.     cout<<*dela[ind];
  103. }
  104. int main() {
  105.     UmetnickoDelo** dela = new UmetnickoDelo*[3];
  106.     dela[0] = new SlikarskoDelo ("sdelo1", 1222, 1000, "tehn1", 50);
  107.     cout<<*dela[0];
  108.     dela[1] = new MuzickoDelo ("mdelo1", 1622, 1000, "zanr1");
  109.     cout<<*dela[1];
  110.     dela[2] = new MuzickoDelo ("mdelo2", 2004, 500, "zanr2");
  111.     cout<<*dela[2];
  112.     cout<<endl;
  113.     cout<<"Najskapo Delo: " << endl;
  114.     najskapoDelo(dela, 3);
  115.     return 0;
  116. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement