Question

In: Computer Science

Instructions The included program found in main.cpp is designed to find the area of a rectangle,...

Instructions

The included program found in main.cpp is designed to find the area of a rectangle, the area of a circle, or the volume of a cylinder.

However:

  • the statements are in the incorrect order;
  • the function calls are incorrect;
  • the logical expression in the while loop is incorrect;
  • the function definitions are incorrect;
  • You may assume that the value of π = 3.14159.

Rewrite the program so that it works correctly. Your program must be properly indented. (Note that the program is menu driven and allows the user to run the program as long as the user wishes.)

Format your output with setprecision(2) to ensure the proper number of decimals for testing!

I have tried previous answers on site, but they are all incorrect and fail in the Mindtap cite used for the class.

Solutions

Expert Solution

=>Note wrote the c++ program and i used only float for inputs.

Code:-

#include<iostream>
#include <iomanip>
#include <stdlib.h>
using namespace std;
float pi=3.14159;
void rectangle(float height,float width){ // function rectangle takes height and width and area of the rectangle
float area=height*width;
std::cout<<"Area of rectangle: "<<std::setprecision(2)<< area<<endl;
}

void circle(float radius){ //function takes radius and prints area od cirlce
float area=pi*radius*radius;
std::cout<<"Area of circle is: "<< std::setprecision(2)<< area <<endl;


}
void cylinder(float height,float radius){ // takes radius and height of the cylinder and prints the volume of cylinder
double vol=pi*radius*radius*height;
std::cout<<"Volume of cylinder is: "<<std::setprecision(2)<<vol<<endl;

}
int main(){
while(true){
    float height;
    float width;
    float radius;
    int a;
    cout << "Enter 1-- rectangle\nEnter 2-- circle\nEnter 3--cylinder 4-- quit\n"; //switch is used to select the option
    cin >> a;
    switch(a){
      case 1:
            cout<<"Enter length and width:\n";
            cin>>height;
            cin>>width;
            rectangle(height,width);
            break;
          
      case 2:
              cout<<"Enter radius:\n";
              cin>>radius;
              circle(radius);
              break;
      case 3:
            cout<<"Enter radius and height:\n";
            cin>>height;
            cin>>radius;
            cylinder(height,radius);
            break;
      case 4:
              exit(0);
      default:
            cout<<"Invalid input";// prints if invalid input is given
            break;

    }
  
}                
}


Related Solutions

Find the maximum area of a rectangle inscribed in a triangle of area A.(NOTE: the triangle...
Find the maximum area of a rectangle inscribed in a triangle of area A.(NOTE: the triangle need not necessarily be a right angled triangle).
rite a program that will calculate the perimeter and area of a rectangle. Prompt the user...
rite a program that will calculate the perimeter and area of a rectangle. Prompt the user to input the length and width. Calculate the area as length * width. Calculate the perimeter as 2* length + 2* width. Display the area and perimeter. Please use a proper heading in a comment block (name, date, description of the program). Please use comments in your code. Run your program twice using different input. Copy the output and place it at the bottom...
The following program supposes to calculate the area of a rectangle and square. Then, produce the...
The following program supposes to calculate the area of a rectangle and square. Then, produce the following output. Area of Rectangle: 50 Unfortunately, the program has compile-time and run-time errors that prevent the program from running and producing the correct result. Using table 3.1 below, allocate the error(s) on each program line. 1 public class RectangleArea {   2   Public static void main() {   3     int width == 10; 4     int height = 5; 5     int recArea = width + height; 6      System.Out.print(Area of Rectangle:); 7      System.out.println(“recArea”)...
using C# Write a program named RectangleArea tocalculate the area of a rectangle with a...
using C# Write a program named RectangleArea to calculate the area of a rectangle with a length of 15.8 and a width of 7.9. The program should have two classes, one is theRectangleArea holding the Main(), and the other one is Rectangle. The Rectangleclass has three members: a property of length, a property of width, and a method with a name of CalArea() to calculate the area. You can invoke the auto-provided constructor or write a self-defined constructor to initialize...
The rectangle below is made up of 12 squares of the same size. Find the perimeter of the rectangle if the area of the rectangle is equal to 1728 square cm.
The rectangle below is made up of 12 squares of the same size. Find the perimeter of the rectangle if the area of the rectangle is equal to 1728 square cm.
Write a program to calculate the area of four shapes (Rectangle, triangle, circle and square). The...
Write a program to calculate the area of four shapes (Rectangle, triangle, circle and square). The program to present the user with a menu where one of the shapes can be selected. Based on the selection made, the user enters the proper input, the program validates the input (i.e all entries must be greater than zero). Once the input is entered and validated, the intended area is calculated and the entered information along with the area are displayed. Area of...
Find the length and width of a rectangle whose perimeter is 21 meters and whose area...
Find the length and width of a rectangle whose perimeter is 21 meters and whose area is 20 square meters. Assign variables to the unknown(s)... Form a system of equations... Solve the system and state your answer in the context of the problem, show all steps clearly, be sure to check your answers:
/* calculating area of a circle, calculating area of a rectangle, calculating area of a triangle,...
/* calculating area of a circle, calculating area of a rectangle, calculating area of a triangle, and quit. */ import java.util.Scanner; public class GeoCalculator {    public static void main(String arg[]) { int geoCalc; //number selection of user Scanner get = new Scanner(System.in); //display section. System.out.println("Geometry Calculator"); System.out.println("Please select from the following menu:"); System.out.println("1. Calculate the Area of a Cirlce."); System.out.println("2. Calculate the Area of a Rectangle."); System.out.println("3. Calculate the Area of a Triangle."); System.out.println("4. QUIT"); System.out.println("Please make a selection:...
The area of a particular rectangle is 12 times the area of a certain square, and...
The area of a particular rectangle is 12 times the area of a certain square, and the width of the rectangle is three times the length of a side of the square. The perimeter of the rectangle is 30 units greater than the perimeter of the square. Find the dimensiuons of both the rectangle and the square.
a function named area to calculate the area of a rectangle area = Length x width...
a function named area to calculate the area of a rectangle area = Length x width 2.a function named volume to calculate the volume of a sphere volume = 4/3 x 3.14 x radius x radius x radius 3.a function named volume to calculate the volume of a cuboid volume = Length x width x ht 4. Use a loop structure to calculate the sum of all odd numbers from 1 to 17 5) Use a loop structure to calculate...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT