velimir

Саксиско цвеќе

Jun 12th, 2016
336
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.35 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3.  
  4. using namespace std;
  5.  
  6. class SaksiskoCvekje{
  7. protected:
  8.     char *ime;
  9.     int cena;
  10.     char *family;
  11. public:
  12.     SaksiskoCvekje(char *i, int c, char *f){
  13.         ime = new char[strlen(i)+1];
  14.         strcpy(ime, i);
  15.         cena = c;
  16.         family = new char[strlen(f)+1];
  17.     }
  18.     char *getFamily(){
  19.         return family;
  20.     }
  21.     int getCena(){
  22.         return cena;
  23.     }
  24.     char *getIme(){
  25.         return ime;
  26.     }
  27.     virtual int presmetajCena(){
  28.         return 0;
  29.     }
  30. };
  31.    
  32. class BezCvet : public SaksiskoCvekje{
  33.     int staro;
  34. public:
  35.     BezCvet(char *i, int c, char *f, int s) : SaksiskoCvekje(i, c, f){
  36.         staro = s;
  37.     }
  38.     void setStaro(int x){
  39.         staro = x;
  40.     }
  41.     int getStaro(){
  42.         return staro;
  43.     }
  44.     int presmetajCena(){
  45.         if(getStaro()<10) return cena+20;
  46.         else if(getStaro()<35) return cena+10;
  47.             else return cena;
  48.     }
  49. };
  50.    
  51. class SoCvet : public SaksiskoCvekje{
  52.     int cvetovi;
  53. public:
  54.     SoCvet(char *i, int c, char *f, int cvet) : SaksiskoCvekje(i, c, f){
  55.         cvetovi = cvet;
  56.     }
  57.     void setCvetovi(int x){
  58.         cvetovi = x;
  59.     }
  60.     int getCvetovi(){
  61.         return cvetovi;
  62.     }
  63.     int presmetajCena(){
  64.         return cena+getCvetovi();
  65.     }
  66. };
  67.  
  68. bool operator==(SaksiskoCvekje *s1, SaksiskoCvekje &s2){
  69.     if(s1->getFamily()==s2.getFamily()) return true;
  70.     else return false;
  71. }
  72.  
  73. void pecatiMaxCena(SaksiskoCvekje **s, int n, BezCvet &C) {
  74.     SaksiskoCvekje *max = s[0];
  75.     for(int i = 0; i < n; i++) {
  76.         if(strcmp(s[i]->getFamily(), C.getFamily())==0) {
  77.             if(s[i]->getCena() > max->getCena())
  78.                 max = s[i];
  79.         }
  80.     }
  81.     cout<< max->getIme() << " " << max->getFamily() << "cactus " << max->presmetajCena();
  82. }
  83.  
  84. int main(){
  85.  
  86. char ime[10],familija[10];
  87. int tip,starost,broj,cena;
  88. int n;
  89. cin>>n;
  90. SaksiskoCvekje **cvekinja;
  91. cvekinja=new SaksiskoCvekje*[n];
  92.  
  93. for (int i=0;i<n;i++){
  94.  
  95.     cin>>tip>>ime>>cena>>familija;
  96.     if (tip==1) {
  97.         cin>>starost;
  98.         cvekinja[i]=new BezCvet(ime,cena,familija,starost);
  99.  
  100.     }
  101.     else {
  102.         cin>>broj;
  103.         cvekinja[i]=new SoCvet(ime,cena,familija,broj);
  104.     }
  105.  
  106.  
  107. }
  108.  
  109. BezCvet nov("opuntia",90,"cactus",10);
  110. pecatiMaxCena(cvekinja,n,nov);
  111.  
  112. for (int i=0;i<n;i++) delete cvekinja[i];
  113. delete [] cvekinja;
  114. return 0;
  115. }
Advertisement
Add Comment
Please, Sign In to add comment