Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- enum thuoctinh
- {
- CAN, DEU, VUONGCAN, VUONG, THUONG
- };
- struct diem
- {
- float x, y;
- };
- struct tamgiac
- {
- diem A, B, C;
- };
- void nhap(diem &d)
- {
- cout << "Nhap hoanh do = ";
- cin >> d.x;
- cout << "Nhap tung do = ";
- cin >> d.y;
- }
- void xuat(diem d)
- {
- cout << "(" << d.x << ";" << d.y << ")" << endl;
- }
- double khoangcach(diem a, diem b)
- {
- return sqrt(pow(a.x - b.x, 2) + pow(a.y - b.y, 2));
- }
- int kiemtra(tamgiac ABC)
- {
- double a = khoangcach(ABC.A, ABC.B);
- double b = khoangcach(ABC.B, ABC.C);
- double c = khoangcach(ABC.C, ABC.A);
- if (a + b > c || a + c > b || b + c > a)
- {
- if (a == b || b == c || a == c)
- {
- if (a == b && a == c) return DEU;
- else
- {
- if (a * a + b * b == c * c || a * a + c * c == b * b || c * c + b * b == a * a) return VUONGCAN;
- else return CAN;
- }
- }
- if (a * a + b * b == c * c || a * a + c * c == b * b || c * c + b * b == a * a) return VUONG;
- else return THUONG;
- }
- return -1;
- }
- int NhapTamGiac(tamgiac &ABC)
- {
- nhap(ABC.A);
- nhap(ABC.B);
- nhap(ABC.C);
- int t = kiemtra(ABC);
- if (t == -1) NhapTamGiac(ABC);
- else return t;
- }
- void ChuViDienTich(tamgiac ABC, double &cv, double &dt)
- {
- double a = khoangcach(ABC.A, ABC.B);
- double b = khoangcach(ABC.B, ABC.C);
- double c = khoangcach(ABC.C, ABC.A);
- cout << a << b << c;
- cv = a + b + c;
- dt = sqrt(cv * (cv / 2 - a) * (cv / 2 - b) * (cv / 2 - c) / 2);
- }
- void main()
- {
- tamgiac ABC;
- int t;
- double cv = 0, dt = 0;
- t = NhapTamGiac(ABC);
- switch (t)
- {
- case THUONG:
- cout << "Tam giac thuong\n";
- break;
- case CAN:
- cout << "Tam giac can\n";
- break;
- case VUONGCAN:
- cout << "Tam giac vuong can\n";
- break;
- case VUONG:
- cout << "Tam giac vuong\n";
- break;
- case DEU:
- cout << "Tam giac deu\n";
- break;
- }
- ChuViDienTich(ABC, cv, dt);
- cout << "Chu vi: " << cv << "\nDien tich: " << dt;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement