i see this code in this thread, i want to know how to get input by user or from file in this code. for example this list how to use it as input in this code. i don't know how to modify and how to use it.

Daniweb thread reference = http://www.daniweb.com/software-development/cpp/threads/282872

for example this list as input
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

#include <iostream>
#include <vector>
#include <math>

using namespace std;

struct point
  {
    int x;int y;
    point () {}
    point (int <strong class="highlight"><vb_highlight>a</strong></vb_highlight>,int b) : x(<strong class="highlight"><vb_highlight>a</strong></vb_highlight>) , y(b) {}


    friend float dist (point <strong class="highlight"><vb_highlight>a</strong></vb_highlight>,point b)
      {
        int p1; int p2;

        (<strong class="highlight"><vb_highlight>a</strong></vb_highlight>.x>b.x) ? p1=a.x-b.x : p1=b.x-a.x;
        (<strong class="highlight"><vb_highlight>a</strong></vb_highlight>.y>b.y) ? p2=a.y-b.y : p2=b.y-a.y;
        
        return sqrt((p1*p1) + (p2*p2));        
      }
   };

struct <strong class="highlight">triangle</strong> : public point
  {
    point <strong class="highlight"><vb_highlight>a</strong></vb_highlight>;point b;point c;
    <strong class="highlight">triangle</strong> (point a1,point b1,point c1) : <strong class="highlight"><vb_highlight>a</strong></vb_highlight>(a1) , b(b1) , c(c1){}

    float <strong class="highlight"><vb_highlight>area</strong></vb_highlight>()
      {        
        return (~( <strong class="highlight"><vb_highlight>a</strong></vb_highlight>.x*(b.y-c.y) + b.x*(c.y-a.y) + c.x*(<strong class="highlight"><vb_highlight>a</strong></vb_highlight>.y-b.y) ) /2) +1; 
      }

    float perim() {return dist(<strong class="highlight"><vb_highlight>a</strong></vb_highlight>,b)+dist(b,c)+dist(<strong class="highlight"><vb_highlight>a</strong></vb_highlight>,c);}
  };
      

int main ()
  {
    point <strong class="highlight"><vb_highlight>a</strong></vb_highlight>(31,21);
    point b(23,33);
    point c(54,34);
    <strong class="highlight">triangle</strong> d(<strong class="highlight"><vb_highlight>a</strong></vb_highlight>,b,c);
    cout << d.perim() << endl << d.area();
  }

thanks
waiting for replies

This is correct code

#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;
}

for example this list as input
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

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.