Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Topic:Function with parameter passed by value and passed by reference. Write a C+ single function rectangleAreaPerim(width, height, area, perimeter) that calculates both the area and

Topic:Function with parameter passed by value and passed by reference.

Write a C+ single function rectangleAreaPerim(width, height, area, perimeter) that calculates both the area and the perimeter of a rectangle given its width and height.

-Input to the functions are the width and height of the a rectange. Function cannot modify the input parameters.

-Output of the functions are the area, perimeter parameter, and a boolean return (success or a failure).

-This function returns true if both width and height are not negative (and thus calculation is meaningful). Otherwise function returns false and skips any calculation.

-The function rectangleAreaPerim(width, height, area, perimeter)should Not use any "cin" or "cout". Only main() will contain "cin" and "cout".

-Write the main() function to call the function rectangleAreaPerim() in a loop until user enters 0 0, that means using the concept of Sentinel in chapter 5.

The function could be used as followed:

double width = 1.2, height = 2.3, area, perimeter;

bool success = rectangleAreaPerim(width, height, area, perimeter);

if (success)

.

else

..

This does NOT mean you have to copy and paste the above code to your code exactly. It means that thefunction prototypemust match.

The result true of false of the function is used in main() to display the correct output: true means the calculation result is stored in area and perimeter, and false means that the input parameters width, height are invalid.

Write main() to accept multiple width, height inputs and print results. Function main() should have a loop that runs until user enters 0 and 0 for the width and height.

Write the function prototype before main() and write the full function definition after main().

Output sample

Calculate area and perimeter or rectangle.

Enter width and height separated by spaces: 1.2 3.4

Rectangle area is XXXXXX

Rectangle perimeter is XXXXXX

Enter width and height separated by spaces: 0 3.4

Rectangle area is XXXXXX

Rectangle perimeter is XXXXXX

Enter width and height separated by spaces: -1.2 3.4

Invalid input

Enter width and height separated by spaces: 1.2 -3.4

Invalid input

Enter width and height separated by spaces: 0 0

Goodbye

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Object Databases The Essentials

Authors: Mary E. S. Loomis

1st Edition

020156341X, 978-0201563412

Students also viewed these Databases questions

Question

Explain the different types of marketing strategies.

Answered: 1 week ago

Question

Explain product positioning.

Answered: 1 week ago

Question

Explain Industrial market segment.

Answered: 1 week ago