Question

3. Write an that a user a rectangle. It should output the area and perimeter of the rectangle. Use methods for entering the values, performing the computations, and displaying the results. Results should be formatted with one position to the right of the decimal and printed number aligned in a tabular display. application allows to input thè heignt and wiaul I need help with
0 0
Add a comment Improve this question Transcribed image text
Answer #1

// program to display area and perimeter of rectange

#include <stdio.h>

void getInput(float* height, float* width)
{
   printf ("Enter the height: ");
   scanf ("%f", height);
   printf ("Enter the width: ");
   scanf ("%f", width);
}

float getArea(float h, float w)
{
   float area = h * w;
   return area;
}

float getPerimeter(float h, float w)
{
   float perimter = (2* h) + (2 * w);
   return perimter;
}

void displayResult(float h, float w, float area, float perimter)
{
   printf("Height\tWidth\tArea\tPerimeter\n");
   printf ("%.1f\t%.1f\t%.1f\t%.1f\t\n", h, w, area, perimter);

}

int main()
{
   float height, width, area, perimter;

   getInput(&height, &width);

   area = getArea(height, width);
   perimter = getPerimeter(height, width);
   displayResult(height, width, area, perimter);

   return 0;
}

Enter the height 4.33 Enter the width: 7.81 Height Width Area 4.3 Perimeter 24.3 7.8 33.8

As per the question, one decimal placed is showed in the output.

The code is in C programming language.

Add a comment
Know the answer?
Add Answer to:
I need help with Write an application that allows user to input the height and width...
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
  • ****Here is the assignment **** Purpose: To write an Object-Oriented application that creates a Java class...

    ****Here is the assignment **** Purpose: To write an Object-Oriented application that creates a Java class with several instance variables, a constructor to initialize the instance variables, several methods to access and update the instance variables’ values, along with other methods to perform calculations. Also, write a test class that instantiates the first class and tests the class’s constructor and methods. Details: Create a class called Rectangle containing the following: Two instance variables, An instance variable of type double used...

  • Write a short application that computes the perimeter of a rectangle. It should allow the user...

    Write a short application that computes the perimeter of a rectangle. It should allow the user to input the length and width of the rectangle as a double. Java language.

  • This exercise guides you through the process of converting an Area and Perimeter application from a...

    This exercise guides you through the process of converting an Area and Perimeter application from a procedural application to an object-oriented application. Create and use an object 1. Open the project named ch04_ex2_Area and Perimeter that’s stored in the ex_starts folder. Then, review the code for the Main class. 2. Create a class named Rectangle and store it in the murach.rectangle package. 3. In the Rectangle class, add instance variables for length and width. The, code the get and set...

  • ******** IN JAVA ********* I have a program that I need help debugging. This program should...

    ******** IN JAVA ********* I have a program that I need help debugging. This program should ask a user to input 3 dimensions of a rectangular block (length, width, and height), and then perform a volume and surface area calculation and display the results of both. It should only be done using local variables via methods and should have 4 methods: getInput, volBlock, saBlock, and display (should be void). I have most of it written here: import java.util.*; public class...

  • 1. Write a program that determines the area and perimeter of a square. Your program should...

    1. Write a program that determines the area and perimeter of a square. Your program should accept the appropriate measurement of the square as input from the user and display the result to the screen. Area of Square = L (squared) Perimeter of Square = 4 * L 2.  Write a program that determines the area and circumference of a circle. Your program should accept the appropriate measurement of the circle as input from the user and display the result to...

  • Write a C# application that implements a class ‘Prism’ with the following members. Five private data...

    Write a C# application that implements a class ‘Prism’ with the following members. Five private data members ‘length’, ‘height’, ‘width’, ‘Volume’ and ‘Area’ of double data type. Implement the constructor Prism( ) to accept the length, height, and width of the rectangular prism from the user. Implement three methods, Vol(), Area(), and Result() Vol() – to calculate the volume of the prism using the formulae Volume= length ×height ×width Area() – to calculate the surface area of the prism using...

  • (PYTHON) Write a program that displays the following menu:. , Write Algorithm for Code Geometry Calculator...

    (PYTHON) Write a program that displays the following menu:. , Write Algorithm for Code Geometry Calculator 1. Calculate the Area of a Circle 2. Calculate the Area of a Rectangle 3. Calculate the Area of a Triangle 4. Quit Enter your choice (1 - 4): If the user enters 1, the program should ask for the radius of the circle and then display its area. If the user enters 2, the program should ask for the length and width of...

  • Hello Guys. I need help with this its in java In this project you will implement...

    Hello Guys. I need help with this its in java In this project you will implement a Java program that will print several shapes and patterns according to uses input. This program will allow the use to select the type (say, rectangle, triangle, or diamond), the size and the fill character for a shape. All operations will be performed based on the user input which will respond to a dynamic menu that will be presented. Specifically, the menu will guide...

  • (1) Prompt the user to input a wall's height and width. Calculate and output the wall's...

    (1) Prompt the user to input a wall's height and width. Calculate and output the wall's area. (Submit for 2 points). Enter wall height (feet): 12 Enter wall width (feet): 15 Wall area: 180 square feet (2) Extend to also calculate and output the amount of paint in gallons needed to paint the wall. Assume a gallon of paint covers 350 square feet. Store this value using a const double variable. (Submit for 2 points, so 4 points total). Enter...

  • Using C++, Write a program that will provide the user a menu from which the user...

    Using C++, Write a program that will provide the user a menu from which the user may select to calculate the area of one of four geometric shapes: a circle, a rectangle, a triangle, and a trapezoid. You should use the most appropriate SWITCH block for this program. The user will input all data needed to calculate the area. The program should output all data input by the user, the calculated area, and the geometric shape selected. Run this program...

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