Программа C++ для нахождения третьего угла треугольника

Чтобы найти третий угол треугольника в C++, можно использовать различные методы. Вот несколько возможных подходов:

Метод 1: использование свойства углов треугольника
В любом треугольнике сумма всех внутренних углов всегда равна 180 градусов. Итак, если вы знаете размеры двух углов треугольника, вы можете найти третий угол, вычитая сумму двух известных углов из 180.

#include <iostream>
int main() {
  double angle1, angle2;
  std::cout << "Enter the measure of the first angle: ";
  std::cin >> angle1;
  std::cout << "Enter the measure of the second angle: ";
  std::cin >> angle2;

  double angle3 = 180 - angle1 - angle2;
  std::cout << "The measure of the third angle is: " << angle3 << std::endl;

  return 0;
}

Метод 2. Использование функции.
Вы можете создать функцию, которая принимает на вход значения двух углов и возвращает значение третьего угла.

#include <iostream>
double calculateThirdAngle(double angle1, double angle2) {
  return 180 - angle1 - angle2;
}
int main() {
  double angle1, angle2;
  std::cout << "Enter the measure of the first angle: ";
  std::cin >> angle1;
  std::cout << "Enter the measure of the second angle: ";
  std::cin >> angle2;

  double angle3 = calculateThirdAngle(angle1, angle2);
  std::cout << "The measure of the third angle is: " << angle3 << std::endl;

  return 0;
}

Метод 3. Использование класса
Вы можете создать класс, представляющий треугольник и включающий метод расчета третьего угла на основе измерений двух других углов.

#include <iostream>
class Triangle {
public:
  double angle1, angle2;

  double calculateThirdAngle() {
    return 180 - angle1 - angle2;
  }
};
int main() {
  Triangle triangle;
  std::cout << "Enter the measure of the first angle: ";
  std::cin >> triangle.angle1;
  std::cout << "Enter the measure of the second angle: ";
  std::cin >> triangle.angle2;

  double angle3 = triangle.calculateThirdAngle();
  std::cout << "The measure of the third angle is: " << angle3 << std::endl;

  return 0;
}