Computer Science, asked by manyaacdikshit, 8 months ago

Write a class with the name Perimeter using function overloading that computes
the perimeter of a square, a rectangle and a circle.
Formula:
Perimeter of a square = 4 * s
Perimeter of a rectangle = 2 * (l + b)
Perimeter of a circle = 2 * (22/7) * r

Answers

Answered by Anonymous
2

Explanation:

Write a class Perimeter using function overloading calculate() that computes the perimeter of a square, a rectangle and a circle. Formula: Perimeter of a square = 4 * s. Perimeter of a rectangle = 2 * (l + b)

Top answer · 4 votes

Answer:HOPE IT WILL HELP YOU............ PLEASE MARK IT AS

Answered by mad210203
5

Program is given below.

Explanation:

#include<iostream>

using namespace std;

class Perimeter

{

private:

int length;

int breadth;

int side;

int radius;

int p;

public:

void perimeter(int l, int b)

{

length=l;

breadth=b;

p=2*(length+breadth);

cout<<"Length of the Rectangle: "<<length<<" cm"<<endl;

cout<<"Breadth of the Rectangle: "<<breadth<<" cm"<<endl;

cout<<"Perimeter of the Rectangle is equal to "<<p<<" cm."<<endl;

}

void perimeter(int s)

{

side=s;

p=4*s;

cout<<"Side of the Square: "<<side<<" cm"<<endl;

cout<<"Perimeter of the Square is equal to "<<p<<" cm."<<endl;

}

/* Here, perimeter of circle contains only 1 argument. If we write same function name as previous one, we get a error because already we have a function with 1 argument. So, we need to change name for this function. */

void perimeter_of_circle(int r)

{

radius=r;

p=2*(22/7)*r;

cout<<"Radius of the circle: "<<radius<<" cm"<<endl;

cout<<"Perimeter of the Circle is equal to "<<p<<" cm (Approximately)."<<endl;

}

};

int main()

{

Perimeter p1;

p1.perimeter(4,5);

cout<<endl;

p1.perimeter(7);

cout<<endl;

p1.perimeter_of_circle(2);

cout<<endl;

}

Refer the attached image for the output.

Attachments:
Similar questions