Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- using namespace std;
- class Figure {
- protected:
- float a;
- float b;
- float p;
- public:
- void show() {
- cout << "Info:" << endl;
- calculate();
- info();
- }
- virtual float calculate() = 0;
- virtual void info() = 0;
- };
- class IsoscelesTriangle : public Figure {
- public:
- IsoscelesTriangle() {a = b = 0;}
- IsoscelesTriangle(float x, float y) {
- a = x;
- b = y;
- }
- float calculate() {
- p = a + 2 * b;
- cout << "p of isosceles triangle = " << p << endl;
- cout << endl;
- return p;
- }
- void info() {
- cout << "Info about isosceles triangle:" << endl;
- cout << "a = " << a << endl;
- cout << "b = " << b << endl;
- cout << endl;
- }
- friend istream& operator >> (istream& is, IsoscelesTriangle& a);
- bool operator > (const IsoscelesTriangle& a) {return this->a > a.a && b > a.b;}
- };
- istream& operator >> (istream& is, IsoscelesTriangle& a) {
- cout << "Enter info about isosceles triangle:" << endl;
- cout << "a = "; is >> a.a;
- cout << "b = "; is >> a.b;
- cout << endl;
- return is;
- }
- class RightTriangle : public Figure {
- public:
- RightTriangle() {a = b = 0;}
- RightTriangle(float x, float y) {
- a = x;
- b = y;
- }
- float calculate() {
- p = a + b + sqrt(a * a + b * b);
- cout << "p of right triangle = " << p << endl;
- cout << endl;
- return p;
- }
- void info() {
- cout << "Info about right triangle:" << endl;
- cout << "a = " << a << endl;
- cout << "b = " << b << endl;
- cout << endl;
- }
- friend istream& operator >> (istream& is, RightTriangle& a);
- bool operator > (const RightTriangle& a) {return this->a > a.a && b > a.b;}
- };
- istream& operator >> (istream& is, RightTriangle& a) {
- cout << "Enter info about right triangle:" << endl;
- cout << "a = "; is >> a.a;
- cout << "b = "; is >> a.b;
- cout << endl;
- return is;
- }
- int main() {
- int count;
- bool res;
- cout << "Enter count of objects: ";
- cin >> count;
- IsoscelesTriangle arr1[count];
- for (int i = 0; i < count; i++) {
- cout << "Enter " << i + 1 << " isosceles triangle:" << endl;
- cin >> arr1[i];
- }
- for (int i = 1; i < count; i++) {
- res = arr1[i - 1] > arr1[i];
- cout << "(" << i << " obj > " << i + 1 << " obj) = ";
- if (res) cout << "true" << endl;
- else cout << "false" << endl;
- }
- cout << endl;
- RightTriangle arr2[count];
- for (int i = 0; i < count; i++) {
- cout << "Enter " << i + 1 << " right triangle:" << endl;
- cin >> arr2[i];
- }
- for (int i = 1; i < count; i++) {
- res = arr2[i - 1] > arr2[i];
- cout << "(" << i << " obj > " << i + 1 << " obj) = ";
- if (res) cout << "true" << endl;
- else cout << "false" << endl;
- }
- cout << "------" << endl << endl;
- Figure* obj;
- obj = new IsoscelesTriangle(2, 3);
- obj->show();
- obj = new RightTriangle(3, 4);
- obj->show();
- }
Add Comment
Please, Sign In to add comment