Answer to Question #184069 in C++ for Bilal

Question #184069

Comment this code line by line in simple english

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";
 
        }
 
 
    }
 
 
    float Base(){
 
        if(AC == (AB + BC)){
 
            return sqrt(AB);
 
        }
 
        if(AB == (AC + BC)){
 
            return sqrt(AC);
 
        }
 
        return sqrt(AC);
 
    }
 
 
    float Perpendicular(){
 
        if(AC == (AB + BC)){
 
            return sqrt(BC);
 
        }
 
        if(AB == (AC + BC)){
 
            return sqrt(BC);
 
        }
 
        return sqrt(AB);
 
    }
 
 
    float Hypotenuse(){
 
        return sqrt((Base()*Base() + Perpendicular()*Perpendicular()));
 
    }
 
 
    float Alpha(){
 
        return (acos(Base()/Hypotenuse())* 180.0) / 3.14;
 
    }
1
Expert's answer
2021-04-24T06:10:43-0400

The given code was not correct. Below is the corrected code along with comments for each line:

using namespace std;


float AB,AC,BC,a,b,c;


float Base()
{
	int Flag=0;	//Declare a Flag to give 1 if the sides are of a right angle triangle else 0
    if(c*c == (a*a+b*b))	//Check if Pythagorous theorm appliues to sides to one combination of a, b and c
	{
		AC = c;				// Confirm for Hypotenous
		AB = a;				// Confirm for Base	
		BC = b;				// Confirm for Perpendicular	
		Flag=1;				// Right Angle triangle confirm flag
    }
    if(b*b == (a*a+c*c))	//Check if Pythagorous theorm appliues to sides to one combination of a, b and c
	{
		AC = b;				// Confirm for Hypotenous
		AB = a;				// Confirm for Base
		BC = c;				// Confirm for Perpendicular
		Flag=1;				// Right Angle triangle confirm flag
    }
    if(a*a == (c*c+b*b))	//Check if Pythagorous theorm appliues to sides to one combination of a, b and c
	{
		AC = a;				// Confirm for Hypotenous
		AB = c;				// Confirm for Base
		BC = b;				// Confirm for Perpendicular
		Flag=1;				// Right Angle triangle confirm flag
    }
    if(Flag) 	return sqrt(AB*AB);	//Return Base
    else 		return(Flag);		//Else Return Flag as 0	
}
 
 
float Perpendicular()
{
	int Flag=0;	//Declare a Flag to give 1 if the sides are of a right angle triangle else 0
    if(c*c == (a*a+b*b))	//Check if Pythagorous theorm appliues to sides to one combination of a, b and c
	{
		AC = c;				// Confirm for Hypotenous
		AB = a;				// Confirm for Base	
		BC = b;				// Confirm for Perpendicular	
		Flag=1;				// Right Angle triangle confirm flag
    }
    if(b*b == (a*a+c*c))	//Check if Pythagorous theorm appliues to sides to one combination of a, b and c
	{
		AC = b;				// Confirm for Hypotenous
		AB = a;				// Confirm for Base
		BC = c;				// Confirm for Perpendicular
		Flag=1;				// Right Angle triangle confirm flag
    }
    if(a*a == (c*c+b*b))	//Check if Pythagorous theorm appliues to sides to one combination of a, b and c
	{
		AC = a;				// Confirm for Hypotenous
		AB = c;				// Confirm for Base
		BC = b;				// Confirm for Perpendicular
		Flag=1;				// Right Angle triangle confirm flag
    }
    if(Flag) 	return sqrt(BC*BC);	//Return Perpendicular
    else 		return(Flag);		//Else Return Flag as 0	
}
 
float Hypotenuse()
{
	int Flag=0;	//Declare a Flag to give 1 if the sides are of a right angle triangle else 0
    if(c*c == (a*a+b*b))	//Check if Pythagorous theorm appliues to sides to one combination of a, b and c
	{
		AC = c;				// Confirm for Hypotenous
		AB = a;				// Confirm for Base	
		BC = b;				// Confirm for Perpendicular	
		Flag=1;				// Right Angle triangle confirm flag
    }
    if(b*b == (a*a+c*c))	//Check if Pythagorous theorm appliues to sides to one combination of a, b and c
	{
		AC = b;				// Confirm for Hypotenous
		AB = a;				// Confirm for Base
		BC = c;				// Confirm for Perpendicular
		Flag=1;				// Right Angle triangle confirm flag
    }
    if(a*a == (c*c+b*b))	//Check if Pythagorous theorm appliues to sides to one combination of a, b and c
	{
		AC = a;				// Confirm for Hypotenous
		AB = c;				// Confirm for Base
		BC = b;				// Confirm for Perpendicular
		Flag=1;				// Right Angle triangle confirm flag
    }
    if(Flag) 	return sqrt(AC*AC);	//Return Hypotenous
    else 		return(Flag);		//Else Return Flag as 0	
}
 
float Alpha()
{
    //Calculate the angle between base and hypotenous
	return (acos(Base()/Hypotenuse())* 180.0) / 3.14;
}


float Beta()
{
    //Calculate the angle between perpendicular and hypotenous
    return (acos(Perpendicular()/Hypotenuse())* 180.0) / 3.14;
}


main(void)
{
	//Get the sides ofthe triangle
	cout<<"\nEnter three sides of the triangle as AB, BC and AC:";
	cout<<"\nEnter AB: "; cin>>a;	//Get side-a
	cout<<"\nEnter BC: "; cin>>b;	//Get side-b
	cout<<"\nEnter AC: "; cin>>c;	//Get side-c
	
	//Check if the sides are for a right angle triangle
	if(Hypotenuse()==0 || Base()==0 || Perpendicular()==0)
	{
		cout << "It is not a right angle triangle\n";
    }
    else
	{
		//Get the hypotaneous length
		cout << "\n\nThe length of Hypotenuse: " << Hypotenuse() << "\n";
		//Get the angle between base and hypotaneous
    	cout << "The angle between Base and Hypotenuse: " << Alpha() << "\n";
		//Get the angle between perpendicular and hypotaneous
    	cout << "The angle between Hypotenuse and Perpendicular: " << Beta() << "\n";
	}
}

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