Answer to Question #293312 in C++ for satu

Question #293312

Write a program which will do the following:

Create a class called

Triangle

. The three sides of the triangle

are private

members of the class. The

class should contain a member f

unction to determine whether a

triangle is equilateral, isosceles or

scalene.

The class

should

also

include member functions which will give area and perimeter of the

triangle. The side

s of the triangle should be taken as input from the user in the main function.



1
Expert's answer
2022-02-02T13:22:04-0500
#include<iostream>
#include<cmath>

using namespace std;

class Triangle
{
	float side1;
	float side2;
	float side3;
public:
	Triangle(){}

	void SidesAssign()
	{
		cout << "Please, enter the size of side1: ";
		cin >> side1;
		cout << "Please, enter the size of side2: ";
		cin >> side2;
		cout << "Please, enter the size of side3: ";
		cin >> side3;
	}
	void DetermineTrian()
	{
		if (side1 == side2&&side1 == side3)
			cout << "Triangle is equaliteral!";
		else if (side1 == side2 || side1 == side3 || side2 == side3)
			cout << "Triangle is isosceles!";
		else 
			cout << "Triangle is scalene!";
	}
	float PerimetrTrian()
	{
		return side1 + side2 + side3;
	}
	float AreaTrian()
	{
		float p = PerimetrTrian() / 2;
		return sqrt(p*(p-side1)*(p - side2)*(p - side3));
	}
};

int main()
{
	Triangle t;
	t.SidesAssign();
	t.DetermineTrian();
	cout<<"\nPerimetr of triangle is "<<t.PerimetrTrian();
	cout << "\nArea of triangle is " << t.AreaTrian();
}	

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