Issue with line class

Hi, I have a problem with my line class, in that I am stuck trying to get the code to work. My logic is wrong I'm sure of it. But not sure how to fix it. I need to match it with main below. Can anyone tell me where I've gone wrong and show me the correct way to fix it in my codes? Thank you.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
  class Polygon : public Shape 
	{ 
	public:
		int getArea() { 
			return (width * height); 
		}
	};

	class Line : public Polygon 
	{ 
	public:
	Point() { };                           //Default Constructor
		Point(int px, int py) {                //Constructor
			x = px;
			y = py;
		}
	void draw();
		
	};
void Line::draw() {
    cout << "Line" << "drawing" << endl;
}
int main() 
{
	Line l1; 				//Output: Line construction
	std::cout << l1; 		//Output: Line (0,0) (0,0)
	l1.Draw(); 				//Output: Line drawing
	
	Line l2(Point(), 
	Point(100,100));	//Output: Line construction
	std::cout << l2; 		//Output: Line (0,0) (100,100)
	l1 = l2;
	std::cout << l1; 		//Output: Line (0,0) (100,100)

}
Last edited on
I would suggest you start with just 'Point' and 'Line', before adding the complications of 'Shape' and 'Polygon'.

1
2
3
4
5
6
7
8
class Point {
  // vars and methods
};

class Line {
   Point start, end;
   // more vars and methods
};
Hi Salem, as this is a school assignment, I can't modify or change what's been given to me.
And what have you been 'given', and what have you changed to get into the state you're in?

> as this is a school assignment, I can't modify or change what's been given to me.
There is nothing stopping you creating a parallel file containing whatever code you like that helps you understand the problem.

Topic archived. No new replies allowed.