Advertisement
VictoriaLodochkina

lab 5 (2s) all

Mar 24th, 2020
307
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.38 KB | None | 0 0
  1. #include <iostream>
  2. #define _USE_MATH_DEFINES
  3. #include <math.h>
  4. #include <string>
  5. #include <vector>
  6. #include <algorithm>
  7. using namespace std;
  8. struct Point
  9. {
  10.     double x;
  11.     double y;
  12. };
  13. double leng(Point a, Point b);
  14. struct Triangle
  15. {
  16.     Point a;
  17.     Point b;
  18.     Point c;
  19. };
  20. struct Highs
  21. {
  22.     double hi1;
  23.     double hi2;
  24.     double hi3;
  25. };
  26.  
  27.  
  28. struct Information
  29. {
  30.     string Name;
  31.     string Date;
  32.     string Problem;
  33.     string Status;
  34. };
  35. double perim(Triangle t);
  36. double area(Triangle t);
  37. double dist(Point p, Point a, Point b);
  38. //void altitudes(Triangle t);
  39. Highs altitudes(Triangle t);
  40. int main()
  41. {
  42.     setlocale(LC_ALL, "Russian");
  43.     long n;
  44.     char ex = 'n';
  45.     do {
  46.         cout << "Введите номер задания: " << endl;
  47.         char task;
  48.         /*cin.ignore(100, '\n');*/
  49.         cin >> task;
  50.         switch (task)
  51.         {
  52.         case '1': {
  53.             Point A, B, C, D;
  54.             cout << "Enter Ax, Ay, Bx, By, Cx, Cy, Dx, Dy: " << endl;
  55.             cin >> A.x >> A.y >> B.x >> B.y >> C.x >> C.y >> D.x >> D.y;
  56.             Triangle ABC = { A, B, C };
  57.             Triangle ABD = { A, B, D };
  58.             Triangle ACD = { A, C, D };
  59.             Highs resH;
  60.             resH=altitudes(ABC);
  61.             cout << "Your result: " << endl << "h1 = " << resH.hi1 << endl << "h2 = " << resH.hi2 << endl << "h3 = " << resH.hi3 << endl;
  62.             resH=altitudes(ABD);
  63.             cout << "Your result: " << endl << "h1 = " << resH.hi1 << endl << "h2 = " << resH.hi2 << endl << "h3 = " << resH.hi3 << endl;
  64.             resH=altitudes(ACD);
  65.             cout << "Your result: " << endl << "h1 = " << resH.hi1 << endl << "h2 = " << resH.hi2 << endl << "h3 = " << resH.hi3 << endl;
  66.             break;
  67.         }
  68.         case '2': {
  69.             int n;
  70.             cout << "Enter n: " << endl;
  71.             cin >> n;
  72.             vector<Information> info(n);
  73.             cin.ignore(100, '\n');
  74.             cin.clear();
  75.             for (int i = 0; i < n; i++)
  76.             {
  77.                 cout << "Fill list " << i + 1 << ":" << endl << "Name: " << endl;
  78.                 getline(cin, info.at(i).Name);
  79.                 cout << "Date: " << endl;
  80.                 getline(cin, info.at(i).Date);
  81.                 cout << "Problem: " << endl;
  82.                 getline(cin, info.at(i).Problem);
  83.                 cout << "Status: " << endl;
  84.                 getline(cin, info.at(i).Status);
  85.             }
  86.             for (int i = 0; i < info.size(); i++)
  87.             {
  88.                 if (info.at(i).Status == "processed")
  89.                 {
  90.                     info.erase(info.begin() + i);
  91.                 }
  92.             }
  93.             cout << "*******************************************************************" << endl;
  94.             cout << "Results: " << endl;
  95.             for (int i = 0; i < info.size(); i++)
  96.             {
  97.                 cout << "List " << i + 1 << ":" << endl << info.at(i).Name << endl << info.at(i).Date << endl << info.at(i).Problem << endl << info.at(i).Status << endl;
  98.                 cout << "             ***" << endl;
  99.             }
  100.             break;
  101.         }
  102.         default: {cout << "Нет такой задачи.\n"; } break;
  103.         }
  104.         cout << "Если вы хотите выйти, нажмите \'y\', в противном случае-любую другую клавишу" << endl;
  105.         cin.ignore(100, '\n');
  106.         cin >> ex;
  107.     } while (ex != 'y');
  108.     return 0;
  109. }
  110.  
  111. double leng(Point a, Point b)
  112. {
  113.     double len = sqrt(pow((b.x - a.x), 2) + pow((b.y - a.y), 2));//
  114.     return len;
  115. }
  116.  
  117. double perim(Triangle t)
  118. {
  119.     double p = leng(t.a, t.b) + leng(t.b, t.c) + leng(t.c, t.a);
  120.     return p;
  121. }
  122.  
  123. double area(Triangle t)
  124. {
  125.     double p2 = perim(t) / 2;
  126.     double s = sqrt((p2) * (p2 - leng(t.a, t.b)) * (p2 - leng(t.b, t.c)) * (p2 - leng(t.c, t.a)));
  127.     return s;
  128. }
  129.  
  130. double dist(Point p, Point a, Point b)
  131. {
  132.     Triangle tt = { p, a, b };
  133.     double dst = 2 * (area(tt) / leng(a, b));///////////////
  134.     return dst;
  135. }
  136.  
  137. Highs altitudes(Triangle t)
  138. {
  139.     Highs myH;
  140.     double ha, hb, hc;
  141.     ha = dist(t.a, t.b, t.c);
  142.     hb = dist(t.b, t.a, t.c);
  143.     hc = dist(t.c, t.a, t.b);
  144.     myH.hi1 = ha;
  145.     myH.hi2 = hb;
  146.     myH.hi3 = hc;
  147.     //cout << "Your result: " << endl << "h1 = " << ha << endl << "h2 = " << hb << endl << "h3 = " << hc << endl;
  148.     return myH;
  149. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement