SHARE
TWEET

volume

martukha Feb 18th, 2020 81 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #pragma once
  2. #include"figure.h"
  3. using namespace std;
  4. class VolumFigure {
  5. public:
  6.     virtual int volume() = 0;
  7.     virtual int side_area() = 0;
  8.     virtual int full_area() = 0;
  9.     virtual int basis_area() = 0;
  10.  
  11.     virtual ~VolumFigure() {};
  12. };
  13.  
  14. class Prism :public VolumFigure {
  15. protected:
  16.     Polygon* basis;
  17.     int height;
  18. public:
  19.     Prism() :basis(nullptr), height(0) {}
  20.     Prism(Polygon* p_basis, int p_height) :basis(p_basis), height(p_height) {}
  21.     Prism(const  Prism& p) :basis(p.basis), height(p.height) {}
  22.  
  23.     int volume(){
  24.         return basis->shape_area() * height;
  25.     }
  26.     int side_area() {
  27.         return basis->shape_perimetr() * height;
  28.     }
  29.     int full_area() {
  30.         return 2 * basis->shape_area() + side_area();
  31.     }
  32.     int basis_area() {
  33.         return basis->shape_area();
  34.     }
  35.  
  36.     friend ostream& operator<<(ostream& out, const Prism& p) {
  37.         out << "Prism basis is " << p.basis->get_shape() << "Height:" << p.height << "cm" << endl;
  38.         return out;
  39.     }
  40.     /*friend istream& operator>>(istream& in, Prism& p) {
  41.         in >> p.basis;
  42.         in >> p.height;
  43.         return in;
  44.     }*/
  45. };
  46.  
  47. class Cube : public VolumFigure {
  48. protected:
  49.     Square* basis;
  50. public:
  51.     Cube() :basis(0) {}
  52.     Cube(Square* c_basis) :basis(c_basis) {}
  53.     Cube(const Cube& c) :basis(c.basis) {}
  54.  
  55.     int volume() {
  56.         return pow(basis->get_diagonal(), 3);
  57.     }
  58.     int side_area() {
  59.         return (basis->shape_area() * 4);
  60.     }
  61.     int full_area() {
  62.         return (pow(basis->get_diagonal(),2)*6);
  63.     }
  64.     int basis_area() {
  65.         return basis->shape_area();
  66.     }
  67.     friend ostream& operator<<(ostream& out, const Cube& c) {
  68.         out << c.basis->get_shape()<< endl;
  69.         return out;
  70.     }
  71.     /*friend istream& operator>>(istream& in, Cube& c) {
  72.         in >> c.basis;
  73.         return in;
  74.     }*/
  75.  };
  76.  
  77. class Cylinder : public VolumFigure {
  78. protected:
  79.     Circle* basis;
  80.     int height;
  81. public:
  82.     Cylinder() :basis(nullptr), height(0) {}
  83.     Cylinder(Circle* c_basis, int c_height) :basis(c_basis), height(c_height) {}
  84.     Cylinder(const Cylinder& c) :basis(c.basis), height(c.height) {}
  85.  
  86.     int volume() {
  87.         return (basis->shape_area() * height);
  88.     }
  89.     int side_area() {
  90.         return basis->shape_perimetr() * height;
  91.     }
  92.     int full_area() {
  93.         return 2 * basis->shape_perimetr() + side_area();
  94.     }
  95.     int basis_area() {
  96.         return basis->shape_area();
  97.     }
  98.  
  99.     friend ostream& operator<<(ostream& out, const Cylinder& c) {
  100.         out << "Cylinder basis is " << c.basis->get_shape() << "Height:" << c.height << "cm" << endl;
  101.         return out;
  102.     }
  103.     /*friend istream& operator>>(istream& in, Cylinder& c) {
  104.         in >> c.basis;
  105.         in >> c.height;
  106.         return in;
  107.     }*/
  108. };
  109.  
  110. class Cone : public Cylinder {
  111. public:
  112.     Cone() {}
  113.     Cone(Circle* c_basis, int c_height) :Cylinder(c_basis, c_height) {}
  114.     Cone(const Cone& c) :Cylinder(c) {}
  115.  
  116.     int volume() {
  117.         return (basis->shape_area() * height) / 3;
  118.     }
  119.     int side_area() {
  120.         return 3, 14 * basis->get_radius() * sqrt(pow(height, 2) - pow(basis->get_radius(), 2));
  121.     }
  122.     int full_area() {
  123.         return basis->shape_area() + side_area();
  124.     }
  125.     int basis_area() {
  126.         return basis->shape_area();
  127.     }
  128.  
  129.     friend ostream& operator<<(ostream& out, const Cone& c) {
  130.         out << "Cone basis is " << c.basis->get_shape() << "Height:" << c.height << "cm" << endl;
  131.         return out;
  132.     }
  133.     /*friend istream& operator>>(istream& in, Cone& c) {
  134.         in >> c.basis;
  135.         in >> c.height;
  136.         return in;
  137.     }*/
  138. };
  139.  
  140. class Ball :public VolumFigure {
  141. protected:
  142.     Circle* basis;
  143. public:
  144.     Ball() :basis(0) {}
  145.     Ball(Circle* b_basis) :basis(b_basis) {}
  146.     Ball(const Ball& b) :basis(b.basis) {}
  147.  
  148.     int volume() {
  149.         return 3, 14 * (4 / 3) * pow(basis->get_radius(), 3);
  150.     }
  151.     int side_area() {
  152.         return 4 * 3, 14 * pow(basis->get_radius(), 2);
  153.     }
  154.     int full_area() {
  155.         return side_area();
  156.     }
  157.     int basis_area() {
  158.         return basis->shape_area();
  159.     }
  160.  
  161.     friend ostream& operator<<(ostream& out, const Ball& b) {
  162.         out << "Bole basis is " << b.basis->get_shape() << endl;
  163.         return out;
  164.     }
  165.     /*friend istream& operator>>(istream& in, Ball& b) {
  166.         in >> b.basis;
  167.         return in;
  168.     }*/
  169. };
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top