x025.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <cmath>
4 #include <iostream>
5 
6 namespace nmx::apps::x025 {
7 
12 inline void ex1() {
13  try {
14  double x = 0, y = 0;
15 
16  // Eingabe der ersten Kathete
17  std::cout << "x =?\t";
18  std::cin >> x;
19 
20  //prüfe erste Eingabe
21  if (std::cin.fail()) {
22  throw std::invalid_argument("x");
23  }
24  if (x <= 0) {
25  throw std::domain_error("x");
26  }
27 
28  // Eingabe der zweiten Kathete
29  std::cout << "y =?\t";
30  std::cin >> y;
31 
32  //prüfe zweite Eingabe
33  if (std::cin.fail()) {
34  throw std::invalid_argument("y");
35  }
36  if (x <= 0) {
37  throw std::domain_error("y");
38  }
39 
40  //Berechnung der Hypotenuse mit Funktion aus der std-Bibliothek
41  std::cout << "hypotenuse:" << std::hypot(x, y) << std::endl;
42  } catch (std::invalid_argument &invarg) {
43  //wenn die Eingabe keine Zahl ist
44  std::cout << "invalid argument for:" << invarg.what() << std::endl;
45  } catch (std::domain_error &domerr) {
46  //wenn die Eingabe <= 0 ist
47  std::cout << "input parameter must be >0:" << domerr.what() << std::endl;
48  }
49 }
50 
51 } // namespace nmx::apps::x025
void ex1()
ex1 Berechnung der Hypotenuse eines rechtwinkligen Dreiecks Version 2
Definition: x025.h:12