Answer to Question #320141 in C++ for khan

Question #320141


create two classes, first class ‘Point’ with two data

members x and y. Provide appropriate constructors, get, set or display methods.

Create the second class ‘Triangle’ with three points as its data members. Provide

appropriate constructors for this class and a display method which calls the display methods of points.

In the main function, declare three points and pass them to the constructor of an instance of the triangle class and pass direct values to the second instance of the triangle class without creating points instances. Call the display method of triangle to verify the coordinates of the triangle.

prototypes

Point():

void insertPoint(int, int):

void displayPoint(int):4. Triangle():

Triangle(Point, Point, Point):

Triangle(int, int, int, int, int, int):

void insertData():

void displayData():

NOTE: Define functions outside of the class using scope resolution operator except

constructors and destructors.


1
Expert's answer
2022-04-01T04:50:00-0400
#include <iostream>
using namespace std;

class Point
{
private:
	int x;
	int y;

public:
	Point() {};

	Point(int _x, int _y)
	{
		x = _x;
		y = _y;
	}

	int getX();
	int getY();
	void display();

	~Point() {};
};

class Triangle
{
public:

	Point A(), B(), C();

	Triangle(Point a1, Point b1, Point c1)

	{
		a1.display();
		b1.display();
		c1.display();
	}

	~Triangle() {};
};

int Point::getX() { return x; }
int Point::getY() { return y; }

void Point::display() 
{
	cout << "\nValue of X: " << x;
	cout << "\nValue of Y: " << y << "\n";
}

int main()
{
	Point A(1, 2), B(2, 4), C(3, 6);

	Triangle t(A, B, C);

	return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog