> Please help me out with this C++ program(to calculate area and perimeter of a right angled triangle)?

Please help me out with this C++ program(to calculate area and perimeter of a right angled triangle)?

Posted at: 2014-12-18 
You are missing the point of object oriented programming.

You cannot call a method of an object if the object does not yet exist (With possible exceptions of class methods).

You need to first declare an instance of an rTriangle before you can call it's methods.

int main()

{

rTriangle t;

t.getData();

t.area();

t.perimeter();

t.display();

}

One other sticking point is that your getData method does not have a return statement. You defined the method with a return value in the prototype . This is probably unnecessary. You can get rid of the return type.

void rTriangle::getData()

{

cout<<"Enter base 1";

cin>>a;

cout<<"enter base 2";

cin>>b;

}

Make those 2 changes and the program will run.

I think it may be that you aren't calling the functions. you may be just declaring them again in your main function. try getdata() without the int in the main?

This is a C++ program to calculate area and perimeter of a right angled triangle. When i compile it, no errors are shown. But when i run it, it shows"Process exited with return value 0" while it is supposed to ask the user to input the values of the two base lengths initially.

#include

using namespace std;

class rTriangle

{

int a,b;

float Area,per;

public:

int getData();

float area();

float perimeter();

void display();

};

int rTriangle::getData()

{

cout<<"Enter base 1";

cin>>a;

cout<<"enter base 2";

cin>>b;

}

float rTriangle::area()



{

Area=(a*b)/2;

return Area;



}

float rTriangle::perimeter()

{

per=a+b+(a^2+b^2)^1/2 ;

return per;

}

void rTriangle::display()

{

cout<<"base 1 is"<
}

int main()

{

int getData();

float area();

float perimeter();

void display();

}