Click here to Skip to main content
15,910,981 members

Comments by Member 12959299 (Top 23 by date)

Member 12959299 8-Oct-20 0:52am View    
This question has been answered here - https://stackoverflow.com/a/64057717/7444874
Member 12959299 8-Oct-20 0:51am View    
This question has been answered here - https://stackoverflow.com/a/64057717/7444874
Member 12959299 5-Mar-17 0:29am View    
Thank you so much for writing in detail.
Member 12959299 2-Feb-17 11:55am View    
Deleted
OK now, the complete exercise is:-

Create a class called Triangle that stores the length of the base and height of a right triangle in two private instance variables. Include a constructor that sets these values. Define two functions. The first is hypot( ), which returns the length of the hypotenuse. The second is area( ),which returns the area of the triangle.

The program is :-

#include<stdio.h>
#include<conio.h>
#include<iostream.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
class triangle
{
private:
double length,height,ar,hyp;
public:
triangle(double l, double h);
double hypot();
double area();
};
triangle::triangle(double l, double h)
{
length=l;
height=h;
}
double triangle::hypot()
{
hyp=sqrt(pow(length,2)+pow(height,2));
return hyp;
}
double triangle::area()
{
ar=(length*height)/2;
return ar;
}
main()
{
double l,h;
clrscr();
cout<<"enter length of the base of the right angled triangle: ";
cin>>l;
cout<<"\nenter height the right angled triangle: ";
cin>>h;
triangle o(l,h);
cout<<o.hypot();
cout<<o.area();
getch();
}

/*Everything is well when I call either of the functions cout<<o.hypot(); or cout<<o.area(); once everytime I run the program, but when I call the functions together, then it gives me the wrong answer.
eg. if I enter the length and height of the triangle as 4 and 3 respectively, and call the function cout<<o.hypot(); it shows hypotenuse as 5 or if I call the function cout<<o.area(); it shows area as 6, both of which are correct, but when I call both the functions together, it shows just one answer 56 which neither the hypotenuse nor the area. How to correct it ?*/
Member 12959299 2-Feb-17 9:26am View    
Yes, confusing for a beginner