Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <random>
- #include <chrono>
- using namespace std;
- struct point
- {
- double x,y;
- };
- struct triangle
- {
- point a,b,c;
- };
- point get_point(std::default_random_engine &engine)
- {
- std::uniform_real_distribution<double> distro (0,10);
- point p;
- p.x = distro(engine);
- p.y = distro(engine);
- return p;
- }
- void print(const point &p)
- {
- cout << p.x <<" "<< p.y;
- }
- void fill(point arr[],const int SIZE,std::default_random_engine &engine)
- {
- for (int i = 0 ; i < SIZE;i++)
- {
- arr[i] = get_point(engine);
- }
- for (int i = 0 ; i < SIZE;i++)
- {
- cout << arr[i].x <<" "<< arr[i].y << endl;
- }
- }
- double side(const point &c,const point &d)
- {
- return sqrt( (c.x - d.x)*(c.x - d.x) + (c.y - d.y)*(c.y - d.y) );
- }
- triangle find_the_largest(point arr[],const int SIZE)
- {
- triangle t;
- double p_, pole;
- double ab, bc, ca;
- double pole_max = 0;
- for (int i = 0; i<SIZE ;i++)
- {
- for (int j = 0; j<SIZE ;j++)
- {
- for (int k = 0; k<SIZE ;k++)
- {
- t.a = arr[i];
- t.b = arr[j];
- t.c = arr[k];
- ab = side(t.a,t.b);
- bc = side(t.b,t.c);
- ca = side(t.c,t.a);
- p_ = (ab+bc+ca)/2;
- pole = sqrt(p_ *(p_-ab)*(p_-bc)*(p_-ca));
- if ( pole > pole_max )
- {
- pole_max = pole;
- }
- }
- }
- }
- cout << pole_max;
- }
- int main()
- {
- const int SIZE = 3;
- point arr[SIZE];
- std::default_random_engine engine;
- engine.seed(std::chrono::system_clock::now().time_since_epoch().count());
- point p = get_point(engine);
- //1
- fill(arr,SIZE,engine); //2
- find_the_largest(arr,SIZE); //3
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement