Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _USE_MATH_DEFINES
- #include <iostream>
- #include <cmath>
- #include <vector>
- using namespace std;
- class pyramid;
- class cylinder {
- public:
- double h;
- double r;
- cylinder();
- cylinder(double, double);
- double areaofc();
- bool IsHigher(pyramid);
- friend istream& operator>>(istream&, cylinder&);
- };
- // pass by reference
- // pass by value
- class pyramid {
- private:
- double side_of_rect;
- double h;
- public:
- pyramid();
- pyramid(double, double);
- double areaofp();
- friend bool cylinder::IsHigher(pyramid);
- friend istream& operator>>(istream&, pyramid&);
- };
- istream& operator>>(istream& left, cylinder& right) {
- left >> right.h;
- left >> right.r;
- return left;
- }
- istream& operator>>(istream& left, pyramid& right) {
- left >> right.side_of_rect;
- left >> right.h;
- return left;
- }
- cylinder::cylinder() {}
- cylinder::cylinder(double a, double b) {
- h = a;
- r = b;
- }
- double cylinder::areaofc() {
- double area;
- area = (2 * M_PI * r * h) + (2 * M_PI * pow(r, 2));
- return area;
- }
- bool cylinder::IsHigher(pyramid p) {
- return h > p.h;
- }
- pyramid::pyramid() {}
- pyramid::pyramid(double a, double b) {
- h = a;
- side_of_rect = b;
- }
- double pyramid::areaofp() {
- double area;
- double unknown_h;
- unknown_h = sqrt(pow(h, 2) + pow(side_of_rect/2, 2));
- area = pow(side_of_rect, 2) + ((side_of_rect * unknown_h) / 2) * 4;
- return area;
- }
- int main()
- {
- /*cylinder c1(4.5, 2);
- c1.areaofc();
- cout << c1.areaofc() << endl;
- pyramid p1(8.4, 3);
- p1.areaofp();
- cout << p1.areaofp() << endl;
- c1.IsHigher(p1);
- cout << c1.IsHigher(p1) << endl;
- int a;
- int numbers[20];
- numbers[0] = 10;
- vector<int> numbers2;
- numbers2.push_back(1000);*/
- vector<pyramid> pyramids;
- vector<cylinder> cylinders;
- cout << "how many objects do you want to compare?" << endl;
- int count;
- cin >> count;
- for (int y = 0; y < count; y++) {
- cout << "enter h and r for cylinder: " << endl;
- cylinder c;
- cin >> c;
- cout << endl;
- cout << "enter h and base side for pyramid: " << endl;
- pyramid p;
- cin >> p;
- cout << endl;
- pyramids.push_back(p);
- cylinders.push_back(c);
- }
- for (int y = 0; y < count; y++) {
- cout << "cylinder " << y << " is higher than pyramid " << y << ":" << cylinders[y].IsHigher(pyramids[y]) << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement