1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4.  
  5. class triangle
  6. {
  7. private: //members
  8. int a; //declarations
  9. int b;
  10. int c;
  11.  
  12. //Area = sq rt{s(s - a)(s - b)(s - c)}
  13.  
  14. public: //methods "functions"
  15. triangle(); //declarations but no deffinitions
  16.  
  17. void set_a(int d);
  18. void set_b(int e);
  19. void set_c(int f);
  20.  
  21. int calc_perimeter();
  22. double calc_area();
  23. };
  24.  
  25. // definitions of methods (not-inline vs. inline)
  26.  
  27. triangle::triangle() //refers to method in rectangle class
  28. {
  29.  
  30. a = 5;
  31. b = 16;
  32. c = 15;
  33.  
  34. // Triangle inequality theorem: A + B > C, B + C > A, A + C > B
  35. }
  36.  
  37.  
  38.  
  39. void triangle::set_a(int d)// for cin
  40. {
  41. a = d;
  42. }
  43. void triangle::set_b(int e)// for cin
  44. {
  45. b = e;
  46. }
  47. void triangle::set_c(int f)// for cin
  48. {
  49. c = f;
  50. }
  51.  
  52. int triangle::calc_perimeter()
  53. {
  54. return (a+b+c);
  55. }
  56. double triangle::calc_area()
  57. {
  58. double s = (a+b+c)/2;
  59. return (sqrt(s*(s - a)*(s - b)*(s - c)));
  60. }
  61.  
  62. int main()
  63. {
  64. triangle t; // declaring OBJECT t of triangle class
  65.  
  66. cout << "Perimeter: " << t.calc_perimeter() << endl << "Area: " << t.calc_area() << endl;
  67.  
  68. cout << "Enter three sides of triangle Remember A + B > C, B + C > A, A + C > B: ";
  69. int g,h,i = 0;
  70. cin >> g >> h >> i;
  71.  
  72. t.set_a(g);
  73. t.set_b(h);
  74. t.set_c(i);
  75.  
  76. cout << "Perimeter: " << t.calc_perimeter() << endl << "Area: " << t.calc_area() << endl;
  77.  
  78. return 0;
  79. }