In this program i am trying to find the perimeter of an ellipse and even when I try switching one number I still get the same answer. I know it is not correct because i solved it on my calculator and cannot seem to get the correct answer.. can someone help me please? This is what my program looks like and what is bold is where I seem to be having trouble. The equation i have for a half an ellipse is π√a2+√b2÷2 (The square root goes over a2+b2 [2's are squared]). I believe the correct answer to the perimeter of the figure in this whole program is 62.3833.

#include<fstream>

#include<iomanip>

#include<iostream>

#include<math.h>

#include<stdlib.h>

using namespace std;

int main()

{

double a,b,c,d,e,f,g,h;

double pi=acos (-1.0);

double A_Trig,A_Rect,A_Ellipse,A_Circle,A_Par;

double P_Trig,P_Rect,P_Ellipse,P_Circle,P_Par;

ofstream output ("C:result.dat");

cout<<"Tyler Perry"<<endl;

output<<"Tyler Perry"<<endl;

a=10.0;

b=3.0;

c=5.0;

d=4.0;

e=3.5;

f=11.0;

g=6.4;

h=4.3;

A_Trig= 1.0/2*c*d;

cout<<"The area of the triangle is="<<A_Trig<<endl;

output<<"The area of the triangle is="<<A_Trig<<endl;

A_Rect= f*a;

cout<<"The area of the rectangle is="<<A_Rect<<endl;

output<<"The area of the rectangle is="<<A_Rect<<endl;

A_Ellipse=(1/2.0)*(pi*b*c);

cout<<"The area of the ellipse is="<<A_Ellipse<<endl;

output<<"The area of the ellipse is="<<A_Ellipse<<endl;

A_Circle=(pi*pow(b,2)/2);

cout<<"The area of the circle is="<<A_Circle<<endl;

output<<"The area of the circle is="<<A_Circle<<endl;

A_Par=e*a;

cout<<"The area of the parallelogram is="<<A_Par<<endl;

output<<"The area of the parallelgram is="<<A_Par<<endl;

double Area=A_Trig+A_Rect+A_Ellipse+A_Circle+A_Par;

(A_Trig+A_Rect+A_Ellipse+A_Circle+A_Par);

cout<<"The total area of the figure is="<<Area<<endl;

output<<"The total area of the figure is="<<Area<<endl;

P_Trig=d+g;

**P_Ellipse=pi*(pow(b,2)+(pow(c,2)),(1.0/2))/2;**

cout<<"Ellipse="<<P_Ellipse<<endl;

output<<"Ellipse="<<P_Ellipse<<endl;

P_Circle=(pi)*(b);

P_Par=(2*h)+(a);

double Perimeter=P_Trig+P_Ellipse+P_Circle+P_Par+f;

(P_Trig+P_Ellipse+P_Circle+P_Par+f);

cout<<"The total perimeter of the figure is="<<Perimeter<<endl;

output<<"The total perimeter of the figure is="<<Perimeter<<endl;

system("PAUSE");

return 0;

}

#include<fstream>

#include<iomanip>

#include<iostream>

#include<math.h>

#include<stdlib.h>

using namespace std;

int main()

{

double a,b,c,d,e,f,g,h;

double pi=acos (-1.0);

double A_Trig,A_Rect,A_Ellipse,A_Circle,A_Par;

double P_Trig,P_Rect,P_Ellipse,P_Circle,P_Par;

ofstream output ("C:result.dat");

cout<<"Tyler Perry"<<endl;

output<<"Tyler Perry"<<endl;

a=10.0;

b=3.0;

c=5.0;

d=4.0;

e=3.5;

f=11.0;

g=6.4;

h=4.3;

A_Trig= 1.0/2*c*d;

cout<<"The area of the triangle is="<<A_Trig<<endl;

output<<"The area of the triangle is="<<A_Trig<<endl;

A_Rect= f*a;

cout<<"The area of the rectangle is="<<A_Rect<<endl;

output<<"The area of the rectangle is="<<A_Rect<<endl;

A_Ellipse=(1/2.0)*(pi*b*c);

cout<<"The area of the ellipse is="<<A_Ellipse<<endl;

output<<"The area of the ellipse is="<<A_Ellipse<<endl;

A_Circle=(pi*pow(b,2)/2);

cout<<"The area of the circle is="<<A_Circle<<endl;

output<<"The area of the circle is="<<A_Circle<<endl;

A_Par=e*a;

cout<<"The area of the parallelogram is="<<A_Par<<endl;

output<<"The area of the parallelgram is="<<A_Par<<endl;

double Area=A_Trig+A_Rect+A_Ellipse+A_Circle+A_Par;

(A_Trig+A_Rect+A_Ellipse+A_Circle+A_Par);

cout<<"The total area of the figure is="<<Area<<endl;

output<<"The total area of the figure is="<<Area<<endl;

P_Trig=d+g;

cout<<"Ellipse="<<P_Ellipse<<endl;

output<<"Ellipse="<<P_Ellipse<<endl;

P_Circle=(pi)*(b);

P_Par=(2*h)+(a);

double Perimeter=P_Trig+P_Ellipse+P_Circle+P_Par+f;

(P_Trig+P_Ellipse+P_Circle+P_Par+f);

cout<<"The total perimeter of the figure is="<<Perimeter<<endl;

output<<"The total perimeter of the figure is="<<Perimeter<<endl;

system("PAUSE");

return 0;

}

Last edited on

i figured it out thanks tho. All i was doing wrong was that i forgot to add an additional pow() command for the square root. Silly mistake.

and i was using the same formula shown above. I got it from http://www.mathsisfun.com/geometry/ellipse-perimeter.html , but that is for a full ellipse so I removed the 2 in front of the equation making it so it was for half an ellipse opposed to a full ellipse.

and i was using the same formula shown above. I got it from http://www.mathsisfun.com/geometry/ellipse-perimeter.html , but that is for a full ellipse so I removed the 2 in front of the equation making it so it was for half an ellipse opposed to a full ellipse.

Last edited on

How about

pi*sqrt( (b*b+c*c)/2.0 );

?

This is just a rough approximation to the perimeter of an ellipse, see here

http://www.mathsisfun.com/geometry/ellipse-perimeter.html

pi*sqrt( (b*b+c*c)/2.0 );

?

This is just a rough approximation to the perimeter of an ellipse, see here

http://www.mathsisfun.com/geometry/ellipse-perimeter.html

the formula should look like this:

for the WHOLE PERIMETER of the ellipse:

double P_Ellipse = 2 * pi * sqrt((pow(a, 2) + pow(b, 2)) / 2);

for HALF of the PERIMETER of the ellipse:

double P_Ellipse = ((2 * pi * sqrt((pow(a, 2) + pow(b, 2)) / 2)) / 2) + a;

for the WHOLE PERIMETER of the ellipse:

double P_Ellipse = 2 * pi * sqrt((pow(a, 2) + pow(b, 2)) / 2);

for HALF of the PERIMETER of the ellipse:

double P_Ellipse = ((2 * pi * sqrt((pow(a, 2) + pow(b, 2)) / 2)) / 2) + a;

Never thought of that way, but I see how that would work the exact same way just without needing pow(). Thanks for the help!

if the second formula doesn't work quite right, try this instead:

double P_Ellipse = ((2 * pi * sqrt((pow(a, 2) + pow(b, 2)) / 2)) / 2) + b;

notice that the 'a' at the end changed to a 'b', which is changing the major axis to the minor axis.

double P_Ellipse = ((2 * pi * sqrt((pow(a, 2) + pow(b, 2)) / 2)) / 2) + b;

notice that the 'a' at the end changed to a 'b', which is changing the major axis to the minor axis.

Topic archived. No new replies allowed.