Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- #include <cstdio>
- #include <cmath>
- using namespace std;
- class igracki{
- protected:
- char boja[100];
- int gustina;
- public:
- igracki(){
- gustina=0;
- }
- igracki(char b[100],int g){
- strcpy(boja,b);
- gustina=g;
- }
- virtual double getMasa()=0;
- virtual double getVolumen()=0;
- };
- class kocka: public igracki{
- private:
- int visina;
- int sirina;
- int dlabocina;
- public:
- kocka():igracki(){
- visina=0;
- sirina=0;
- dlabocina=0;
- }
- kocka(char b[100],int g,int v,int s,int d):igracki(b,g){
- visina=v;
- sirina=s;
- dlabocina=d;
- }
- double getMasa(){
- return gustina*getVolumen();
- }
- double getVolumen(){
- return visina*sirina*dlabocina;
- }
- };
- class topka:public igracki{
- private:
- int radius;
- public:
- topka():igracki(){
- radius=0;
- }
- topka(char b[100],int g ,int r):igracki(b,g){
- radius=r;
- }
- double getMasa(){
- return getVolumen()*gustina;
- }
- double getVolumen(){
- return (4*radius*radius*radius*3.14)/3.0;
- }
- };
- int main(){
- int n,b,gustina,radius,visina,sirina,dlabocina;
- char ime[50];
- cin>>n;
- igracki **kupche=new igracki*[n];
- for(int i=0;i<n;i++)
- {
- cin>>b;
- if(b==1)
- {
- cin>>ime;
- cin>>gustina;
- cin>>radius;
- //topka t(ime,gustina,radius);
- kupche[i]=new topka(ime,gustina,radius);
- }
- else if(b==2)
- {
- cin>>ime;
- cin>>gustina;
- cin>>visina;
- cin>>sirina;
- cin>>dlabocina;
- kupche[i]= new kocka(ime,gustina,visina,sirina,dlabocina);
- //kocka k(ime,gustina,visina,sirina,dlabocina);
- //kupche[i]=&k;
- }
- }
- cin>>ime;
- cin>>gustina;
- cin>>visina;
- cin>>sirina;
- cin>>dlabocina;
- kocka Petra=kocka(ime,gustina,visina,sirina,dlabocina);
- double vkupnamasa=0;double maxVol=(*kupche[0]).getVolumen();
- for(int i=0;i<n;i++)
- {
- vkupnamasa+=(*kupche[i]).getMasa();
- //cout << (*kupche[i]).getMasa();
- if(maxVol<(*kupche[i]).getVolumen())
- maxVol=(*kupche[i]).getVolumen();
- }
- if(vkupnamasa>Petra.getMasa())
- cout<<"DA"<<endl;
- else
- cout<<"NE"<<endl;
- //cout << maxVol;
- //printf("%.2f",maxVol);
- cout<<"Razlikata e: "<<abs(maxVol-Petra.getVolumen());
- //vnesi informacii za kupche
- //vnesi informacii za igrachkata na Petra
- //baranje 1
- //baranje 2
- return 0;
- }
Add Comment
Please, Sign In to add comment