Class MyTriangle

Write a class called MyTriangle, which models a triangle with 3 vertices, is
designed as follows. It contains:
1. The MyTriangle class uses three MyPoint instances as the three vertices.
2. Three private instance variables v1, v2, v3 (instances of MyPoint), for
the three vertices.
3. A constructor that constructs a MyTriangle with three points v1=(x1,
y1), v2=(x2, y2), v3=(x3, y3).
4. An overloaded constructor that constructs a MyTriangle given three
instances of MyPoint.
5. A toString() function that returns a string description of the instance in the
format "Triangle @ (x1, y1), (x2, y2), (x3, y3)".
6. A getPerimeter() function that returns the length of the perimeter in
double. You should use the distance() method of MyPoint to compute
the perimeter.
7. Also write a test program (called main.cpp) to test all the functions defined
in the class (example of a triangle: (-2, 1), (1, 3) and (3, -3)).

where are my mistakes?
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
class MyTriangle
{
	MyPoint v1;
	MyPoint v2;
	MyPoint v3;

public:
	MyTriangle(int x1,int y1,int x2,int y2,int x3,int y3)
	{
       v1=(x1,y1);
       v2=(x2, y2);
       v3=(x3, y3);
    }
	MyTriangle(MyPoint v1,MyPoint v2,MyPoint v3){}
	string toString();
	double getPerimeter();
};


string MyTriangle::toString()
{
	cout<<"Triangle"<<"@"<<"("<<x1<<","<<y1<<")"<<","<<"("<<x2<<","<<y2<<")"<<","<<"("<<x3<<","<<y3<<")";
}

double MyTriangle::getPerimeter()
{
	return v1.distance(v1.getX(), v1.getY()) + v2.distance(v2.getX(), v2.getY()) + v3.distance(v3.getX(),v3.getY());
}
	
Lines 10, 11, 12: This isn't quite how one calls a constructor in C++. You're missing a type somewhere.

Line 14: You left this constructor blank. Why? >_>

Line 22: Did you mean to use v1, v2, and v3 here?

-Albatross
2. Three private instance variables v1, v2, v3 (instances of MyPoint), for
the three vertices.
3. A constructor that constructs a MyTriangle with three points v1=(x1,
y1), v2=(x2, y2), v3=(x3, y3).
4. An overloaded constructor that constructs a MyTriangle given three
instances of MyPoint.

I did to these conditions

What should I do?
MyTriangle(int x1,int y1,int x2,int y2,int x3,int y3)
{
v1=(x1,y1);
v2=(x2, y2);
v3=(x3, y3);
}
The stuff they provided in line 3 isn't valid C++ that can be just copied and pasted. They deliberately left something out for it to be valid.

Here's a fun fact. If you call a constructor as a function, it returns an instance of the object. So this:
Bunny speckles = Bunny("Speckles","Speckled");

...is valid.

-Albatross
Topic archived. No new replies allowed.