Using namespace std Write a C program using the concept of f

Using namespace std;

Write a C++ program using the concept of function overloading for the following options:

Main Menu

Select the Options from [1-5]

1-Area of the Circle

2-Area of the Rectangle

3-Area of the Square

4-Area of the Triangle

5-Exit

Your program should work as long as the user wishes. Use appropriate variable declaration and format your output up to three decimal places with a field width 12.

Solution

#include <bits/stdc++.h>
using namespace std;

double Area(double r)
{ double pi=3.14;
   return pi*r*r;
}

double Area(double l,double b)
{
   return l*b;
}

double Area(int s)
{
   return s*s;
}

double Area(int b,int h)
{
   return 0.5*b*h;
}

int main(int argc, char const *argv[])
{
cout << setw (12);
int flag=1;
while(flag)
{
       cout<<\"Main Menu\ Select the Options from [1-5]\ 1-Area of the Circle\ 2-Area of the Rectangle\ 3-Area of the Square\ 4-Area of the Triangle\ 5-Exit\ \";

   int ch;
   cin>>ch;
   switch(ch)
   {
       case 1:cout<<\"Enter Radius of circle\ \";
       double r;
       cin>>r;
       cout<<setprecision(3)<<\"Area of circle is \"<<Area(r)<<endl;
       break;

       case 2:cout<<\"Enter length and breadth of rectangle\ \";
       double l,b;
       cin>>l>>b;
       cout<<setprecision(3)<<\"Area of circle is \"<<Area(l,b)<<endl;
       break;
       case 3:cout<<\"Enter side of square\ \";
       int s;
       cin>>s;
       cout<<\"Area of circle is \"<<Area(s)<<endl;
       break;
       case 4:cout<<\"Enter base and height of Triangle\ \";
       int base,h;
       cin>>base>>h;
       cout<<\"Area of circle is \"<<Area(base,h)<<endl;
       break;
       case 5:
       flag=0;break;

   }
}

      
          
  
   return 0;
}

=================================================

akshay@akshay-Inspiron-3537:~/Chegg$ g++ three.cpp
akshay@akshay-Inspiron-3537:~/Chegg$ ./a.out
Main Menu
Select the Options from [1-5]
1-Area of the Circle
2-Area of the Rectangle
3-Area of the Square
4-Area of the Triangle
5-Exit
1
Enter Radius of circle
2
Area of circle is 12.56
Main Menu
Select the Options from [1-5]
1-Area of the Circle
2-Area of the Rectangle
3-Area of the Square
4-Area of the Triangle
5-Exit
2
Enter length and breadth of rectangle
2
3
Area of circle is 6
Main Menu
Select the Options from [1-5]
1-Area of the Circle
2-Area of the Rectangle
3-Area of the Square
4-Area of the Triangle
5-Exit
3
Enter side of square
4
Area of circle is 16
Main Menu
Select the Options from [1-5]
1-Area of the Circle
2-Area of the Rectangle
3-Area of the Square
4-Area of the Triangle
5-Exit
4

Enter base and height of Triangle
2
6
Area of circle is 6
Main Menu
Select the Options from [1-5]
1-Area of the Circle
2-Area of the Rectangle
3-Area of the Square
4-Area of the Triangle
5-Exit
5

Using namespace std; Write a C++ program using the concept of function overloading for the following options: Main Menu Select the Options from [1-5] 1-Area of
Using namespace std; Write a C++ program using the concept of function overloading for the following options: Main Menu Select the Options from [1-5] 1-Area of
Using namespace std; Write a C++ program using the concept of function overloading for the following options: Main Menu Select the Options from [1-5] 1-Area of

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site