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
Chris is working with other employees on a worksheet. the other employees have made comments, but they are not visible.
andriy [413]

Answer:

a. select show all comments on the review tab

Explanation:

Please mark me brainliest if correct

7 0
2 years ago
Create a game that rolls two dies (number from 1 to 6 on the side) sequentially for 10 times (use loop). If at least once out of
Alex73 [517]

Answer:

Explanation:

The following code is written in Java and loops through 10 times. Each time generating 2 random dice rolls. If the sum is 10 it breaks the loop and outputs a "You Win" statement. Otherwise, it outputs "You Lose"

import java.util.Random;

class Brainly {

   public static void main(String[] args) {

       UseRandom useRandom = new UseRandom();

       boolean youWin = false;

       for (int x = 0; x<10; x++) {

           int num1 = useRandom.getRandom(6);

           int num2 = useRandom.getRandom(6);

           if ((num1 + num2) == 10) {

               System.out.println("Number 1: " + num1);

               System.out.println("Number 2: " + num2);

               System.out.println("You Win");

               youWin = true;

               break;

           }

       }

       if (youWin == false) {

           System.out.println("You Lose");

       }

   }

}

class UseRandom{

   public int getRandom(int n)

   {

       Random r=new Random();

       int rand=r.nextInt(n);

       return rand;

   }}

8 0
3 years ago
What is the default setting Excel shows when Insert is clicked?
NikAS [45]

Answer: entire column

7 1
3 years ago
Read 2 more answers
Develop a script to demonstrate an understanding of the overload (overwrite) methods of using Python operators. This lesson will
MrRa [10]

hsjshekejeoehejeoejebenwkwuwbnwlwjdvrbrnfnfjkddjddmdmdndnfndmdkdjdjdjdjjdjdjdjdkdkdkdkdfkkdjdjdjdyremssjyehsmmamaajbshsjsbdbsksidhdbdbddddddddododododkdkdkdjdjdhddhhdvxbxbbxbxbxjdiegebeodhe

8 0
2 years ago
Mental state shift involves what?
Delvig [45]

Answer:

It involves a matter involving doubt, uncertainty, or difficulty that may be solved, problem ... getting into a frame of mind to be creative and solve problems.

Explanation:

Hope i am marked as brainliest answer

5 0
3 years ago
Other questions:
  • What are pixels that are the exact same between multiple frames called?
    15·1 answer
  • Do most facebook and twitter users access the platform from their personal computers?
    6·2 answers
  • Prevent a page break in the final paragraph of this document by keeping the lines together
    10·1 answer
  • A ____ by a design professional is used to determine the best system to provide the appropriate level and type of protection.
    6·1 answer
  • Which network component blocks status?
    9·1 answer
  • Why is data processing done in computer?​
    14·1 answer
  • can somebody please explain to me why I woke up today to see that all of my 40 answers where deleted ? like what I spent hours
    11·2 answers
  • A computer is assigned an IP address of 169.254.33.16. What can be said about the computer, based on the assigned address?
    9·1 answer
  • Read the introduction (paragraphs 1-3].
    7·1 answer
  • find_cow(name, cows) Given a name and a Python list of Cow objects, return the Cow object with the specified name. If no such Co
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!