Computer Science, asked by mukeshsahh83, 4 months ago

create a class shape which has two overloaded member function: Area( ) and perimeter ( ). Depending upon whether the dimensions are input as integers or floating point numbers, calculate the area and perimeter of three different shapes.The dimensions of the shape would be entered by the user.the output should be in the format as the input.write a program in C++.​

Answers

Answered by chandnaaashman7
1

Answer:

very easy bro , just figure it out

Explanation:

Program for Area And Perimeter Of Rectangle

Last Updated: 23-04-2018

A rectangle is a flat figure in a plane.It has four sides and four equal angles of 90 degree each.In rectangle all four sides are not of equal length like square, sides opposite to each other have equal length.Both diagonals of rectangle have equal length.

Examples:

Input : 4 5

Output : Area = 20

        Perimeter = 18

Input : 2 3

Output : Area = 6

        Perimeter = 10

Recommended: Please try your approach on {IDE} first, before moving on to the solution.

Formulae :

ADVERTISING

Area of rectangle : a*b  

Perimeter of ractangle: 2*(a + b)

C++

filter_none

edit

play_arrow

brightness_4

// CPP program to find area  

// and perimeter of rectangle  

#include<bits/stdc++.h>  

using namespace std;  

 

// Utility function  

int areaRectangle(int a, int b)  

{  

  int area = a * b;  

  return area;  

}  

 

int perimeterRectangle(int a, int b)  

{  

  int perimeter = 2*(a + b);  

  return perimeter;  

}  

 

// Driver program  

int main()  

{  

 int a = 5;  

 int b = 6;  

 cout << "Area = " << areaRectangle(a, b) << endl;  

 cout << "Perimeter = " << perimeterRectangle(a, b);  

 return 0;  

}  

python

Answered by Rohanaj60
3

Answer:

Explanation:

//Program By RNZ :D

#include <iostream>

using namespace std;

#define PI 3.14

class shape

{

public:

   void Area(int r);

   void Area(int l, int b);

   void Perimeter(float r);

   void Perimeter(int c, int d);

   void Area(float q, float w);

   void Perimeter(int v, int b, int n);

};

void shape::Area(int r)

{

   cout << "The Area Of CIRCLE is " << PI * r * r << endl;

}

void shape::Area(int l, int b)

{

   cout << "The Area of Rectangle is " << l * b << endl;

}

void shape::Perimeter(float r)

{

   cout << "The Perimeter of CIRCLE is " << 2 * PI * r << endl;

}

void shape::Perimeter(int c, int d)

{

   cout << "The perimeter of Rectangle is " << 2 * (c + d) << endl;

}

void shape::Area(float q, float w)

{

   cout << "The Area of Triangle is " << (q * w) / 2 << endl;

}

void shape::Perimeter(int v, int b, int n)

{

   cout << "The Perimeter of Triangle is " << (v + b + n) << endl;

}

int main()

{

   int le, br, cr;

   int ch;

   int t1, t2, t3;

   int t4, t5;

   shape rnz;

   cout << "Program to Find both Area And Perimeter of the different shapes" << endl;

   cout << "Press 1 for CIRCLE " << endl;

   cout << "Press 2 for RECTANGLE " << endl;

   cout << "Press 3 for TRIANGLE " << endl;

   cin >> ch;

   switch (ch)

   {

   case 1:

       cout << "Enter The radius of circle" << endl;

       cin >> cr;

       rnz.Perimeter(cr);

       rnz.Area(cr);

       break;

   case 2:

       cout << "Enter The dimension of rectangle" << endl;

       cin >> le >> br;

       rnz.Perimeter(le, br);

       rnz.Area(le, br);

       break;

   case 3:

       cout << "Enter base and height of Triangle" << endl;

       cin >> t4 >> t5;

       rnz.Area(t4, t5);

       cout << "Enter sides of Triangle" << endl;

       cin >> t1 >> t2 >> t3;

       rnz.Perimeter(t1, t2, t3);

       break;

   default:

       cout << "Please choose Correct Choice" << endl;

       break;

   }

   return 0;

}

Similar questions