Untitled
user_2559545
plain_text
a year ago
881 B
8
Indexable
#include <bits/stdc++.h>
using namespace std;
// T
class Rectangle {
public:
Rectangle(int length, int width) : length_(length), width_(width) {}
virtual int GetPerimeter() {
return 2 * (length_ + width_);
}
virtual int GetArea() {
return length_ * width_;
}
private:
int length_, width_;
};
// S
class Square : public Rectangle {
public:
Square(int length) : Rectangle(length, length) {}
};
// Code using T
pair<int,int> GetRectangleInformation(Rectangle &rectangle) {
return {rectangle.GetArea(), rectangle.GetPerimeter()};
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
Rectangle rectangle(4, 2);
auto it = GetRectangleInformation(rectangle);
cout << it.first << " " << it.second << endl;
Square square(5);
it = GetRectangleInformation(square);
cout << it.first << " " << it.second << endl;
return 0;
}
Editor is loading...
Leave a Comment