Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <windows.h>
- #include <string>
- #include <iostream>
- #include <iomanip>
- #include <math.h>
- #include <vector>
- #include <utility>
- #include <stdlib.h>
- #include <time.h>
- using namespace std;
- struct trng
- {
- int v1;
- int v2;
- int v3;
- double sq;
- };
- class SquareTrngl
- {
- public:
- SquareTrngl() {}
- pair<double,double> p;
- struct trng Vertx;
- vector < pair <double,double> > PointsTrngl;
- vector < struct trng > SqTrg;
- /////////////////////
- void InputData()
- {
- srand (time(NULL));
- cout << "Введите количество точек = "; cin >> Pts;
- if (!PointsTrngl.empty()) PointsTrngl.clear();
- int t= Pts; int x, y;
- while (t)
- {
- x= rand() % 100 - 50;
- p.first= (double) x; p.first/=10.0;
- y= rand() % 100 - 50;
- p.second= (double) y; p.second/=10.0;
- PointsTrngl.push_back(p);
- t--;
- }
- }
- ///////////////
- void OutCoord()
- {
- cout << setw(10) << "Х коорд" << setw(10) << "Y коорд" << endl;
- cout << setw(50) << setfill('=') << "=" << endl;
- cout << setfill(' ');
- int t= 0;
- while(t<PointsTrngl.size())
- {
- p= PointsTrngl[t];
- cout << setw(10) << setprecision(2) << p.first;
- cout << setw(10) << setprecision(2) << p.second;
- cout << endl;
- t++;
- }
- }
- //////////////
- void MakeTrg()
- {
- int v1, v2, v3;
- for (v1=0; v1<(Pts-1); v1++)
- {
- for (v2= v1+1; v2<Pts; v2++)
- {
- for (v3= v2+1; v3<Pts; v3++)
- {
- Vertx.v1= v1;
- Vertx.v2= v2;
- Vertx.v3= v3;
- Vertx.sq= 0.0;
- SqTrg.push_back(Vertx);
- }
- }
- }
- }
- void OutTrgSq()
- {
- cout << setw(10) << "Вершина 1";
- cout << setw(10) << "Вершина 2";
- cout << setw(10) << "Вершина 3";
- cout << setw(10) << "Площадь" << endl;
- cout << setw(50) << setfill('=') << "=" << endl;
- cout << setfill(' ');
- int t= 0;
- while(t<SqTrg.size())
- {
- Vertx= SqTrg[t];
- cout << setw(10) << Vertx.v1;
- cout << setw(10) << Vertx.v2;
- cout << setw(10) << Vertx.v3;
- cout << setw(10) << Vertx.sq;
- cout << endl;
- t++;
- }
- }
- /////////////////
- void SquareUnit()
- {
- double pp, ss; double x1,x2,x3,y1,y2,y3; double a,b,c;
- int t= 0;
- while (t<SqTrg.size())
- {
- Vertx= SqTrg[t];
- p= PointsTrngl[Vertx.v1];
- x1= p.first; y1= p.second;
- p= PointsTrngl[Vertx.v2];
- x2= p.first; y2= p.second;
- p= PointsTrngl[Vertx.v3];
- x3= p.first; y3= p.second;
- a= (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2); a= sqrt(a);
- b= (x3-x2)*(x3-x2) + (y3-y2)*(y3-y2); b= sqrt(b);
- c= (x1-x3)*(x1-x3) + (y1-y3)*(y1-y3); c= sqrt(c);
- pp= (a+b+c)/2.0;
- ss= sqrt( pp*(pp-a)*(pp-b)*(pp-c) );
- Vertx.sq= ss;
- SqTrg[t]= Vertx;
- t++;
- }
- }
- ///////////////////////
- void IsTrngl()
- {
- int t= 0; double minS;
- //Находим первый невырожденный треугольник с ненулевой площадью
- while(t<SqTrg.size())
- {
- Vertx= SqTrg[t];
- if (Vertx.sq!=0) { minS= Vertx.sq; break; }
- t++;
- }
- // Сортируем по минимальной площади
- while(t<SqTrg.size())
- {
- Vertx= SqTrg[t];
- if (Vertx.sq < minS && Vertx.sq!=0) { minS= Vertx.sq; mnSq= t; }
- t++;
- }
- cout << endl << "Треугольник с минимальной площадью имеет парметры" << endl;
- Vertx= SqTrg[mnSq];
- p= PointsTrngl[Vertx.v1];
- cout << setw(10) << "Вершина 1";
- cout << setw(10) << "X1= " << setw(10) << p.first << setw(10) << "Y1= " << p.second << endl;
- p= PointsTrngl[Vertx.v2];
- cout << setw(10) << "Вершина 2";
- cout << setw(10) << "X2= " << setw(10) << p.first << setw(10) << "Y2= " << p.second << endl;
- p= PointsTrngl[Vertx.v3];
- cout << setw(10) << "Вершина 3";
- cout << setw(10) << "X3= " << setw(10) << p.first << setw(10) << "Y3= " << p.second << endl;
- cout << setw(10) << "Площадь= " << setw(10) << Vertx.sq << endl;
- cout << setw(50) << setfill('=') << "=" << endl;
- cout << setfill(' ');
- }
- ///////////////////////
- ~SquareTrngl() {}
- protected:
- int Pts;
- double xPt;
- double yPt;
- int mnSq;
- private:
- };
- int main(int argc, char **argv)
- {
- system("chcp 1251 > nul"); // Руссификация сообщений
- setlocale(LC_ALL, "Russian");
- SquareTrngl st; st.InputData(); st.OutCoord();
- st.MakeTrg(); st.SquareUnit(); st.OutTrgSq();
- st.IsTrngl();
- cout << endl << endl;
- system("pause"); // system("pause > nul");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment