anyone can write this c++ code.

Status
Not open for further replies.

iamuser_2007

New Member
2
2011
0
0
Given set of points in the plane

1. The minimum distance between two points.
2. The maximum distance between two points.
3. The largest area of a triangle which has vertices at given points.
4. The area of a convex hull of the set of points.

The values should be computed as a number with 5 digits after the decimal point.


96 48
91 94
77 31
3 2
68 17
33 9
52 23
99 78
25 63
18 89
98 54
82 64
31 98
99 71
97 36
32 49
8 65
63 61
93 79
48 93
8 45
59 54
92 94
47 0
40 65
25 16
24 92
79 35
73 13
41 89
0 86
21 14
74 96
82 15
0 29
20 76
49 36
66 24
84 57
4 38
66 41
53 47
49 20
92 91
86 78
63 64
20 71
24 81
85 39
63 48


Thnx for help
 
3 comments
i have this code. i am learning cpp.
i am beginner and trying to learn programming


#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

struct point
{
int x;int y;
point () {}
point (int a,int b) : x(a) , y(b) {}


friend float dist (point a,point b)
{
int p1; int p2;

(a.x>b.x) ? p1=a.x-b.x : p1=b.x-a.x;
(a.y>b.y) ? p2=a.y-b.y : p2=b.y-a.y;

return sqrt((p1*p1) + (p2*p2));
}
};

struct triangle : public point
{
point a;point b;point c;
triangle (point a1,point b1,point c1) : a(a1) , b(b1) , c(c1){}

float area()
{
return (~( a.x*(b.y-c.y) + b.x*(c.y-a.y) + c.x*(a.y-b.y) ) /2) +1;
}

float perim() {return dist(a,b)+dist(b,c)+dist(a,c);}
};


int main()
{
point a(96,48);
point b(91,94);
point c(77,31);
triangle d(a,b,c);
cout << d.perim() << endl << d.area();
system("pause");
return 0;
}


how to modify this code and how to enter those above list numbers.
 
I think that's a difficult problem.

With a "naive" algorithm you have:
distances: if you have n points you have to check n² distances/pairs.
area of triangles: if you have n points you have to check n³ triangles.

Is a naive algorithm ok? Because anything else:
- beyond my capability
- I don't have the time.
 
Status
Not open for further replies.
Back
Top