Topic: A function with parameters passed by value and passed by reference  Do not use anything beyond Chapter 6 materials. Write a C++ Write a single function rectangleAreaPerim (width, height, area, perimeter) that calculates both the area and the perimeter of a rectangle given its width and height.   -Input parameters to the functions are the width and height of the rectangle. Function cannot modify the input parameters. -Output parameters of the function are the area, perimeter, and a boolean return (success or failure). -This function returns true if both width and height are not negative, and thus calculation is required. Otherwise the function returns false and skips all calculations. -The function rectangleAreaPerim(width, height,  area, perimeter) should Not use any "cin" or "cout". Only the main() function will contain "cin" and "cout". -The main() function calls the function rectangleAreaPerim() in a loop until the user enters 0 0. These are "Sentinel" values that stop the loop (chapter 5). If only one input is 0, the loop keeps going. This is a basic simple code without loop to test your function: int main() {    double width = 0, height = 0, area, perimeter;    bool success = rectangleAreaPerim(width, height, area, perimeter);    if (success)       cout << "Area is " << area << ". Perimeter is " << perimeter << endl;    else       cout << "Invalid input" << endl;   // Expected output is:   // Area is 0. Perimeter is 0 }   This does NOT mean you have to copy and paste the above code to your code for submission. It just gives you a guide of how to write the function prototype so that the test code above works correctly..   The result 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.   After using the simple test code above, write code in main() to accept multiple width, height inputs and print results by writing a Sentinel loop (chapter 5) that runs until the 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   This program calculates area and perimeter or rectangle.   Enter width and height separated by spaces, or enter 0 0 to stop:  1.2  3.4 Rectangle area is 4.08 Rectangle perimeter is 9.2   Enter width and height separated by spaces, or enter 0 0 to stop:  0  3.4 Rectangle area is 0 Rectangle perimeter is 6.8   Enter width and height separated by spaces, or enter 0 0 to stop:  -1.2  3.4 Invalid input   Enter width and height separated by spaces, or enter 0 0 to stop:  1.2  -3.4 Invalid  input   Enter width and height separated by spaces, or enter 0 0 to stop:  -1.2  -3.4 Invalid  input   Enter width and height separated by spaces, or enter 0 0 to stop: 0  0 Goodbye

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Topic: A function with parameters passed by value and passed by reference 

Do not use anything beyond Chapter 6 materials. Write a C++

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

 

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

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

-This function returns true if both width and height are not negative, and thus calculation is required. Otherwise the function returns false and skips all calculations.

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

-The main() function calls the function rectangleAreaPerim() in a loop until the user enters 0 0. These are "Sentinel" values that stop the loop (chapter 5). If only one input is 0, the loop keeps going.

This is a basic simple code without loop to test your function:

int main()

{

   double width = 0, height = 0, area, perimeter;

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

   if (success)

      cout << "Area is " << area << ". Perimeter is " << perimeter << endl;

   else

      cout << "Invalid input" << endl;

  // Expected output is:

  // Area is 0. Perimeter is 0

}

 

This does NOT mean you have to copy and paste the above code to your code for submission. It just gives you a guide of how to write the function prototype so that the test code above works correctly..

 

The result 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.

 

After using the simple test code above, write code in main() to accept multiple width, height inputs and print results by writing a Sentinel loop (chapter 5) that runs until the 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

 

This program calculates area and perimeter or rectangle.

 

Enter width and height separated by spaces, or enter 0 0 to stop:  1.2  3.4

Rectangle area is 4.08

Rectangle perimeter is 9.2

 

Enter width and height separated by spaces, or enter 0 0 to stop:  0  3.4

Rectangle area is 0

Rectangle perimeter is 6.8

 

Enter width and height separated by spaces, or enter 0 0 to stop:  -1.2  3.4

Invalid input

 

Enter width and height separated by spaces, or enter 0 0 to stop:  1.2  -3.4

Invalid  input

 

Enter width and height separated by spaces, or enter 0 0 to stop:  -1.2  -3.4

Invalid  input

 

Enter width and height separated by spaces, or enter 0 0 to stop: 0  0

Goodbye




Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Knowledge Booster
Types of Function
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.
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education