Computer Science, asked by sonumhaske23, 11 months ago

write a c++ program to calculate area of rectangle if choise is a & calculate area of circle if choise is b

Answers

Answered by QGP
3

Menu Driven Program in C++


Such a program requires the use of switch with different cases. We ask for user input and based on it we execute a specific code. Here is a program which accomplishes the given task:


/* Write a C++ Program to calculate the area of a rectangle if choice is 'a' and the area of a circle if choice is 'b' */


#include <iostream>

using namespace std;


int main()

{

   cout << "---MENU---" << endl;

   cout << "a) Area of rectangle" << endl;

   cout << "b) Area of circle" << endl;

   

   cout << "\nEnter your choice [a/b]: ";

   char choice;

   

   cin >> choice;

   

   cout << endl;

   float area;

   switch(choice)

   {

       case 'a':

           float length, breadth;

           

           cout << "Enter length: ";

           cin >> length;

           

           cout << "\nEnter breadth: ";

           cin >> breadth;

           

           area = length * breadth;

           

           cout << "\nArea of Rectangle = " << area << endl;

           break;

           

       case 'b':

           float radius, pi;

           pi = 3.1416;

           

           cout << "Enter radius of circle: ";

           cin >> radius;

           

           area = pi*radius*radius;

           

           cout << "\nArea of Circle = " << area << endl;

           break;

       

       default:

           cout << "Invalid Input" << endl;

   }

   return 0;

}

Attachments:
Similar questions