In: Computer Science
Write a c++ program that asks the user to choose his preferred shape, and asks then for two numbers (positive but not necessary integers) in order to calculate the shape's area.
The possible shapes are: Triangle, Ring and Rectangle. If the user chose a different shape, you
will warn him and wait for a valid shape.
While the user will enter the values in cm , the program will display the number of paint bottles
needed to paint the area of the shape. Each bottle can cover 5cm^2. The number of paint bottles should be an integer value.
Note:
AS THE NUMBER OF BOTTLES MUST BE AN INTEGER,WE WILL TAKE CEIL OF THE ACTUAL ANSWER.
Eg:if numberofbottles=3.4 then we will take
number ofbottles=4 as we have to take integer value
#include<iostream>
#include<cmath>
using namespace
std;
int main()
{
cout<<"
1.TRIANGLE\n";
cout<<"
2.RING\n";
cout<<"
3.RECTANGLE\n";
cout<<"CHOOSE ONE OF
THE ABOVE SHAPES,ENTER NUMBER ACCORDINGLY:";
int choice;
cin>>choice;
while(choice<1 ||
choice>3)
{
cout<<"PLEASE MAKE
SURE YOU CHOOSE ONE OF THE ABOVE SHAPES ONLY:";
cin>>choice;
}
float
a,b,temp;
cout<<"Enter two
values a and b:";
cin>>a>>b;
if(a<b)
{
temp=a;a=b;b=temp;
}
float area=0;
if(choice==1)
area=(a*b)/2;
else
if(choice==2)
area=3.4*(a*a-b*a);
else
area=a*b;
int bottles=0;
bottles=ceil(area/5);
cout<<"Number of
paint bottles requires is
:"<<bottles<<"\n";
return 0;
}