Advertisement
Dr4noel

Triunghi

Apr 23rd, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.52 KB | None | 0 0
  1. #include <iostream>
  2. #include <math.h>
  3.  
  4. using namespace std;
  5.  
  6. class Triunghi {
  7. private:
  8.     float a;
  9.     float b;
  10.     float c;
  11.     static float checkA;
  12.     static float checkB;
  13.     static float checkC;
  14. public:
  15.     Triunghi(float a, float b, float c);
  16.  
  17.     static bool verifica();
  18.  
  19.     void arie();
  20.  
  21.     void perimetru();
  22.  
  23.     void esteDreptunghic();
  24. };
  25.  
  26. float Triunghi::checkA = 0;
  27. float Triunghi::checkB = 0;
  28. float Triunghi::checkC = 0;
  29.  
  30. Triunghi::Triunghi(float a, float b, float c) {
  31.     this->a = a;
  32.     this->b = b;
  33.     this->c = c;
  34.     checkA = a;
  35.     checkB = b;
  36.     checkC = c;
  37. }
  38.  
  39. void Triunghi::arie() {
  40.     float p = (a + b + c) / 2;
  41.  
  42.     cout << "Aria triunghiului este : " << sqrt(p*(p - a)*(p - b)*(p - c));
  43. }
  44.  
  45. void Triunghi::perimetru() {
  46.     cout << "\nPerimetrul triunghilui este : " << a + b + c;
  47. }
  48.  
  49. void Triunghi::esteDreptunghic() {
  50.     float x = pow(c,2);
  51.     float y = pow(a, 2) + pow(b, 2);
  52.     if (x == y) {
  53.         cout << "\nTriunghiul este dreptunghic!";
  54.     }
  55.     else {
  56.         cout << "\nTriunghiul nu este dreptunghic!";
  57.     }
  58. }
  59.  
  60. bool Triunghi::verifica() {
  61.     if ((checkA == 0) || (checkB == 0) || (checkC == 0)) {
  62.         return false;
  63.     }
  64.     else {
  65.         return true;
  66.     }
  67. }
  68.  
  69. void main() {
  70.     Triunghi a(3,4,5);
  71.  
  72.     if (a.verifica() == false) {
  73.         cout << "Laturile date nu pot forma un triunghi!\n";
  74.     }
  75.     else {
  76.         a.arie();
  77.  
  78.         a.perimetru();
  79.  
  80.         a.esteDreptunghic();
  81.     }
  82.     cin.get();
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement