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
Can anyone help my please
Makovka662 [10]

order: soil, plant seeds, water, seedling, corn plant

4 0
1 year ago
Read 2 more answers
Petra has an interview with an IT company. What technique can help prepare her?
SVEN [57.7K]
I would go C because that way it gets her prepared to answer any techie questions they would have for her and would make her a better option.
3 0
2 years ago
Read 2 more answers
Based on your prior knowledge, match each civilization to the region it occupied.<br>​
zhannawk [14.2K]

Answer: Inca- South America

Aztec - Meso America

Explanation:

7 0
3 years ago
The type of line shown below represents an / a:​
VikaD [51]

Answer:

esrfsrtg

Explanation:

6 0
2 years ago
Which function can NOT be performed using the Conditional Formatting option?
Liono4ka [1.6K]

Answer:D is the answer to this one

5 0
3 years ago
Read 2 more answers
Other questions:
  • Regulatory control limits the activities of an organization in compliance with the organization's policies. True False
    14·2 answers
  • You are looking to buy a laptop on a budget and want to save money by not purchasing an extended service agreement with the manu
    13·1 answer
  • Discuss the differences between permanent internal memory and volatile internal memory.
    14·1 answer
  • At age 16 Cheyanne just got her drivers license
    5·2 answers
  • Anna’s computer will not power on. What aspect of the computer should Anna check (hardware or software)? How can Anna work to re
    5·1 answer
  • A common technique for masking contents of messages or other information traffic so that opponents can not extract the informati
    14·1 answer
  • (15 POINTS) When an error is made in HTML code, the browser does what?
    11·1 answer
  • PLZ ANSWER THESE QUESTIONS FOR 30 POINTS AND BRAINLIEST!
    9·1 answer
  • Five examples of technology in community​
    7·2 answers
  • HELP ASAP 10 POINTS COMPUTER SCIENCE
    14·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!