Advertisement
awsmpshk

Untitled

Mar 25th, 2020
198
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <type_traits>
  3. #include <cmath>
  4.  
  5. using namespace std;
  6.  
  7. template <typename t1, typename t2>
  8. class Triangle {
  9. private:
  10.     t1 a;
  11.     t1 b;
  12.     t1 c;
  13. public:
  14.     Triangle() {
  15.         this->a = 0;
  16.         this->b = 0;
  17.         this->c = 0;
  18.     }
  19.     Triangle(int a, int b, int c) {
  20.         this->a = a;
  21.         this->b = b;
  22.         this->c = c;
  23.     }
  24.     Triangle(t1 side) {
  25.         this->a = side;
  26.         this->b = side;
  27.         this->c = side;
  28.     }
  29.     Triangle(const Triangle& t) {
  30.         this->a = t.a;
  31.         this->b = t.b;
  32.         this->c = t.c;
  33.     }
  34.  
  35.     friend ostream& operator<<(ostream& out, const Triangle t) {
  36.         out << this->a << " " << this->b << " " << this->c << endl;
  37.         return out;
  38.     }
  39.  
  40.     t1 per() {
  41.         cout << this->a + this->b + this->c << endl;
  42.         return this->a + this->b + this->c;
  43.     }
  44.     t2 sqr() {
  45.         int p = per() / 2;
  46.         cout << sqrt(p * (p - this->a) * (p - this->b) * (p - this->c)) << endl;
  47.         return sqrt(p * (p - this->a) * (p - this->b) * (p - this->c));
  48.     }
  49. };
  50.  
  51. int main() {
  52.     setlocale(LC_ALL, "rus");
  53.     Triangle<int, double> t1;
  54.     Triangle<int, double> t2 = t1;
  55.     cout << t1 << t2;
  56.  
  57.     Triangle<int, double> t3(4);
  58.     Triangle<int, double> t4 = t3;
  59.     cout << t3 << t4;
  60.  
  61.     Triangle<int, double> t5(3, 4, 5);
  62.     Triangle<int, double> t6 = t5;
  63.     cout << t5 << t6;
  64. }
Advertisement
RAW Paste Data Copied
Advertisement