Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- using std::cin;
- using std::cout;
- using std::endl;
- struct Point
- {
- double x;
- double y;
- double z;
- };
- double distance(Point A, Point B)
- {
- return sqrt(pow((A.x - B.x), 2) + pow((A.y - B.y), 2) + pow((A.z - B.z), 2));
- }
- double Perimetre(Point A, Point B, Point C)
- {
- return distance(A, B) + distance(B, C) + distance(A, C);
- }
- double Square(Point A, Point B, Point C)
- {
- return sqrt((Perimetre(A, B, C) / 2)*((Perimetre(A, B, C) / 2) - distance(A, B))*((Perimetre(A, B, C) / 2) - distance(B, C))*((Perimetre(A, B, C) / 2) - distance(A, C)));
- }
- int main()
- {
- setlocale(LC_ALL, "RUSSIAN");
- Point A{ 1, 5, 9 },
- B{ 2, 7, 4 },
- C{ 3, 1, 0 };
- cout << " " << endl;
- cout << "Периметр треугольника ABC: " << Perimetre(A, B, C) << endl;
- cout << "Площадь треугольника ABC: " << Square(A, B, C) << endl;
- return 0;
- }
- ###########################################
- Ф И Н А Л О Ч К А
- #include <iostream>
- #include <cmath>
- using std::cin;
- using std::cout;
- using std::endl;
- struct Point
- {
- double x;
- double y;
- double z;
- };
- double distance(Point A, Point B)
- {
- return sqrt(pow((A.x - B.x), 2) + pow((A.y - B.y), 2) + pow((A.z - B.z), 2));
- }
- double Perimetre(Point A, Point B, Point C)
- {
- return distance(A, B) + distance(B, C) + distance(A, C);
- }
- double Square(Point A, Point B, Point C)
- {
- return sqrt((Perimetre(A, B, C) / 2)*((Perimetre(A, B, C) / 2) - distance(A, B))*((Perimetre(A, B, C) / 2) - distance(B, C))*((Perimetre(A, B, C) / 2) - distance(A, C)));
- }
- void Input(Point&P)
- {
- cout << "x:";
- cin >> P.x;
- cout << "y:";
- cin >> P.y;
- cout << "z:";
- cin >> P.z;
- }
- void Display(Point P)
- {
- cout << "{" << P.x << ", " << P.y << ", " << P.z << "}";
- }
- int main()
- {
- setlocale(LC_ALL, "RUSSIAN");
- Point A, B, C;
- cout << "Введите точки:" << endl;
- Input(A);
- cout << " " << endl;
- Input(B);
- cout << " " << endl;
- Input(C);
- cout << " " << endl;
- cout << "Вы ввели точки:" << endl;
- Display(A);
- cout << " " << endl;
- Display(B);
- cout << " " << endl;
- Display(C);
- cout << " " << endl;
- cout << "Периметр треугольника ABC: " << Perimetre(A, B, C) << endl;
- cout << "Площадь треугольника ABC: " << Square(A, B, C) << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement