jordanov

Жичани инструменти

May 29th, 2020
390
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.12 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3.  
  4. using namespace std;
  5.  
  6.  
  7. class ZicanInstrument{
  8. protected:
  9.   char ime[20];
  10.   int brZici;
  11.   float osnCena;
  12. public:
  13.   ZicanInstrument(char i[20], int br=0, float osn=0){
  14.     strcpy(ime, i);
  15.     brZici=br;
  16.     osnCena=osn;
  17.   }
  18.  
  19.   virtual float cena(){
  20.     return osnCena;
  21.   }
  22.  
  23.   int getBrZici(){
  24.     return brZici;
  25.   }
  26.  
  27.   bool operator==(ZicanInstrument &zi){
  28.     return (brZici==zi.brZici);
  29.   }
  30.  
  31.   friend ostream& operator<<(ostream &out, ZicanInstrument &zi){
  32.     out<<zi.cena()<<endl;
  33.  
  34.     return out;
  35.   }
  36. };
  37.  
  38. class Mandolina: public ZicanInstrument{
  39. private:
  40.   char forma[20];
  41. public:
  42.   Mandolina(char i[20], int br=0, float osn=0, char f[20]=""):ZicanInstrument(i, br, osn){
  43.     strcpy(forma, f);
  44.   }
  45.   float cena(){
  46.     if (strcmp(forma, "Neapolitan")==0)
  47.       return ZicanInstrument::cena()*1.15; //moze i obicno
  48.     return ZicanInstrument::cena();
  49.   }
  50. };
  51.  
  52. class Violina: public ZicanInstrument{
  53. private:
  54.   float golemina;
  55. public:
  56.   Violina(char i[20], int br=0, float osn=0, float gol=0):ZicanInstrument(i, br, osn){
  57.       golemina=gol;
  58.   }
  59.   float cena(){
  60.     if(golemina==0.25)
  61.       return ZicanInstrument::cena()*1.1;
  62.     else if(golemina==1)
  63.       return ZicanInstrument::cena()*1.2;
  64.     else
  65.       return ZicanInstrument::cena();
  66.  
  67.   }
  68. };
  69.  
  70.  
  71. void pecatiInstrumenti(ZicanInstrument &zi, ZicanInstrument **i, int n){
  72.   for(int j=0;j<n;j++){
  73.     if(zi==*(i[j]))
  74.       cout<<*(i[j]);
  75.   }
  76. }
  77.  
  78. int main() {
  79.     char ime[20];
  80.     int brojZici;
  81.     float cena;
  82.     char forma[20];
  83.     cin >> ime >> brojZici >> cena >> forma;
  84.     Mandolina m(ime, brojZici, cena, forma);
  85.     int n;
  86.     cin >> n;
  87.     ZicanInstrument **zi = new ZicanInstrument*[2 * n];
  88.     for(int i = 0; i < n; ++i) {
  89.         cin >> ime >> brojZici >> cena >> forma;
  90.         zi[i] = new Mandolina(ime, brojZici, cena, forma);
  91.     }
  92.     for(int i = 0; i < n; ++i) {
  93.         float golemina;
  94.         cin >> ime >> brojZici >> cena >> golemina;
  95.         zi[n + i] = new Violina(ime, brojZici, cena, golemina);
  96.     }
  97.     pecatiInstrumenti(m, zi, 2 * n);
  98.     for(int i = 0; i < 2 * n; ++i) {
  99.         delete zi[i];
  100.     }
  101.     delete [] zi;
  102.     return 0;
  103. }
Add Comment
Please, Sign In to add comment