In: Computer Science
areaCircle() – should accept the radius of the circle from the main function, calculate the area, and then print the area of the circle.
Code:
#include<iostream>
#include<cmath>
using namespace std;
#define PI M_PI
void displayMenu()
{/*printing the menu*/
   cout<<"Menu"<<endl;
   cout<<"1.Area of Square"<<endl;
   cout<<"2.Area of Rectangle"<<endl;
   cout<<"3.Area of
Parllelogram"<<endl;
   cout<<"4.Area of Circle"<<endl;
   cout<<"5.Exit"<<endl;
}
double areaSquare(double height)
{/*Returning the area of the square*/
   return(height*height);
}
double areaRectangle(double height,double width)
{/*Returning the area of the rectangle*/
   return(height*width);
}
double areaParllelogram(double base,double height)
{/*Returning the area of the parllelogram*/
   return(base*height);
}
double areaCircle(double radius)
{/*Returning the area of the circle*/
   return(PI*radius*radius);
}
int main()
{
   int choice;
   double height,width,base,radius;/*Declaring
variables*/
   do
   {/*This loop iterates untill choice is 5*/
       displayMenu();/*Calling display
menu*/
       cout<<"Enter your
choice:";
       cin>>choice;/*Reading choice
form the user*/
       switch(choice)
       {
           case 1:/*If
choice is 1*/
          
    cout<<"Enter the height of the
square:";
          
    cin>>height;/*Reading height of the
square*/
          
    cout<<"Area of the square is
:"<<areaSquare(height)<<endl;
          
    break;/*Printing the area of square by calling
areaSquare function*/
           case 2:/*If
choice is 2*/
          
    cout<<"Enter the height of the
rectangle:";
          
    cin>>height;
          
    cout<<"Enter the width of the
rectangle:";
          
    cin>>width;/*Reading height and
width*/
          
    cout<<"Area of the Rectangle is
:"<<areaRectangle(height,width)<<endl;
          
    break;/*Printing the result*/
           case 3:/*If
choice is 3*/
          
    cout<<"Enter the base of the
parllelogram:";
          
    cin>>base;
          
    cout<<"Enter the height of the
parllelogram:";
          
    cin>>height;/*Reading height and base
*/
          
    cout<<"Area of the Parllelogram is
:"<<areaParllelogram(base,height)<<endl;
          
    break;/*Printing the result*/
           case 4:/*If
choice is 4*/
          
    cout<<"Enter the radius of the
circle:";
          
    cin>>radius;/*Reading radius form the
user*/
          
    cout<<"Area of the
circle:"<<areaCircle(radius)<<endl;
          
    break;/*printing the result*/
           case 5:/*If
choice is 5*/
          
    break;
           default:
          
    cout<<"Invalid choice"<<endl;
          
    break;      
       }  
   }
   while(choice!=5);  
}
Output:

Indentation:

