Untitled
unknown
plain_text
a year ago
980 B
18
Indexable
#include <bits/stdc++.h> using namespace std; // Interface class TwoDimentionShapeInterface { public: virtual double GetArea() = 0; }; class ThreeDimentionShapeInterface { public: virtual double GetArea() = 0; virtual double GetVolume() = 0; }; // Client1 class Square : public TwoDimentionShapeInterface { public: Square(int len) : len_(len) {} double GetArea() override { return len_ * len_; } private: int len_; }; // Client2 class Sphere : public ThreeDimentionShapeInterface { public: Sphere(int radius) : radius_(radius) {} double GetArea() override { return 4 * 3.14 * radius_ * radius_; } double GetVolume() override { return 4 * 3.14 * radius_ * radius_ * radius_ / 3; } private: int radius_; }; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); Sphere sphere(2); cout << sphere.GetArea() << " " << sphere.GetVolume() << endl; Square square(5); cout << square.GetArea() << endl; return 0; }
Editor is loading...
Leave a Comment