Question
using C++, format withusing namespacestd; B. Building an Area Calculator Write a program that prompts the user for three 3 integers: side (of a square),
using C++, format withusing namespacestd;
B. Building an Area Calculator
Write a program that prompts the user for three 3 integers: side (of a square), length and width (of a rectangle) and store them in respective variables.
1. A function with int as a return datatype:
Write a function called calcArea() that accepts an integer representing the length of the side of a square as a parameter and calculates, then returns the area of that square. This function should not have any print statements.
In your main() function print the area returned from this function without storing the returned value in a variable.
2. A function with bool as a return datatype:
Write a function called isLargeArea() that accepts an integer representing the length of the side of a square as a parameter and calculates the area of that square. This function returns true if the calculated area is greater than 20. The function should not have any print statements.
In your main() function print the statement The area is larger than 20 if the value returned by the function is true, or The area is less than or equal 20 otherwise. Try to not use (== true) in your if statement, how would this work? Why? Can you rename this function in this program as calcArea(), why (not)?
3. An overloaded function:
Write a function called calcArea() that finds the area of a rectangle where the length and width entered by the user are passed to the function. This function should return an integer representing the calculated area.
In your main() function print the area returned from this function after storing the returned value in a local variable.
4. Reference variables:
Write a function called calcAreaRef() that finds the area of a square. This function should not return any value. Without using global variables, the main function should still have access to the calculated area.
In your main() function print the area calculated in this function.
5. Static variables:
Write a function called calcArea() that finds the area of a rectangle. This function should return an integer representing the calculated area. It should not accept any parameters.
In your main() function, call the function 5 times through a for loop to print the area of the 5 rectangles. It should find the area of 5 rectangles whose lengths and widths are multiples of 6 and 4 respectively. The output should look like this:
Rectangle Area 1 24
2 96
3 216
4 384
5 600
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started