I think I successfully completed the "area" portion of it but I'm mainly wondering how exactly I should go about doing the perimeter portion. Is the optimal solution to use the previous variable's I set for the sides and add the ones that are on the outside of the shape?
Also, do you guys mind looking over the area work I did as well.
// September 20, 2011
//Second program finding perimeter and area
#include <fstream>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <stdlib.h>
usingnamespace std;
int main()
{
//Calculating area for the square
double a1, b1, area1;
ofstream output("e:result.dat");
cout<<"September 20, 2011 -- Second Program"<<endl;
output<<"September 20, 2011 -- Second Program"<<endl;
a1=10.0;
b1=11.0;
area1=a1*b1;
cout<<"The area of the rectangle is: "<<area1<<" meters"<<endl;
output<<"The area of the rectangle is: "<<area1<<" meters"<<endl;
//Calculating area for the triangle
double a2, b2, area2;
a2=5;
b2=4;
area2=.5*a2*b2;
cout<<"The area of the triangle is: "<<area2<<" meters"<<endl;
output<<"The area of the triangle is: "<<area2<<" meters"<<endl;
//Calculating area of the circle
double a3,area3;
double PI = 4.0*atan(1.0);
a3=3.0;
area3= PI*a3*a3;
cout<<"The area of the circle is: "<<area3<<" meters"<<endl;
output<<"The area of the circle is: "<<area3<<" meters"<<endl;
//Calculating area of the ellipse
double a4,b4,area4;
a4=3.0;
b4=5.0;
area4= PI*a4*b4;
cout<<"The area of the ellipse is: "<<area4<<" meters"<<endl;
output<<"The area of the ellipse is: "<<area4<<" meters"<<endl;
//Calculating area of the parallelogram
double a5,b5,area5;
a5=3.5;
b5=10.0;
area5 = a5 * b5;
cout<<"The area of the parallelogram is: "<<area5<<" meters"<<endl;
output<<"The area of the parallelogram is: "<<area5<<" meters"<<endl;
//Calculating the area of the whole shape
double area6;
area6 = area1+area2+area3+area4+area5;
cout<<"The area of the whole shape is: "<<area6<<" meters"<<endl;
output<<"The area of the whole shape is: "<<area6<<" meters"<<endl;
system("PAUSE");
return 0;
}
September 20, 2011 -- Second Program
The area of the rectangle is: 110 meters
The area of the triangle is: 10 meters
The area of the circle is: 28.2743 meters
The area of the ellipse is: 47.1239 meters
The area of the parallelogram is: 35 meters
The area of the whole shape is: 230.398 meters
I suppose that the perimeter is only supposed to be the outside shape?
Just calculate the perimeter of the semi ellipse, the semi circle, the 2 outer sides of the triangle, the 3 outer sides of the parallelogram, and the one side of the rectangle. Just like you'd do it on paper.
I'm trying to calculate the perimeter of an ellipse but it doesn't seem to be calculating the right answer so I'm assuming I have it written wrong in the program...
2πSqrt((r1² + r2²) / 2)
r1 = 5
r2 = 3
p1= 2*PI*sqrt((r1,2+r2,2)/2);
That is what I have, and the compiler is saying it is 6.28319 while my calculator answer is 25.906
Also, seeing how I'm calculating the perimeter of the whole shape: