Advertisement
ilevishinov

Игротека

Apr 28th, 2017
543
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.47 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3. #include <cmath>
  4. using namespace std;
  5.  
  6. class Igrachka {
  7. public:
  8.     virtual float getVolumen() = 0;
  9.     virtual float getMasa() = 0;
  10. };
  11.  
  12. class Forma{
  13. protected:
  14.     char boja[100];
  15.     int gustina;
  16. public:
  17.     // да се имплементираат потребните методи
  18.     Forma(char* boja,int gustina){
  19.         strcpy(this->boja,boja);
  20.         this->gustina=gustina;
  21.     }
  22.    
  23.    
  24. };
  25.  
  26. class Topka:public Igrachka, public Forma{
  27. protected:
  28.     int r;
  29. public:
  30.     Topka(char* boja,int gustina,int radius):Forma(boja,gustina){
  31.         r=radius;
  32.     }
  33.    
  34.     float getVolumen(){
  35.         return 4*r*r*r*3.14/3;
  36.     }
  37.    
  38.     float getMasa(){
  39.         return this->getVolumen()*gustina;
  40.        
  41.     }
  42. };
  43.  
  44. class Kocka:public Igrachka, public Forma{
  45. protected:
  46.     int h;
  47.     int w;
  48.     int d;
  49. public:
  50.     Kocka(char* boja,int gustina,int visina,int shirina,int dlabochina):Forma(boja,gustina){
  51.         h=visina;
  52.         w=shirina;
  53.         d=dlabochina;
  54.     }
  55.    
  56.     float getVolumen(){
  57.         return h*w*d;
  58.     }
  59.    
  60.     float getMasa(){
  61.         return this->getVolumen()*gustina;
  62.     }
  63.    
  64. };
  65.  
  66.  
  67.  
  68. int main(){
  69.    
  70.     //vnesi informacii za kupche
  71.    
  72.     Igrachka **kupche;
  73.     int n;
  74.     cin>>n;
  75.     kupche=new Igrachka*[n];
  76.    
  77.     char boja[100];
  78.     int gustina;
  79.     int radius;
  80.     int shirina,visina,dlabochina;
  81.     int m;
  82.    
  83.     for(int i=0;i<n;i++){
  84.         cin>>m;
  85.         if(m==1){ //Topka
  86.             cin>>boja>>gustina>>radius;
  87.             kupche[i]=new Topka(boja,gustina,radius);
  88.         } else{
  89.             cin>>boja>>gustina>>visina>>shirina>>dlabochina;
  90.             kupche[i]=new Kocka(boja,gustina,visina,shirina,dlabochina);
  91.         }
  92.     }
  93.    
  94.     //vnesi informacii za igrachkata na Petra
  95.    
  96.     cin>>boja>>gustina>>visina>>shirina>>dlabochina;
  97.     Igrachka *petra=new Kocka(boja,gustina,visina,shirina,dlabochina);
  98.    
  99.    
  100.     //baranje 1
  101.    
  102.     int vkupnaMasa=0;
  103.     for(int i=0;i<n;i++){
  104.         vkupnaMasa+=kupche[i]->getMasa();
  105.     }
  106.     (vkupnaMasa>petra->getMasa())? cout<<"DA"<<endl : cout<<"NE"<<endl;
  107.  
  108.  
  109.     //baranje 2
  110.    
  111.     Igrachka *maxV=kupche[0];
  112.     for(int i=1;i<n;i++){
  113.         if(kupche[i]->getVolumen() > maxV->getVolumen())
  114.             maxV=kupche[i];
  115.     }
  116.    
  117.     cout<<"Razlikata e: "<<abs(maxV->getVolumen() - petra->getVolumen());
  118.    
  119.     delete petra;
  120.     delete maxV;
  121.     delete [] kupche;
  122.    
  123.  
  124.     return 0;
  125. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement