Question

The statement in the following program is in the incorrect order. Rearrange the statements so that...

The statement in the following program is in the incorrect order. Rearrange the statements so that they prompt the user to input the shape type (rectangle, circle, or cylinder) and the appropriate dimension of the shape. The program then outputs the following information about the shape: For a rectangle, it outputs the area and perimeter, for a circle, it outputs the area and circumference; and for a cylinder, it output the volume and surface area. After rearranging the statements, your program should be properly indented. Please make sure that the output is two decimals points.


using namespace std;

#include <iostream>

int main()
{
string shape;
double height;

#include <string>

cout << "Enter the shape type: (rectangle, circle, cylinder) ";
cin >> shape;
cout << end1;

if (shape == "rectangle")
{
cout << "Area of the circle = "
<< PI * pow(radius, 2.0) << end1;

cout << "Circumference of the circle: "
<< 2 * PI * radius << end1;

cout << "Enter the height of the cylinder: ";
cin >> height;
cout << end1;

cout << "Enter the width of the rectangle; ";
cin >> width;
cout << end1;

cout << "Perimeter of the rectangle = "
<< 2 * (length + width) << end1;
double width;
}

cout << "Surface area of the cylinder: "
<< 2 * PI * radius * height + 2 * PI * pow(radius, 2.0)
<< end1;
}
else if (shape == "circle")
{
cout << "Enter the radius of the circle; ';
cin >> radius;
cout << end1;

cout << "Volume of the cylinder = "
<< PI * pow(radius, 2.0)* height << end1;
double length;
}
return 0;
else if (shape == "cyclinder")
{
double radius;

cout << "Enter the length of the rectangle: ";
cin >> length;
cout << end1;

#include <iomanip>


cout << "Enter the radius of the base of the cylinder: ";
cin >> radius;
cout << end1;

const double PI = 3.1416;
cout << "Area of the rectangle = "
<< length * width << end1;
else
cout << "The program does not handle " << shape << end1;
cout << fixed << showpoint << setprecision(2) ;

#include <cmath>
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Corrected and Indented Code-

#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>

using namespace std;

int main()
{
   string shape;
   double height;
   double radius;
   double width;
   double length;
   const double PI = 3.1416;
  
   cout << fixed << showpoint << setprecision(2);
  
   cout<<"Enter the shape type: (rectangle, circle, cylinder)";
   cout << endl;
   cin>>shape;
  
   if (shape == "rectangle")
   {
       cout << "Enter the length of the rectangle: ";
       cin >> length;
       cout << endl;
       cout << "Enter the width of the rectangle: ";
       cin >> width;
       cout << endl;
       cout << "Area of the rectangle = " << length * width << endl;
       cout << "Perimeter of the rectangle = " << 2 * (length + width) << endl;  
  
   }
  
   else if (shape == "circle")
   {
       cout << "Enter the radius of the circle: ";
       cin >> radius;
       cout << endl;
       cout << "Area of the circle = " << PI * pow(radius, 2.0) << endl;
       cout << "Circumference of the circle: " << 2 * PI * radius << endl;  
   }
  
   else if (shape=="cylinder")
   {
      
       cout << "Enter the radius of the base of the cylinder: ";
       cin >> radius;
       cout << endl;
       cout << "Enter the height of the cylinder: ";
       cin >> height;
       cout << endl;
       cout << "Surface area of the cylinder: "<< 2 * PI * radius * height + 2 * PI * pow(radius, 2.0)<< endl;
       cout << "Volume of the cylinder = "<< PI * pow(radius, 2.0)* height << endl;
                  
   }
  
   else
   {
       cout << "The program does not handle " << shape << endl;
      
   }
  
   return 0;
}

Corrected and Indented Code Snippet-

Output of the Corrected and Indented Code-

Add a comment
Know the answer?
Add Answer to:
The statement in the following program is in the incorrect order. Rearrange the statements so that...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Consider the following program in which the statements are in the incorrect order. Rearrange the statements...

    Consider the following program in which the statements are in the incorrect order. Rearrange the statements so that the program prompts the user to input the height and the radius of the base of a cylinder and outputs the volume and surface area of the cylinder. Formant the output to two decimal places. #include <iomanip> #include <cmath> int main () {} double height; cout << ”Volume of the cylinder = “ <<PI * pow(radius, 2.0) * height << endl; cout...

  • PLEASE TYPE OUT IN TEXT (please no pdf or writing) C++ CODE Consider the following program...

    PLEASE TYPE OUT IN TEXT (please no pdf or writing) C++ CODE Consider the following program in which the statements are in the incorrect order. Rearrange the statements in the following order so that the program prompts the user to input: The height of the base of a cylinder The radius of the base of a cylinder The program then outputs (in order): The volume of the cylinder. The surface area of the cylinder Format the output to two decimal...

  • Write a C program named assignment04.cpp that will ask for and read in a float for...

    Write a C program named assignment04.cpp that will ask for and read in a float for a radius ask for and read in a float for the height each of the following functions will calculate some property of a shape (area, volume, circumference, etc) The functions will accept one or two parameters (radius and/or height) and return the proper calculation. There is no input/output (cin or cout) in the function – just the calculation write the following functions float areaCircle(float...

  • Using Python Write the following well-documented (commented) program. Create a class called Shape that has a...

    Using Python Write the following well-documented (commented) program. Create a class called Shape that has a method for printing the area and the perimeter. Create three classes (Square, Rectangle, and Circle) which inherit from it. Square will have one instance variable for the length. Rectangle will have two instance variables for the width and height. Circle will have one instance variable for the radius. The three classes will have methods for computing the area and perimeter of its corresponding shape....

  • In C++ Amanda and Tyler opened a business that specializes in shipping liquids, such as milk,...

    In C++ Amanda and Tyler opened a business that specializes in shipping liquids, such as milk, juice, and water, in cylindrical containers. The shipping charges depend on the amount of the liquid in the container. (For simplicity, you may assume that the container is filled to the top.) They also provide the option to paint the outside of the container for a reasonable amount. Write a program that does the following: Prompts the user to input the dimensions (in feet)...

  • write a completed program (included the main) for the Q: add an equals method to each...

    write a completed program (included the main) for the Q: add an equals method to each of the Rectangle circle and triangle classes introduced in this chapter. two shapes are considered equal if their fields have equivalent values. based on public class Circle implements Shape f private double radius; // Constructs a new circle with the given radius. public Circle (double radius) f this.radius - radius; // Returns the area of this circle. public double getArea) return Math.PI *radius *...

  • I wrote a program which computes the area and perimeter of a square, circle, or rectangle. As you will see in my main function, there is a for loop in which the user is supposed to be able repeat the...

    I wrote a program which computes the area and perimeter of a square, circle, or rectangle. As you will see in my main function, there is a for loop in which the user is supposed to be able repeat the program until they enter "q" to quit. However, my program runs through one time, the prompt appears again, but then it terminates before the user is allowed to respond to the prompt again. I'm not able to debug why this...

  • I am trying to write a Geometry.java program but Dr.Java is giving me errors and I...

    I am trying to write a Geometry.java program but Dr.Java is giving me errors and I dont know what I am doing wrong. import java.util.Scanner; /** This program demonstrates static methods */ public class Geometry { public static void main(String[] args) { int choice; // The user's choice double value = 0; // The method's return value char letter; // The user's Y or N decision double radius; // The radius of the circle double length; // The length of...

  • C++ program. int main() {    Rectangle box;     // Define an instance of the Rectangle class...

    C++ program. int main() {    Rectangle box;     // Define an instance of the Rectangle class    double rectWidth; // Local variable for width    double rectLength; // Local variable for length    string rectColor;    // Get the rectangle's width and length from the user.    cout << "This program will calculate the area of a\n";    cout << "rectangle. What is the width? ";    cin >> rectWidth;    cout << "What is the length? ";    cin >>...

  • C++ problem 11-3 Chapter 10 defined the class circleType to implement the basic properties of a...

    C++ problem 11-3 Chapter 10 defined the class circleType to implement the basic properties of a circle. (Add the function print to this class to output the radius, area, and circumference of a circle.) Now every cylinder has a base and height, where the base is a circle. Design a class cylinderType that can capture the properties of a cylinder and perform the usual operations on the cylinder. Derive this class from the class circleType designed in Chapter 10. Some...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT