Advertisement
Razorspined

Untitled

Nov 1st, 2022
766
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.30 KB | None | 0 0
  1. #define _USE_MATH_DEFINES
  2. #include <iostream>
  3. #include <cmath>
  4. #include <vector>
  5.  
  6.  
  7. using namespace std;
  8.  
  9. class pyramid;
  10. class cylinder {
  11. public:
  12.     double h;
  13.     double r;
  14.  
  15.     cylinder();
  16.     cylinder(double, double);
  17.  
  18.     double areaofc();
  19.     bool IsHigher(pyramid);
  20.  
  21.     friend istream& operator>>(istream&, cylinder&);
  22. };
  23.  
  24. // pass by reference
  25. // pass by value
  26.  
  27. class pyramid {
  28. private:
  29.     double side_of_rect;
  30.     double h;
  31.  
  32. public:
  33.  
  34.     pyramid();
  35.     pyramid(double, double);
  36.  
  37.     double areaofp();
  38.  
  39.     friend bool cylinder::IsHigher(pyramid);
  40.     friend istream& operator>>(istream&, pyramid&);
  41. };
  42.  
  43. istream& operator>>(istream& left, cylinder& right) {
  44.     left >> right.h;
  45.     left >> right.r;
  46.     return left;
  47. }
  48.  
  49. istream& operator>>(istream& left, pyramid& right) {
  50.     left >> right.side_of_rect;
  51.     left >> right.h;
  52.     return left;
  53. }
  54.  
  55. cylinder::cylinder() {}
  56.  
  57. cylinder::cylinder(double a, double b) {
  58.     h = a;
  59.     r = b;
  60. }
  61.  
  62. double cylinder::areaofc() {
  63.     double  area;
  64.     area = (2 * M_PI * r * h) + (2 * M_PI * pow(r, 2));
  65.  
  66.     return area;
  67. }
  68.  
  69. bool cylinder::IsHigher(pyramid p) {
  70.     return h > p.h;
  71. }
  72.  
  73. pyramid::pyramid() {}
  74.  
  75. pyramid::pyramid(double a, double b) {
  76.     h = a;
  77.     side_of_rect = b;
  78. }
  79.  
  80. double pyramid::areaofp() {
  81.     double area;
  82.     double unknown_h;
  83.     unknown_h = sqrt(pow(h, 2) + pow(side_of_rect/2, 2));
  84.     area = pow(side_of_rect, 2) + ((side_of_rect * unknown_h) / 2) * 4;
  85.  
  86.     return area;
  87. }
  88.  
  89. int main()
  90. {
  91.     /*cylinder c1(4.5, 2);
  92.     c1.areaofc();
  93.     cout << c1.areaofc() << endl;
  94.     pyramid p1(8.4, 3);
  95.     p1.areaofp();
  96.     cout << p1.areaofp() << endl;
  97.     c1.IsHigher(p1);
  98.     cout << c1.IsHigher(p1) << endl;
  99.  
  100.     int a;
  101.     int numbers[20];
  102.     numbers[0] = 10;
  103.     vector<int>  numbers2;
  104.     numbers2.push_back(1000);*/
  105.  
  106.     vector<pyramid> pyramids;
  107.     vector<cylinder> cylinders;
  108.  
  109.     cout << "how many objects do you want to compare?" << endl;
  110.     int count;
  111.     cin >> count;
  112.  
  113.     for (int y = 0; y < count; y++) {
  114.         cout << "enter h and r for cylinder: " << endl;
  115.         cylinder c;
  116.         cin >> c;
  117.         cout << endl;
  118.  
  119.         cout << "enter h and base side for pyramid: " << endl;
  120.         pyramid p;
  121.         cin >> p;
  122.         cout << endl;
  123.  
  124.         pyramids.push_back(p);
  125.         cylinders.push_back(c);
  126.     }
  127.  
  128.     for (int y = 0; y < count; y++) {
  129.         cout << "cylinder " << y << " is higher than pyramid " << y << ":" << cylinders[y].IsHigher(pyramids[y]) << endl;
  130.     }
  131. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement