Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<cstring>
- using namespace std;
- class Toy {
- public:
- virtual float getVolume() = 0;
- virtual float getWeight() = 0;
- };
- class Shape {
- protected:
- char color[100];
- int density;
- public:
- Shape(char *color="",int density = 0)
- {
- strcpy(this->color,color);
- this->density=density;
- }
- Shape(const Shape &s)
- {
- strcpy(this->color,s.color);
- this->density=s.density;
- }
- };
- class Cubes :public Shape ,public Toy
- {
- private:
- int height;
- int width;
- int depth;
- public:
- Cubes(char *color="",int density =0,int height =0 ,int width =0 ,int depth =0): Shape(color , density)
- {
- this->height=height;
- this->width=width;
- this->depth=depth;
- }
- Cubes(const Cubes &c) : Shape(c)
- {
- this->height=c.height;
- this->width=c.width;
- this->depth=c.depth;
- }
- float getVolume()
- {
- return height * width * depth;
- }
- float getWeight()
- {
- return getVolume() * density;
- }
- };
- class Balls :public Shape ,public Toy
- {
- private:
- int radius;
- public:
- Balls(char *color="",int density = 0, int radius = 0 ): Shape(color , density)
- {
- this->radius=radius;
- }
- Balls(const Balls &b) :Shape(b)
- {
- this->radius=b.radius;
- }
- float getWeight()
- {
- return getVolume() * density;
- }
- float getVolume()
- {
- return 3.14*4/3 * radius * radius * radius;
- }
- };
- int main(){
- int n ;
- cin>>n;
- char color[100];
- int density;
- int height;
- int width;
- int depth;
- int radius;
- Toy **toys=new Toy*[n];
- for(int i = 0 ; i < n ; i ++)
- {
- int s;
- cin>>s;
- if(s == 1)
- {
- cin>>color>>density>>radius;
- toys[i]=new Balls(color,density,radius);
- }
- if(s == 2)
- {
- cin>>color>>density>>height>>width>>depth;
- // cout<<color<<endl<<density<<endl<<height<<endl<<width<<endl<<depth; do tuka raboti
- toys[i]=new Cubes(color,density,height,width,depth);
- }
- }
- cin>>color>>density>>height>>width>>depth;
- //cout<<color<<endl<<density<<endl<<height<<endl<<width<<endl<<depth<<endl;
- Cubes Petra(color,density,height,width,depth);
- //cout<<color<<endl<<density<<endl<<height<<endl<<width<<endl<<depth<<endl;
- float sum=0.0;
- for(int i = 0 ; i < n ; i ++)
- {
- sum+=toys[i]->getWeight();
- }
- if(sum>Petra.getWeight())
- cout<<"YES"<<endl;
- else
- {
- cout<<"NO"<<endl;
- }
- //cout<<"test"<<endl;
- //cout<<sum;
- float maxVolume=0;
- for(int i=0;i<n;i++)
- {
- if(toys[i]->getVolume() >maxVolume)
- {
- maxVolume=toys[i]->getVolume();
- }
- }
- float difference=0;
- difference=maxVolume - Petra.getVolume();
- if(difference<0)
- {
- difference=0-difference;
- }
- cout<<"The difference is: "<<difference<<endl;
- return 0;
- }
Add Comment
Please, Sign In to add comment