answersLogoWhite

0


Best Answer

#include<iostream>

struct shape

{

virtual double perimeter() const = 0;

virtual double area() const = 0;

};

struct circle : shape

{

circle (double radius): r(radius), pi(4*atan(1)) {}

double perimeter() const { return 2*pi*r; }

double area() const { return pi*r*r; }

private:

double r;

const double pi;

};

struct rectangle : shape

{

rectangle (double width, double height): w(width), h(height) {}

double perimeter() const { return 2*(w+h); }

double area() const { return w*h; }

private:

double w;

double h;

};

int main()

{

using std::cout;

using std::endl;

circle c (3.0);

cout << "Circle with radius 3.0\n";

cout << "\tPerimiter: " << c.perimiter() << '\n';

cout << "\tArea: " << c.area() << '\n';

cout << endl;

rectangle r (4.0, 5.0);

cout << "Rectangle with width 4.0 and height 5.0\n";

cout << "\tPerimiter: " << r.perimiter() << '\n';

cout << "\tArea: " << r.area() << '\n';

cout << endl;

}

User Avatar

Wiki User

9y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is the c plus plus program to find the area and perimeter of a circle and rectangle?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Math & Arithmetic
Related questions

If A circle and rectangle have the same area the circle has a diameter of 42 centimeters and rectangle has a width of 18 centimeters find the perimeter of the rectangle?

Area of circle = pi*212 = 1385.44236 square cm Area of rectangle = 1385.44236 square cm Lenght of rectangle = 1385.44236/18 = 76.96902 cm Perimeter of rectangle = 2(76.96902)+2(18) = 189.93804 cm


If two shapes have the same perimeter will they have the same area?

Not at all. For example:A square of 2 x 2 will have a perimeter of 8, and an area of 4. A rectangle of 3 x 1 will also have a perimeter of 8, and an area of 3.A "rectangle" of 4 x 0 will also have a perimeter of 8, but the area has shrunk down to zero. The circle has the largest area for a given perimeter/circumference.


How do you maximize the area given the perimeter?

In the case of a rectangle, you would maximize the area given the perimeter by making the dimensions equal. In other words, you would make the rectangle into a square. However, to truly maximize the area, you would make the perimeter a perfect circle.


Same perimeter different area?

Circle, square, triangle and rectangle of same perimeter. Which will have more area?? The circle will have the greatest area. For regular polygons, the greater the number of vertices, the greater the area. (And so, in the limit, the circle, with an infinite number of vetices, has the greatest area.)


There are three shapes circle rectangle and square which one has least perimeter?

For a given area a circle has least perimeter. eg Let area = 100 sq cms. For the square or rectangle the perimeter = 40 cms For the circle the radius is square root of 100/3.1416 = 5.64 and the circumference = 2 x radius x 3.1416 = 35.44 cms


What is the area of a perimeter of 20 centimeters?

The perimeter and area don't depend on each other. Knowing one doesn't tell you the other. -- A circle with perimeter (circumference) of 20 cm has area of 31.83 cm2. -- A square with perimeter of 20 cm has area of 25 cm2 . -- A (9 x 1) rectangle has perimeter of 20 cm and area of 9 cm2 . -- A (8 x 2) rectangle has perimeter of 20 cm and area of 16 cm2 . -- A (7 x 3) rectangle has perimeter of 20 cm and area of 21 cm2 . -- A (6 x 4) rectangle has perimeter of 20 cm and area of 24 cm2 .


The area of a rectangle is 100 inches the perimeter is 40 a second rectangle has the same area but a different perimeter. Is the second rectangle a square?

the area of a rectangleis 100 square inches. The perimeter of the rectangle is 40 inches. A second rectangle has the same area but a different perimeter. Is the secind rectangle a square? Explain why or why not.


What do you notice about the area of shapes that have the same perimeter?

That two different shapes may well have the same perimeter, but different areas. As an example, a 3 x 1 rectangle and a 2 x 2 rectangle have the same perimeter, but the area is different.


If same area in a rectangle does that mean same perimeter?

No. For example, a 4x1 rectangle will have an area of 4 and a perimeter of 10. A 2x2 rectangle will have the same area of 4, but a perimeter of 8.


The length of a rectangle is twice its width If the perimeter of the rectangle is 54y find its area?

The length of a rectangle is twice its width. If the perimeter of the rectangle is , find its area.


What is the perimeter of a rectangle with an area of 24cm?

The perimeter of the rectangle is the sum of its 4 sides.


How can you find the answer for the perimeter and area of a rectangle?

find the perimeter and area of a rectangle that is 15cm long and 5cm wide