In this question we are going to calculate the surface area of a square and a circle as they change sizes. To get started: The purpose of this question (and of this assignment in general) is to practice writing and using functions with return values. So before you do anything else, you should write the following two functions: • circle_area(): This function should have a single parameter, d, which is the diameter of a circle. I should calculate and return the area of the circle with diameter d. Hint: Processing has a built-in variable called PI. It might help. • square_area(): This function should have a single parameter, w, which is the width of a square. I should calculate and return the area of the square. Once you have completed the two functions above, you should use them to build the following interactive program. While writing the rest of you program, do not ever duplicate the area formulas anywhere else Whenever you need to get the area of a shape, call one of these functions and use its return value. . When the program starts: Display a small circle and small square on the canvas. They should be different colors from each other, but can otherwise be of any color. If you make them look like cookies that's even better. . When the 'c' key is pressed: The diameter of the circle should increase by a small amount. . When the 's' key is pressed: The width of the square should increase by a small amount. . At all times: Display the current area of both shapes somewhere on the canvas. Call your functions that you wrote above to get the area, and simply display the value that they return.

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter6: Modularity Using Functions
Section6.3: Returning Multiple Value
Problem 4E
icon
Related questions
Question
In this question we are going to calculate the surface area of a square and a circle as they change sizes.
To get started: The purpose of this question (and of this assignment in general) is to practice writing and
using functions with return values. So before you do anything else, you should write the following two
functions:
circle_area(): This function should have a single parameter, d, which is the diameter of a circle. It
should calculate and return the area of the circle with diameter d. Hint: Processing has a built-in
variable called PI. It might help.
square_area(): This function should have a single parameter, w, which is the width of a square. It
should calculate and return the area of the square.
Once you have completed the two functions above, you should use them to build the following interactive
program. While writing the rest of you program, do not ever duplicate the area formulas anywhere else!
Whenever you need to get the area of a shape, call one of these functions and use its return value.
. When the program starts: Display a small circle and small square on the canvas. They should be
different colors from each other, but can otherwise be of any color. If you make them look like cookies,
that's even better.
When the 'c' key is pressed: The diameter of the circle should increase by a small amount.
When the 's' key is pressed: The width of the square should increase by a small amount.
. At all times: Display the current area of both shapes somewhere on the canvas. Call your functions
that you wrote above to get the area, and simply display the value that they return.
Circle Area:
706.858
Square Area:
900
Circle Area:
11309.733
Square Area:
4900
Transcribed Image Text:In this question we are going to calculate the surface area of a square and a circle as they change sizes. To get started: The purpose of this question (and of this assignment in general) is to practice writing and using functions with return values. So before you do anything else, you should write the following two functions: circle_area(): This function should have a single parameter, d, which is the diameter of a circle. It should calculate and return the area of the circle with diameter d. Hint: Processing has a built-in variable called PI. It might help. square_area(): This function should have a single parameter, w, which is the width of a square. It should calculate and return the area of the square. Once you have completed the two functions above, you should use them to build the following interactive program. While writing the rest of you program, do not ever duplicate the area formulas anywhere else! Whenever you need to get the area of a shape, call one of these functions and use its return value. . When the program starts: Display a small circle and small square on the canvas. They should be different colors from each other, but can otherwise be of any color. If you make them look like cookies, that's even better. When the 'c' key is pressed: The diameter of the circle should increase by a small amount. When the 's' key is pressed: The width of the square should increase by a small amount. . At all times: Display the current area of both shapes somewhere on the canvas. Call your functions that you wrote above to get the area, and simply display the value that they return. Circle Area: 706.858 Square Area: 900 Circle Area: 11309.733 Square Area: 4900
Expert Solution
steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Concept of Parenthesis
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning