Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <clocale>
- using namespace std;
- class Tbody
- {
- protected:
- float R;
- public:
- Tbody()
- {
- this->R = 0;
- }
- Tbody(float newR)
- {
- this->R = newR;
- }
- virtual float volume(){}
- virtual float area(){}
- };
- class TBall: Tbody
- {
- public:
- TBall():Tbody(){}
- TBall(float newR):Tbody(newR){}
- virtual float volume()
- {
- return (4*3.1415926*pow(this->R,3))/3;
- }
- virtual float area()
- {
- return (4*3.1415926*pow(this->R,2));
- }
- friend ostream &operator<<(ostream &stream, TBall* obj);
- friend istream &operator>>(istream &stream, TBall** obj);
- };
- ostream &operator<<(ostream &stream, TBall* obj)
- {
- cout<<"Радиус сферы равен "<<obj->R<<endl;
- return stream;
- }
- istream &operator>>(istream &stream, TBall** obj)
- {
- float newR;
- cout<<"Введите радиус сферы"<<endl;
- cout<<"R=";
- cin>>newR;
- *obj = new TBall(newR);
- return stream;
- }
- class TCone: Tbody
- {
- private:
- float H;
- public:
- TCone()
- {
- this->H = 0;
- }
- TCone(float newR, float newH):Tbody(newR)
- {
- this->H = newH;
- }
- virtual float volume()
- {
- return (3.1415926*pow(this->R,2)*this->H)/3;
- }
- virtual float area()
- {
- return 3.1415926*this->R*(this->R+sqrt(pow(this->R,2)+pow(this->H,2)));
- }
- friend ostream &operator<<(ostream &stream, TCone* obj);
- friend istream &operator>>(istream &stream, TCone** obj);
- };
- ostream &operator<<(ostream &stream, TCone* obj)
- {
- cout<<"Радиус основания конуса равен "<<obj->R<<endl;
- cout<<"Высота конуса равна "<<obj->H<<endl;
- return stream;
- }
- istream &operator>>(istream &stream, TCone** obj)
- {
- float newR, newH;
- cout<<"Введите радиус основания конуса"<<endl;
- cout<<"R=";
- cin>>newR;
- cout<<"Введите высоту конуса"<<endl;
- cout<<"H=";
- cin>>newH;
- *obj = new TCone(newR, newH);
- return stream;
- }
- int main()
- {
- setlocale(LC_ALL,"RU");
- TBall* ball = new TBall(10);
- TCone* cone = new TCone(5,6);
- cout<<"Площадь поверщности сферы "<<ball->area()<<endl;
- cout<<"Объем шара "<<ball->volume()<<endl;
- cout<<"Площадь поверхности конуса "<<cone->area()<<endl;
- cout<<"Объем конуса "<<cone->volume()<<endl;
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement