Again I come crawling for help...

I made a program that makes coordiant points and lines with these coordinates. A new class is going to inherit from the class with the lines, and calculate the distance between a line segment and a point. I found the correct mathematical formula. With that I first calculate the distance between two points to get the length of the line segment. And this is where the problem is:

#include <iostream>
#include <math.h>

using namespace std;

class Calculating: public Line
{
private:
	double distX;
	double distY;

public:
	Arvingen() {} 

	double distance()
	{
		distX = (x - x); // How do I make this x2-x1?
		distY = (y - y); // How do I make this y2-y1?
		dist2D = sqrt((distX*distX) + (distY*distY));

		return dist2D;
	}
}; // end class

The constructor in Line:

Line()
{
	srand(time(0));

	for(int i = 0;i <= 4;i ++)
	{
		x = rand() % 10 + 1;
		y = rand() % 10 + 1;

		linje2D[i].set2D(x, y);
		bpunkt[i].set2D(x, y);
	}
}

I've tried to get the distX and distY correct by using a for-loop and various other things like that, but all I get is a "expression must have pointer-to-object type".

Help....?

Seems to me your line class should contain the start and end points for a line. Then pass in a point to your "distance" method in Calculating. Seem like you might want a Point class too, perhaps...

I have a Point class. I just didn't post it since the Calculating is inheriting from Line and not Point. :)

But, ok. That sounds like a good idea. I didn't think past "making some points". I'll try editing the Line-class to make start and end points instead of random points.

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.