Hello!
Can someone please give me some advice where to begin this program from and how. Thanks in advance.

Given set of points in the plane, you have to write a program in C++ that computes the following values:

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.

Distance (Pythagoras' Theorem):
c = sqrt (a^2 + b^ 2)

Area of triangle:
( base * height )/2

Those are a couple of the equations you'll need. The rest is just like any other program. Input, Process, Output.

int main() { return 0; }
#include <iostream>
#include <vector>
#include <math>

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(31,21);
    point b(23,33);
    point c(54,34);
    triangle d(a,b,c);
    cout << d.perim() << endl << d.area();
  }
commented: Don't just hand out code. Make suggestions and give guidance. Otherwise the person with the question doesn't learn. +0
commented: 5 star +0

To fbody.I think you can learn a lot better from just reading code.He's not here for a test .. he's looking for help. If he'll just take the code the way it is it's his problem but many of us learned that way .. reading code.

commented: It's explicitely stated that we do not do homework for others, which you did. +0
commented: Congrats on helping another homework kiddo cheat his class! Good job man! -2

To fbody.I think you can learn a lot better from just reading code.He's not here for a test .. he's looking for help. If he'll just take the code the way it is it's his problem but many of us learned that way .. reading code.

Reading example code is a good way to learn. Problem is, the code you posted is not example code, it was a solution that was copy/paste-ready. Odds are, it won't be read, just copy/pasted. What gets learned then??? Nothing...

commented: Yes +12

This is just an example.What is your problem anyway?Do you really think reminding him of those formulas helped?Try putting some muscle into helping others man and .. you're not too involved it seems ;)

This is just an example.What is your problem anyway?Do you really think reminding him of those formulas helped?Try putting some muscle into helping others man and .. you're not too involved it seems ;)

Fbody is right and he actually gave a very descent and useful reply. Unlike your own reply which is just some free code with no explanation what-so-ever. The OP can very well copy-paste this into his homework-assignment and pass his class by cheating. This will ultimately result in yet another incapable C++ programmer in the field.

commented: Thank you. :) +1

So this means that from now on i can't post full code ... ???That really cuts off the enthusiasm.

We are forced to learn C++ I am not becoming a programmer. I solve most of the tasks myself, however this is far more tricky as seen from the code our colleague posted. Furthermore, I am not copy pasting right away senselessly. And also this is not the whole solution but only for the triangle. This doesn't mean I am not grateful, of course. Thanks everybody so far.

Do you need more guidance ?

First I'll try by myself, thanks. :)

Well you all have a point guys, we all wanna help each other and it's up to them if they'll just "copy-paste"..- It's not us they're fooling around but theirselves. Right?!

Well you all have a point guys, we all wanna help each other and it's up to them if they'll just "copy-paste"..- It's not us they're fooling around but theirselves. Right?!

They'd also be fooling their instructor. We help by not short-cutting their learning process, which involves them doing their homework themselves and asking for help only where they need it.

After two years, the OP has probably handed in a solution for this already.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.