Facebook
From Tinct Crow, 5 Years ago, written in Plain Text.
This paste is a reply to Untitled from Crippled Macaw - view diff
Embed
Download Paste or View Raw
Hits: 344
  1. #include <iostream>
  2. #include <cmath>
  3. #include <fstream>
  4. #include <regex>
  5. #include <exception>
  6.  
  7. class Regular_Pyramid
  8. {
  9. protected:
  10.         std::string name;
  11.         double side;
  12.         double height;
  13.         double total_area = 1.0;
  14. public:
  15.         static int ostroslupy_duze;
  16.  
  17.         Regular_Pyramid()
  18.         {
  19.                 name = "Pyramid";
  20.                 side = 1;
  21.                 height = 1;
  22.         }
  23.  
  24.         Regular_Pyramid(std::string name, double side, double height)
  25.         {
  26.                 this->name = name;
  27.                 this->side = side;
  28.                 this->height = height;
  29.         }
  30.         ~Regular_Pyramid() = default;
  31.  
  32.     virtual void calculate_area()
  33.         {
  34.                 /*double triangle_height;
  35.                 triangle_height = sqrt(height*height + 0.25 * side * side);
  36.                 total_area = side * side + 4 * triangle_height * 0.5 * side;
  37.                 std::cout << "Pole powierzchni ostroslupa " << name << " jest rowne: " << total_area << std::endl;*/
  38.         }
  39.  
  40. };
  41.  
  42. class Square_Regular_Pyramid : public Regular_Pyramid
  43. {
  44. public:
  45.    
  46.     void calculate_area() override
  47.     {
  48.         /*double triangle_height;
  49.         triangle_height = sqrt(height*height + 0.25 * side * side);
  50.         total_area = side * side + 4 * triangle_height * 0.5 * side;
  51.         std::cout << "Pole powierzchni ostroslupa " << name << " jest rowne: " << total_area << std::endl;*/
  52.         total_area = 2 * side * sqrt(height * height + 0.25 * side * side) + side * side;
  53.     }
  54.     void operator-(int b)
  55.     {
  56.         try
  57.         {
  58.             if(side <= 0) throw "Nie mozna zmiejszyc o podana dlugosc";
  59.             side = side - b;
  60.         }
  61.         catch(const char* e)
  62.         {
  63.             std::cout << e << std::endl;
  64.         }
  65.     }
  66. };