Plese help me on C++ Using CodeBlocks only Define the struct point with componen
ID: 645690 • Letter: P
Question
Plese help me on C++ Using CodeBlocks only
Define the struct point with components xCoordinate, yCoordinate of type double, which you have used in Lab#6.
Based on Lab#6, modify class polyLine to include the following public member functions:
? void set(int); sets numberOfPoints, creates the dynamic array based on the entered numberOfPoints and then asks the user for the coordinates of each point, sets length.
? void findLength(); computes total polyline length and assigns it to length
? void display() const; display the output messages as in the sample output
? point* getEndpoint(); returns a pointer to one of the endpoints specified by user.
? polyline(int = 0); constructor that invokes the set method
? polyline(
Explanation / Answer
#include
struct point
{
double xcor;
double ycor;
};
class polyLine
{
int n;
point *p;
public:
void set(int i);
void findLength();
void display()
point* getEndpoint();
polyLine(int = 0);
polyLine(polyline &p);
modifyPoint(int i, point &p);
};
void polyLine::set(int i)
{
n=i;
int c;
p=new point[i];
for(c=0;c {
cout<<"Enter the x coordinate for Point "< cin>>p[i].xcor;
cout<<"Enter the y coordinate for Point "< cin>>p[i].ycor;
}
}
void findLength()
{
int c;
double sum;
for(c=0;c {
sum=sum+(p[i+1].x-p[i])(p[i+1].y+p[i].y)/2;
}
}