1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
makkiz [27]
3 years ago
12

Write a C++ program that computes the area and perimeter of aspecified shape

Computers and Technology
1 answer:
leonid [27]3 years ago
4 0

<u>C++ program that computes the area and perimeter of a specified shape</u>

#include <iostream>

#include <cmath>

using namespace std;

void rectangle() //Defining function for rectangle

{ int h,w;

cout << "Enter height: ";

//taking input

cin >> h;

cout << "Enter width: ";

cin >> w;

cout << "The perimeter of the rectangle is " <<2*h+ 2*w << " and the area is " <<h*w << endl;  //printing output

}

void triangle()  //Defining function for triangle

{ int s1,s2,s3,h,w;

cout << "Side 1: ";  //Taking input

cin >> s1;

cout << "Side 2: ";

cin >> s2;

cout << "Side 3: ";

cin >> s3;

cout << "Enter the height: ";

cin >> h;

cout << "Enter the base length: ";

cin >> w;

cout << "The perimeter of the triangle is " <<s1+s2+s3 << " and the area is " <<(.5)*w*h << endl; //printing output

}

void circle()//Defining Function for the circle

{

const double p=3.14;

int w;

cout << "Enter the radius: "; //Taking input

cin >> w;

cout << "The perimeter of the circle is " << p*2*w << " and the area is " << p*w*w<< endl;  //printing output

}

int main()  //driver function

{

int s;

cout << "Enter the shape (1 for rectangle,2 for triangle, 3 for circle): ";

//Asking user for the shape

cin >> s;

switch(s)  //checking which shape it chooses

{

case 1:

rectangle();  //If user type 1 ,then calling rectangle function

break;

case 2:

triangle();   //If user type 2 ,then calling triangle function

break;

case 3:

circle();  //If user type 3,then calling circle function

break;

default:

cout <<"Enter valid choice for shape";  //If user type other than 1,2,3

}

return 0;  

}

<u>Output</u>

Enter the shape (1 for rectangle,2 for triangle, 3 for circle): 1

Enter height:2

Enter width: 3

The perimeter of the rectangle is 10 and the area is 6

<u />

You might be interested in
I will give brainliest!!!!! I NEED HELP ASAP!!!!!!!
klemol [59]

Answer:

I'm pretty sure it's the first answer.

4 0
2 years ago
In this scenario, what is the importance of anti-virus software and other similar virus protection programs?
Svetradugi [14.3K]
To protect my computer form hacking and save my files
3 0
3 years ago
This type of server spools documents and puts them in a queue.
Paraphin [41]

Print is the type of server that spools documents and puts them in a queue. Whenever you are printing multiple documents, it is the standard operation of the printer to prioritize those documents that came first and add to the queue the other documents waiting for printing.

4 0
3 years ago
Value appears on the left hand side of cell <br> true or false
11111nata11111 [884]

Answer:

True

Your welcome

.........

4 0
2 years ago
Read 2 more answers
Which facet of the 4e framework is best addressed by thought-sharing sites?
iris [78.8K]

Educate is the facet of the 4E framework is best addressed by thought-sharing sites.

Therefore, the correct answer is Educate.

4 0
2 years ago
Other questions:
  • Which Internet resource can you use to publicly describe an adventure trip you recently made?
    9·1 answer
  • Macy reviewed Steve's presentation. Images in the slides were distracting from the presentation. What advice should
    7·2 answers
  • You are having problems on your Windows 7 computer and you pull up Device Manager to see if there are any alerts. Two of your de
    11·1 answer
  • Who all likes fortnite
    15·2 answers
  • What are expansion cards used for?​
    9·2 answers
  • What type of Internet monitoring technique records information about a customer during a web surfing session, such as what websi
    8·1 answer
  • What is a credit card balance? A...The amount of interest you must pay the credit card company B...The required minimum payment
    15·1 answer
  • Is Missouri a free state or a slave state​
    13·2 answers
  • Explain how the CPU processes data instructions.
    6·1 answer
  • Zybook C++ 3.21 answer
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!