Question

Calculate the area of a rectangle. -          Utilize at least three functions, “Get Input” – “Calculation” –...

Calculate the area of a rectangle.

-          Utilize at least three functions, “Get Input” – “Calculation” – “Show Output”

-          The “Get Input” function must use call-by-reference parameters to gather data

-          The program must ask the user if they would like to run it again

This is a C++ Project using call by reference. If possible please make it as simple as possible as i'm already very confused the way it is.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Dear Student ,

As per the requirement submitted above , kindly find the below solution.

Here a new C++ program with name "main.cpp" is created, which contains following code.

main.cpp :

//c++ program to calculate area of rectangle
#include <iostream> //header files
using namespace std;
//function prototype
void GetInput(int &l,int &b);
double Calculation(int l,int b);
void ShowOutput(int l,int b,double area);
int main() //main method
{
//declaring variables
int l,b;
double area;
char choice;//variable used to store user choice
bool flag=true;//variable to store user choice
while(flag){
//calling function to take input from user
GetInput(l,b);
area=Calculation(l,b);//calling funtion to calculate area
ShowOutput(l,b,area);//calling function to print area
//asking user his choice
cout<<"Would like to run it again (y/n): ";
cin>>choice;//reading choice
//checking choice
if(choice=='n')
{
flag=false;//set flag to false to break the loop
}
}
return 0;
}
//function to get input from user
void GetInput(int &l,int &b){
//asking user to enter length
cout<<"Enter Length :";
cin>>l;//reading length
//asking user to enter breadth
cout<<"Enter Breadth :";
cin>>b;//reading breadth   
}
//function to calculate area of rectangle
double Calculation(int l,int b){
return l*b;//return area of rectangle
}
//function to show area
void ShowOutput(int l,int b,double area){
//show area
cout<<"Area of rectangle with length "<<l<<" and breadth "<<b<<" is "<<area<<endl;
}

======================================================

Output : Compile and Run above program to get the screen as shown below

Screen 1 :main.cpp

NOTE : PLEASE FEEL FREE TO PROVIDE FEEDBACK ABOUT THE SOLUTION.

Add a comment
Know the answer?
Add Answer to:
Calculate the area of a rectangle. -          Utilize at least three functions, “Get Input” – “Calculation” –...
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
  • Python Programming Write a program that reads the dimension of a rectangle and prints its area....

    Python Programming Write a program that reads the dimension of a rectangle and prints its area. The program must handle errors such invalid input. If it encounters an error, it should ask the user to reenter the input. Sample run: Enter height:abc abc is not a vaid input. Try again. Enter height:10 Enter width:hello hello is not a vaid input. Try again. Enter width:world world is not a vaid input. Try again. Enter width:xyz xyz is not a vaid input....

  • Problem: Given information about a circle, rectangle and a triangle, calculate the area of the shape...

    Problem: Given information about a circle, rectangle and a triangle, calculate the area of the shape from the information supplied. Write pseudocode to solve this problem and write a Python program that asks the user to input the required information for a shape and then calculates the area of the shape. 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...

  • Complete the Rectangle Program Using the code given in rectangle.cpp, implement the functions that are called...

    Complete the Rectangle Program Using the code given in rectangle.cpp, implement the functions that are called in the main function to complete the program. You must not change any of the existing code in the file. You can only add functions and comments to the code. Here’s a sample run of how the program should behave: Enter rectangle length: -1 ← invalid value, ask user to re-enter Enter rectangle length: -2 ← invalid value Enter rectangle length: 0 ← invalid...

  • Python 3: Please follow the respective rubric for the following function definition. Rubric: Rectangle Shape You...

    Python 3: Please follow the respective rubric for the following function definition. Rubric: Rectangle Shape You should implement the following functions to print a rectangle shape. • print_rectangle(length, width, fillChar, hollow). This function will use draw_shape_line() function to print a rectangle shape with the given length and width, If the hollow is true, the shape will be hollow rectangle, otherwise a filled rectangle. This function must not interact with the user. For example, the call print_rectangle(5, 10, '*', False) should...

  • C++ Pr ogramming (CSC-115) Functions (pass by Reference) Programming project Using FUNCTIONS, write a C++ program...

    C++ Pr ogramming (CSC-115) Functions (pass by Reference) Programming project Using FUNCTIONS, write a C++ program that calculates the Area of a cirele, a square and a rectangle. Your program must prompt the user to select which area is to be calculated. Document your program. Apply the do while loop to repeat the program Apply the while loop for input validation. Apply the switch statements or the if/ else if statement to prompt the user for the area's selection. Based...

  • /4 Question An area of square, drea ofa rectangle and triangle can be calculated by using...

    /4 Question An area of square, drea ofa rectangle and triangle can be calculated by using the given formula: sqareaa (renww value from the functioi area is reciabgle-(retrn valwe from the function is area int) ceouatre -D-(return value fromtheneion e s double t and s s formula must be use when the values for the sides of the triangle are whether you want to calculate the area of square or a. b and c are the sides of the triangle...

  • Lab 7: Void and Value-Returning Functions Lab 7: Void and Value-returning functions             ...

    Lab 7: Void and Value-Returning Functions Lab 7: Void and Value-returning functions              Due date: 11/6/19 Problem: Write a C++ program that calculates the areas of a rectangle and of an ellipse.                    Area = base * height             Area = π * radius a * radius b Note: all images extracted from http://www.mathsisfun.com/area-calculation-tool.html ------------------------------------------------------------------------------------------------------------------------ Your task: implement in C++ the algorithm solution shown below. ------------------------------------------------------------------------------------------------------------------------ Part A (79...

  • A) One of the problems that have been discussed in the class is to write a simple C++ program to ...

    C++ programming question will upvote A) One of the problems that have been discussed in the class is to write a simple C++ program to determine the area and circumference of a circle of a given radius. In this lab you will be rewriting the program again but this time you will be writing some functions to take care of the user input and math. Specifically, your main function should look like the following int main //the radius of the...

  • A) One of the problems that have been discussed in the class is to write a...

    A) One of the problems that have been discussed in the class is to write a simple C++ program to determine the area and circumference of a circle of a given radius. In this lab you will be rewriting the program again but this time you will be writing some functions to take care of the user input and math. Specifically, your main function should look like the following: int main() { double radius; double area; double circumference; //the radius...

  • program language: python 3 Purpose: Solve a problem by writing multiple functions that perform different subtasks,...

    program language: python 3 Purpose: Solve a problem by writing multiple functions that perform different subtasks, and combining their use to solve a larger problem. Also to practice documenting functions. Degree of Difficulty: Moderate Your task is to compute the cost of renovating the flooring in a rectangular room. This includes replacing the carpet and and the baseboards. Your task is to write a Python program that calculates and the cost of the renovation. To accomplish this, you will need...

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