Advertisement
huutho_96

Tam giác

Apr 11th, 2015
401
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.89 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. enum thuoctinh
  4. {
  5. CAN, DEU, VUONGCAN, VUONG, THUONG
  6. };
  7. struct diem
  8. {
  9. float x, y;
  10. };
  11. struct tamgiac
  12. {
  13. diem A, B, C;
  14. };
  15. void nhap(diem &d)
  16. {
  17. cout << "Nhap hoanh do = ";
  18. cin >> d.x;
  19. cout << "Nhap tung do = ";
  20. cin >> d.y;
  21. }
  22. void xuat(diem d)
  23. {
  24. cout << "(" << d.x << ";" << d.y << ")" << endl;
  25. }
  26. double khoangcach(diem a, diem b)
  27. {
  28. return sqrt(pow(a.x - b.x, 2) + pow(a.y - b.y, 2));
  29. }
  30. int kiemtra(tamgiac ABC)
  31. {
  32. double a = khoangcach(ABC.A, ABC.B);
  33. double b = khoangcach(ABC.B, ABC.C);
  34. double c = khoangcach(ABC.C, ABC.A);
  35. if (a + b > c || a + c > b || b + c > a)
  36. {
  37. if (a == b || b == c || a == c)
  38. {
  39. if (a == b && a == c) return DEU;
  40. else
  41. {
  42. if (a * a + b * b == c * c || a * a + c * c == b * b || c * c + b * b == a * a) return VUONGCAN;
  43. else return CAN;
  44. }
  45. }
  46. if (a * a + b * b == c * c || a * a + c * c == b * b || c * c + b * b == a * a) return VUONG;
  47. else return THUONG;
  48. }
  49. return -1;
  50. }
  51. int NhapTamGiac(tamgiac &ABC)
  52. {
  53. nhap(ABC.A);
  54. nhap(ABC.B);
  55. nhap(ABC.C);
  56. int t = kiemtra(ABC);
  57. if (t == -1) NhapTamGiac(ABC);
  58. else return t;
  59. }
  60. void ChuViDienTich(tamgiac ABC, double &cv, double &dt)
  61. {
  62. double a = khoangcach(ABC.A, ABC.B);
  63. double b = khoangcach(ABC.B, ABC.C);
  64. double c = khoangcach(ABC.C, ABC.A);
  65. cout << a << b << c;
  66. cv = a + b + c;
  67. dt = sqrt(cv * (cv / 2 - a) * (cv / 2 - b) * (cv / 2 - c) / 2);
  68. }
  69. void main()
  70. {
  71. tamgiac ABC;
  72. int t;
  73. double cv = 0, dt = 0;
  74. t = NhapTamGiac(ABC);
  75. switch (t)
  76. {
  77. case THUONG:
  78. cout << "Tam giac thuong\n";
  79. break;
  80. case CAN:
  81. cout << "Tam giac can\n";
  82. break;
  83. case VUONGCAN:
  84. cout << "Tam giac vuong can\n";
  85. break;
  86. case VUONG:
  87. cout << "Tam giac vuong\n";
  88. break;
  89. case DEU:
  90. cout << "Tam giac deu\n";
  91. break;
  92. }
  93. ChuViDienTich(ABC, cv, dt);
  94. cout << "Chu vi: " << cv << "\nDien tich: " << dt;
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement