Odpowiedź :
Odpowiedź:
#include <iostream>
#include<cmath>
using namespace std;
class kolo
{
unsigned r;
public:
kolo(unsigned r)
{
this->r=r;
}
unsigned policz_pole()
{
return (4/3)*M_PI*r*r*r;
}
};
class prostokat
{
unsigned a,b;
public:
prostokat(unsigned a,unsigned b)
{
this->a=a;
this->b=b;
}
unsigned pole()
{
return a*b;
}
};
class trapez
{
unsigned a,b,h;
public:
trapez(unsigned a,unsigned b,unsigned h)
{
this->a=a;
this->b=b;
this->h=h;
}
unsigned pole()
{
return ((a+b)*h)/2;
}
};
class trojkat
{
unsigned a,h;
public:
trojkat(unsigned a,unsigned h)
{
this->a=a;
this->h=h;
}
unsigned pole()
{
return a*h/2;
}
};
class szescian
{
unsigned a;
public:
szescian(unsigned a)
{
this->a=a;
}
unsigned pole()
{
return a*a*6;
}
unsigned objetosc()
{
return a*a*a;
}
};
int main()
{
int c;
int x,y,z;
cout<<"jaka figure chcesz stworzyc?\n";
cout<<"0 - kolo \n";
cout<<"1 - prostokat \n";
cout<<"2 - trapez \n";
cout<<"3 - trojkat \n";
cout<<"4 - szescian \n";
cin>>c;
if(c==0)
{
cout<<"podaj r\n";
cin>>z;
kolo k1(z);
cout<<"pole wynosi: "<<k1.policz_pole()<<endl;
}
else if(c==1)
{
cout<<"podaj a i b\n";
cin>>z>>x;
prostokat p1(z,x);
cout<<"pole wynosi: "<<p1.pole()<<endl;
}
else if(c==2)
{
cout<<"podaj a i b i h\n";
cin>>z>>x>>y;
trapez t1(z,x,y);
cout<<"pole wynosi: "<<t1.pole()<<endl;
}
else if(c==3)
{
cout<<"podaj a h\n";
cin>>z>>x;
trojkat tt1(z,x);
cout<<"pole wynosi: "<<tt1.pole()<<endl;
}
else if(c==4)
{
cout<<"podaj a \n";
cin>>z;
szescian s1(z);
cout<<"pole wynosi: "<<s1.pole()<<endl;
cout<<"objetosc wynosi: "<<s1.objetosc()<<endl;
}
else
{
cout<<"podano zla wartosc!\n";
}
return 0;
}
Wyjaśnienie:
liczę na naj ;)