Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #define _USE_MATH_DEFINES
- #include <math.h>
- #include <string>
- #include <vector>
- #include <algorithm>
- using namespace std;
- struct Point
- {
- double x;
- double y;
- };
- double leng(Point a, Point b);
- struct Triangle
- {
- Point a;
- Point b;
- Point c;
- };
- struct Highs
- {
- double hi1;
- double hi2;
- double hi3;
- };
- struct Information
- {
- string Name;
- string Date;
- string Problem;
- string Status;
- };
- double perim(Triangle t);
- double area(Triangle t);
- double dist(Point p, Point a, Point b);
- //void altitudes(Triangle t);
- Highs altitudes(Triangle t);
- int main()
- {
- setlocale(LC_ALL, "Russian");
- long n;
- char ex = 'n';
- do {
- cout << "Введите номер задания: " << endl;
- char task;
- /*cin.ignore(100, '\n');*/
- cin >> task;
- switch (task)
- {
- case '1': {
- Point A, B, C, D;
- cout << "Enter Ax, Ay, Bx, By, Cx, Cy, Dx, Dy: " << endl;
- cin >> A.x >> A.y >> B.x >> B.y >> C.x >> C.y >> D.x >> D.y;
- Triangle ABC = { A, B, C };
- Triangle ABD = { A, B, D };
- Triangle ACD = { A, C, D };
- Highs resH;
- resH=altitudes(ABC);
- cout << "Your result: " << endl << "h1 = " << resH.hi1 << endl << "h2 = " << resH.hi2 << endl << "h3 = " << resH.hi3 << endl;
- resH=altitudes(ABD);
- cout << "Your result: " << endl << "h1 = " << resH.hi1 << endl << "h2 = " << resH.hi2 << endl << "h3 = " << resH.hi3 << endl;
- resH=altitudes(ACD);
- cout << "Your result: " << endl << "h1 = " << resH.hi1 << endl << "h2 = " << resH.hi2 << endl << "h3 = " << resH.hi3 << endl;
- break;
- }
- case '2': {
- int n;
- cout << "Enter n: " << endl;
- cin >> n;
- vector<Information> info(n);
- cin.ignore(100, '\n');
- cin.clear();
- for (int i = 0; i < n; i++)
- {
- cout << "Fill list " << i + 1 << ":" << endl << "Name: " << endl;
- getline(cin, info.at(i).Name);
- cout << "Date: " << endl;
- getline(cin, info.at(i).Date);
- cout << "Problem: " << endl;
- getline(cin, info.at(i).Problem);
- cout << "Status: " << endl;
- getline(cin, info.at(i).Status);
- }
- for (int i = 0; i < info.size(); i++)
- {
- if (info.at(i).Status == "processed")
- {
- info.erase(info.begin() + i);
- }
- }
- cout << "*******************************************************************" << endl;
- cout << "Results: " << endl;
- for (int i = 0; i < info.size(); i++)
- {
- 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;
- cout << " ***" << endl;
- }
- break;
- }
- default: {cout << "Нет такой задачи.\n"; } break;
- }
- cout << "Если вы хотите выйти, нажмите \'y\', в противном случае-любую другую клавишу" << endl;
- cin.ignore(100, '\n');
- cin >> ex;
- } while (ex != 'y');
- return 0;
- }
- double leng(Point a, Point b)
- {
- double len = sqrt(pow((b.x - a.x), 2) + pow((b.y - a.y), 2));//
- return len;
- }
- double perim(Triangle t)
- {
- double p = leng(t.a, t.b) + leng(t.b, t.c) + leng(t.c, t.a);
- return p;
- }
- double area(Triangle t)
- {
- double p2 = perim(t) / 2;
- double s = sqrt((p2) * (p2 - leng(t.a, t.b)) * (p2 - leng(t.b, t.c)) * (p2 - leng(t.c, t.a)));
- return s;
- }
- double dist(Point p, Point a, Point b)
- {
- Triangle tt = { p, a, b };
- double dst = 2 * (area(tt) / leng(a, b));///////////////
- return dst;
- }
- Highs altitudes(Triangle t)
- {
- Highs myH;
- double ha, hb, hc;
- ha = dist(t.a, t.b, t.c);
- hb = dist(t.b, t.a, t.c);
- hc = dist(t.c, t.a, t.b);
- myH.hi1 = ha;
- myH.hi2 = hb;
- myH.hi3 = hc;
- //cout << "Your result: " << endl << "h1 = " << ha << endl << "h2 = " << hb << endl << "h3 = " << hc << endl;
- return myH;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement