Perimeter and area of an abstract shape

Hi guys, so this is actually my first program in my C++ course. The main goal of this program is to find the area and perimeter of this shape:

http://img829.imageshack.us/img829/9195/img20110919140134.jpg

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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// September 20, 2011
//Second program finding perimeter and area 

#include <fstream>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <stdlib.h>

using namespace 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
Last edited on
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.
So do exactly what I did to calculate the areas but instead now do it with the perimeter then add up all the outside sides?
Well yeah I suppose.
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:


http://img829.imageshack.us/img829/9195/img20110919140134.jpg

(I'm calculating the left ellipse)


Shouldn't I cut the value I obtained in half because I only need the outside half of the ellipse?
Last edited on
I just realized I did the power's wrong :-)
Topic archived. No new replies allowed.