Assignment 5 Step 1: This file contains just a program shell in which you will w
ID: 3872814 • Letter: A
Question
Assignment 5 Step 1: This file contains just a program shell in which you will write all the programming statements needed to complete the program described below. Here is a sample of the current contents of areas.cpp 1 // Assignment 5 is to compute the area (s) WRITE A COMMENT BRIEFLY DESCRIBING THE PROGRAM PUT YOUR NAME HERE. 2 3 4 // INCLUDE ANY NEEDED HEADER FILES HERE 5 using namespace std;l 7 int main) 9// DEFINE THE NAMED CONSTANT PI HERE AND SET ITS VALUE TO 3.14159 10 11 // DECLARE ALL NEEDED VARIABLES HERE. GIVE EACH ONE A DESCRIPTIVE 12// NAME AND AN APPROPRIATE DATA TYPE 13 14// WRITE STATEMENTS HERE TO DISPLAY THE 4 MENU CHOICES 15 16// WRITE A STATEMENT HERE TO INPUT THE USERS MENU CHOICE 17 18// WRITE STATEMENTS TO OBTAIN ANY NEEDED INPUT INFORMATION 19// AND COMPUTE AND DISPLAY THE AREA FOR EACH VALID MENU CHOICE 20 / IF AN INVALID MENU CHOICE WAS ENTERED, AN ERROR MESSAGE SHOULD 21 /BE DISPLAYED 23 return 0 24 ) Step 2: Design and implement the areas.cpp program so that it correctly meets the program specifications given below Specifications: Sample Run Program to calculate areas of objects Create a menu-driven program that finds and displays areas of 3 different objects. The menu should have the following 4 choices 1 -- square 2 circle 3 - right triangle 4 - quit 1square 2 -- circle 3 -- right triangle 4quit Radius of the circle: 3.0 Area 28.2743 . If the user selects choice 1, the program should find the area of a square . If the user selects choice 2, the program should . If the user selects choice 3, the program should . If the user selects choice 4, the program should . If the user selects anything else (i.e., an invalid find the area of a circle find the area of a right triangle quit without doing anything choice) an appropriate error message should be printedExplanation / Answer
#include<iostream>
#include<math.h>
#include<stdlib.h>
#define PI 3.15159
using namespace std;
void rightTriangle(int side1,int side2)
{
float area;
area=(side1*side2)/2;
cout<<" area of right triangle is "<<area;
}
void circle(int radius)
{
float area;
area=PI*radius*radius;
cout<<" area of circle is "<<area;
}
void square(int side)
{
float area;
area=side*side;
cout<<" area of square is "<<area;
}
int main()
{
int side1,side2,side3,side,length,breadth,radius;
int choice;
char ch;
do
{
cout<<" Program to calculate areas of objects";
cout<<" 1 --square ";
cout<<" 2 --circle ";
cout<<" 3 --right triangle";
cout<<" 4 --quit ";
cout<<" Enter your choice (1,2,3,4) ";
cin>>choice;
switch(choice)
{
case 1: cout<<" Enter side of square ";
cin>>side;
square(side);
break;
case 2: cout<<" Enter radius of circle ";
cin>>radius;
circle(radius);
break;
case 3: cout<<" enter side 1 of right triangle ";
cin>>side1;
cout<<" enter side 2 of right triangle ";
cin>>side2;
rightTriangle(side1,side2);
break;
case 4: cout<<" Exiting from program ";
exit(0);
break;
default:cout<<"enter a valid choice (1,2,3,4)";
}
cout<<" do you want to continue (y/n) ";
cin>>ch;
}while((ch=='y') || (ch=='Y'));
}