Question

In: Computer Science

Write a c++ program that asks the user to choose his preferred shape, and asks then...

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.

  • The area of a circle is πr12-r22 (suppose π= 3.4 ).
  • The area of a triangle is base*height/2.
  • The area of a rectangle is height*width.

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.

Solutions

Expert Solution

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;
}


Related Solutions

Write a program in C++ that asks the user for his/her Taxable Income and displays the...
Write a program in C++ that asks the user for his/her Taxable Income and displays the Income Tax owed. Use the following table to calculate the Income Tax: Taxable Income Tax Rate $0 to $9,225 / 10% $9,226 to $37,450 / $922.50 plus 15% of the amount over $9,225 $37,451 to $90,750 / $5,156.25 plus 25% of the amount over $37,450 $90,751 to $189,300 / $18,481.25 plus 28% of the amount over $90,750 $189,301 to $411,500 / $46,075.25 plus 33%...
In C++ Write a program which asks the user his/ her major, stores it in a...
In C++ Write a program which asks the user his/ her major, stores it in a variable called major, then asks What is your GPA? and stores it in a variable called gpa. Next, ask a question based on the answers from the previous two questions. For example: What is your major? computer science What is your gpa? 3.52 computer science is very hard; why do you think you have a gpa of 3.52?
Write a C program that performs the following: Asks the user to enter his full name...
Write a C program that performs the following: Asks the user to enter his full name as one entry. Asks the user to enter his older brothers’ names each at a time (the user should be instructed by the program to enter NULL if he does not have any older brother). Asks the user to enter his younger brothers’ names each at a time (the user should be instructed by the program to enter NULL if he does not have...
Write a C ++ program that asks the user for the speed of a vehicle (in...
Write a C ++ program that asks the user for the speed of a vehicle (in miles per hour) and how many hours it has traveled. The program should then use a loop to display the distance the vehicle has traveled for each hour of that time period. Here is an example of the output: What is the speed of the vehicle in mph? 40 How many hours has it traveled? 3 Hour Distance Traveled -------------------------------- 1           40 2           80...
Tail of a File, C++ Program. write a program that asks the user for the name...
Tail of a File, C++ Program. write a program that asks the user for the name of a text file. The program should display the last 10 lines, or all lines if less than 10. The program should do this using seekg Here is what I have so far. #include<iostream> #include<fstream> #include<string> using namespace std; class File { private:    fstream file;    string name; public:    int countlines();    void printlines(); }; int File::countlines() {    int total =...
Program specifics: Write a C++ program that does the following: a. Asks the user for the...
Program specifics: Write a C++ program that does the following: a. Asks the user for the distance to the pin and the depth of the green (both in yards). (Note: The pin is the hole in the green and the depth is the diameter of the green, assuming it is circular.) b. Asks the user for an integer club number from 2 to 10, where 10 is the pitching wedge (this club lifts the ball out of rough, sand, etc)....
In C write a program that asks the user for the dimensions of 3 sides of...
In C write a program that asks the user for the dimensions of 3 sides of a triangle. Each side dimension must be between 1.00 and 100.00 including 1.00 and 100.00. If the side dimensions indeed can make a valid triangle then the program should use these values to determine the perimeter and the area of the valid triangle 1. Must use programmer define functions 2. Your program must have at least 4 functions, main and the following 3 functions:...
1- Write a c++ program that asks the user to enter his/her name using one variable...
1- Write a c++ program that asks the user to enter his/her name using one variable only. The name must be then printed out in capital letter with the family name first and the last name second.
c program Write a program that asks the user to enter a sequence of 15 integers,...
c program Write a program that asks the user to enter a sequence of 15 integers, each either being 0, 1, or 2, and then prints the number of times the user has entered a "2" immediately following a "1". Arrays are not allowed to appear in your code. Include ONLY THE SCREENSHOT OF YOUR CODE in an image file and submit the file.
2. Write a program C++ that asks the user for a number (not necessary to force...
2. Write a program C++ that asks the user for a number (not necessary to force any particular requirements). Write a function with the following signature: double square(double x) that returns the square of the user's number (x * x). 3. Write a C++ program that asks the user for an integer. Write a function that returns 1 of the number is even, and 0 if the number is odd. Use this function signature: int isEven(int x). 4. Write a...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT