Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- #include <cmath>
- using namespace std;
- class Igrachka {
- public:
- virtual float getVolumen() = 0;
- virtual float getMasa() = 0;
- };
- class Forma{
- protected:
- char boja[100];
- int gustina;
- public:
- // да се имплементираат потребните методи
- Forma(char* boja,int gustina){
- strcpy(this->boja,boja);
- this->gustina=gustina;
- }
- };
- class Topka:public Igrachka, public Forma{
- protected:
- int r;
- public:
- Topka(char* boja,int gustina,int radius):Forma(boja,gustina){
- r=radius;
- }
- float getVolumen(){
- return 4*r*r*r*3.14/3;
- }
- float getMasa(){
- return this->getVolumen()*gustina;
- }
- };
- class Kocka:public Igrachka, public Forma{
- protected:
- int h;
- int w;
- int d;
- public:
- Kocka(char* boja,int gustina,int visina,int shirina,int dlabochina):Forma(boja,gustina){
- h=visina;
- w=shirina;
- d=dlabochina;
- }
- float getVolumen(){
- return h*w*d;
- }
- float getMasa(){
- return this->getVolumen()*gustina;
- }
- };
- int main(){
- //vnesi informacii za kupche
- Igrachka **kupche;
- int n;
- cin>>n;
- kupche=new Igrachka*[n];
- char boja[100];
- int gustina;
- int radius;
- int shirina,visina,dlabochina;
- int m;
- for(int i=0;i<n;i++){
- cin>>m;
- if(m==1){ //Topka
- cin>>boja>>gustina>>radius;
- kupche[i]=new Topka(boja,gustina,radius);
- } else{
- cin>>boja>>gustina>>visina>>shirina>>dlabochina;
- kupche[i]=new Kocka(boja,gustina,visina,shirina,dlabochina);
- }
- }
- //vnesi informacii za igrachkata na Petra
- cin>>boja>>gustina>>visina>>shirina>>dlabochina;
- Igrachka *petra=new Kocka(boja,gustina,visina,shirina,dlabochina);
- //baranje 1
- int vkupnaMasa=0;
- for(int i=0;i<n;i++){
- vkupnaMasa+=kupche[i]->getMasa();
- }
- (vkupnaMasa>petra->getMasa())? cout<<"DA"<<endl : cout<<"NE"<<endl;
- //baranje 2
- Igrachka *maxV=kupche[0];
- for(int i=1;i<n;i++){
- if(kupche[i]->getVolumen() > maxV->getVolumen())
- maxV=kupche[i];
- }
- cout<<"Razlikata e: "<<abs(maxV->getVolumen() - petra->getVolumen());
- delete petra;
- delete maxV;
- delete [] kupche;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement