Answer to Question #174667 in C++ for zain ul abdeen

Question #174667

Create a class named as RightAngleTriangle. In a right Angle Triangle, there are 3 points, which are 2-D points. There will be 3 members(vertices) i.e. Point2DA, Point2DB, Point2DC. Create the following function:-

1)Input Function.

2)Area Function. (In this function area will be calculated and returned).

3)IsRightAngleTriangle (This will return Boolean i.e. if it is a right angle triangle it will return True else it will return False)

4)Output Function.

5) Base Function. (It will return the length of Base).

6) Perpendicular Function. ( It will return the length of Perpendicular).

7)Hypotenuse Function. (It will return the length of Hypotenuse).

8)Alpha Function. ( It will return the angle between Base and Hypotenuse).

9)Beta Function. ( It will return the angle between Hypotenuse and Perpendicular).


1
Expert's answer
2021-03-24T01:02:47-0400
#include <iostream>
#include <vector>
#include <stdlib.h>
#include <cmath>
using namespace std;


class RightAngleTriangle{
private:
    vector<int> Point2DA, Point2DB, Point2DC;
	float AC,AB,BC;
public:
	RightAngleTriangle(){}
	
    //1)Input Function.
	void Input(){
		int X;
		int Y;
		cout<<"Enter X coordinate for point A: ";
		cin>>X;
		cout<<"Enter Y coordinate for point A: ";
		cin>>Y;
		Point2DA.push_back(X);
		Point2DA.push_back(Y);


		cout<<"Enter X coordinate for point B: ";
		cin>>X;
		cout<<"Enter Y coordinate for point B: ";
		cin>>Y;
		Point2DB.push_back(X);
		Point2DB.push_back(Y);


		cout<<"Enter X coordinate for point C: ";
		cin>>X;
		cout<<"Enter Y coordinate for point C: ";
		cin>>Y;
	
		Point2DC.push_back(X);
		Point2DC.push_back(Y);


		AC=(pow((float)(Point2DA[0]-Point2DC[0]),2)+pow((float)(Point2DA[1]-Point2DC[1]),2));
		AB=(pow((float)(Point2DA[0]-Point2DB[0]),2)+pow((float)(Point2DA[1]-Point2DB[1]),2));
		BC=(pow((float)(Point2DB[0]-Point2DC[0]),2)+pow((float)(Point2DB[1]-Point2DC[1]),2));
	}
	//2)Area Function. (In this function area will be calculated and returned).
	float Area(){
        return abs((Point2DA[0]*(Point2DB[1]-Point2DC[1])+Point2DB[0]*(Point2DC[1]-Point2DA[1])+Point2DC[0]*(Point2DA[1]-Point2DB[1]))/2.0);
    }
	//3)IsRightAngleTriangle (This will return Boolean i.e. if it is a right angle triangle it will return True else it will return False)
	bool IsRightAngleTriangle(){
		return (((AC == (AB + BC)) || (AB == (AC + BC) ) || (BC == (AC + AB))));
	}
	//4)Output Function.
	void Output(){
		cout << "The area of triangle: " << Area() << "\n";
		if(IsRightAngleTriangle()){
			cout << "It is a right angle triangle\n";
			
			cout << "The length of Base: " << Base() << "\n";
			cout << "The length of Perpendicular: " << Perpendicular() << "\n";
			cout << "The length of Hypotenuse: " << Hypotenuse() << "\n";
			cout << "The angle between Base and Hypotenuse: " << Alpha() << "\n";
			cout << "The angle between Hypotenuse and Perpendicular: " << Beta() << "\n";
		}else{
			cout << "It is not a right angle triangle\n";
		}
	
	}
	//5) Base Function. (It will return the length of Base).
	float Base(){
		if(AC == (AB + BC)){
			return sqrt(AB);	
		}
		if(AB == (AC + BC)){
			return sqrt(AC);	
		}
        return sqrt(AC);
    }
	//6) Perpendicular Function. ( It will return the length of Perpendicular).
	float Perpendicular(){
		if(AC == (AB + BC)){
			return sqrt(BC);	
		}
		if(AB == (AC + BC)){
			return sqrt(BC);	
		}
        return sqrt(AB);	
    }
	//7)Hypotenuse Function. (It will return the length of Hypotenuse).
	float Hypotenuse(){
        return sqrt((Base()*Base() + Perpendicular()*Perpendicular()));	
    }
	//8)Alpha Function. ( It will return the angle between Base and Hypotenuse).
	float Alpha(){
        return (acos(Base()/Hypotenuse())* 180.0) / 3.14;
    }
	//9)Beta Function. ( It will return the angle between Hypotenuse and Perpendicular).
	float Beta(){
        return 90-Alpha();
    }
};


int main (){
	RightAngleTriangle rightAngleTriangle;
	rightAngleTriangle.Input();
	rightAngleTriangle.Output();
	system("pause");
	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
APPROVED BY CLIENTS