Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <type_traits>
- #include <cmath>
- using namespace std;
- template <typename t1, typename t2>
- class Triangle {
- private:
- t1 a;
- t1 b;
- t1 c;
- public:
- Triangle() {
- this->a = 0;
- this->b = 0;
- this->c = 0;
- }
- Triangle(int a, int b, int c) {
- this->a = a;
- this->b = b;
- this->c = c;
- }
- Triangle(t1 side) {
- this->a = side;
- this->b = side;
- this->c = side;
- }
- Triangle(const Triangle& t) {
- this->a = t.a;
- this->b = t.b;
- this->c = t.c;
- }
- friend ostream& operator<<(ostream& out, const Triangle t) {
- out << this->a << " " << this->b << " " << this->c << endl;
- return out;
- }
- t1 per() {
- cout << this->a + this->b + this->c << endl;
- return this->a + this->b + this->c;
- }
- t2 sqr() {
- int p = per() / 2;
- cout << sqrt(p * (p - this->a) * (p - this->b) * (p - this->c)) << endl;
- return sqrt(p * (p - this->a) * (p - this->b) * (p - this->c));
- }
- };
- int main() {
- setlocale(LC_ALL, "rus");
- Triangle<int, double> t1;
- Triangle<int, double> t2 = t1;
- cout << t1 << t2;
- Triangle<int, double> t3(4);
- Triangle<int, double> t4 = t3;
- cout << t3 << t4;
- Triangle<int, double> t5(3, 4, 5);
- Triangle<int, double> t6 = t5;
- cout << t5 << t6;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement