# Функция

Oct 18th, 2019
56
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. #include <iostream>
2. #include <cmath>
3. #include <string>
4. using namespace std;
5. double circle (int r) {
6.     const double  p = 3.1415926535897932384626433832795;
7.     double s;
8.     s = p * r * r;
9.     return s;
10. }
11. double rectangle (int a, int b) {
12.     int s;
13.     s = a * b;
14.     return s;
15. }
16. double triangle (int x, int y, int z) {
17.     double s, h;
18.     h = (x + y + z) / 2;
19.     s = sqrt(h * (h - x) * (h - y) * (h - z));
20.     return s;
21. }
22. int main () {
23.     cout << "What is your figure? ";
24.     string g;
25.     double a, b, r, x, y, z, k;
26.     cin >> g;
27.
28.     if(g == "Circle" || g == "circle" || g == "rectangle" || g == "Rectangle" || g == "triangle" || g == "Triangel") {
29.     cout << "Enter your data ";
30.     if (g == "Circle" || g == "circle") {
31.
32.         cin >> r;
33.         k = circle(r);
34.     }
35.     else if (g == "Rectangle" || g == "rectangle") {
36.         cin >> a >> b;
37.         k = rectangle(a, b);
38.
39.     }
40.
41.
42.     else {
43.         cin >> x >> y >> z;
44.         k = triangle(x, y, z);
45.     }
46.     cout << k;
47.     } else {
48.         cout << "WRONG";
49.     }
50.
51.     return 0;
52. }
RAW Paste Data