Question

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 areas selection. Based on your selection each choice enables the user to calculate a different area. Late assignments will not be accepted. Your formatted output must include the input info as well as the results in a readable format. Finding the Area of a Circle How to find the area of a circle: The area of a circle can be found by multiplying pi (which is equal to 3.14) by the square of the radius · If a circle has a radius of 4, its area is 3.14.4.4-50.24 If you know the diameter, the radius is 1/2 as large. Calculating the Area of a Square How to find the area of a square: The area of a square can be found by multiplying the base times itself. This is similar to the area of a rectangle, but the base is the same length as the height. .If a square has a base of length 6 inches its area is 6*6-36 square inches Calculating the Area of a Rectangle How to find the area of a rectangle: The area of a rectangle can be found by multiplying the base times the height. If a rectangle has a base of length 6 inches and a height of 4 inches, its area is 64-24 square inches. .
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Please find the code below:

#include<iostream> // used for cout and cin

using namespace std;

void calcAreaCircle(float&,float&); // prototype of all the 3 functions

void calcAreaSquare(float&,float&); // variables are passed as reference

void calcAreaRectangle(float&,float&,float&);

int main() // main()

{

float areaCircle,areaSquare,areaRectangle; // variables to store the area of circle, square and rectangle

float cRadius; // variable to store the radius of circle

float sBase; // variable to store the base of square

float rHeight,rWidth; // variable to store height and width of rectangle

int choice; // variable to store the user's choice

do // using a do while loop for user's option

{

cout<<endl<<"Please select:"; // provide the menu to the user

cout<<endl<<"1. Area of Circle";

cout<<endl<<"2. Area of Square";

cout<<endl<<"3. Area of rectangle";

cout<<endl<<"0. Quit";

cout<<endl<<"Please enter your choice:";

cin>>choice; // Ask user for choice, take user's choice in variable choice

switch(choice) // using switch case statements to evaluate choice

{

case 1: // if choice is 1, ask user to enter radius

cout<<endl<<"Enter the radius of the circle:";

cin>>cRadius;

while(cRadius<=0) // using a while loop to evaluate if the radius is negative

{ // keep asking user for input till user provides valid data

cout<<endl<<"Please enter a positive value for radius";

cout<<endl<<"Enter the radius of circle:";

cin>>cRadius;

}

calcAreaCircle(cRadius,areaCircle); // call calAreaCircle() and pass radius and area of circle as parameters

cout<<endl<<"The area of circle is: "<<areaCircle; // print the area of circle

break;

case 2:

cout<<endl<<"Enter the base of the square:"; // if choice is 2, ask user to enter the base of square

cin>>sBase;

while(sBase<=0) // if base is negative, keep asking user for base till user provides valid input

{

cout<<endl<<"Please enter a positive value for base";

cout<<endl<<"Enter the base of the square:";

cin>>sBase;

}

calcAreaSquare(sBase,areaSquare); // call calcAreaSquare and pass base and area of square as parameter

cout<<endl<<"The area of square is: "<<areaSquare; // print the area of square

break;

case 3:

cout<<endl<<"Enter the height of the rectangle:"; // if choice is 3, ask user for height and base of rectangle

cin>>rHeight;

cout<<endl<<"Enter the base of the rectangle:";

cin>>rWidth;

while(rHeight<=0) // if height is negative, keep asking user for height till user provides valid input

{

cout<<endl<<"Please enter a positive value for height";

cout<<endl<<"Enter the height of the rectangle:";

cin>>rHeight;

}

while(rWidth<=0) // if base is negative, keep asking user for base till user provides valid input

{

cout<<endl<<"Please enter a positive value for base";

cout<<endl<<"Enter the base of the rectangle:";

cin>>rWidth;

}

calcAreaRectangle(rHeight,rWidth,areaRectangle); // call calcAreaRectangle() and pass height width and area of rectangle

cout<<endl<<"The area of rectangle is: "<<areaRectangle;

break;

case 0: // if case is 0, print good bye

cout<<endl<<"Good Bye!";

break;

default: // if any other value is used as choice, print invalid choice

cout<<endl<<"Invalid choice";

}

}while(choice!=0); // continue looping till user enters 0

return 0;

}

void calcAreaCircle(float& cRadius,float& areaCircle) // definition of calcAreaCircle()

{ // it takes the references of cRadius and areaCircle variables as parameters

float pi=3.14; // declare and initialize pi to 3.14

areaCircle=pi*cRadius*cRadius; // calculate area as pi*radius*radius

}

void calcAreaSquare(float& sBase,float& areaSquare) // definition of calcAreaSquare()

{ // it takes references of sBase and areaSquare as parameters

areaSquare=sBase*sBase; // calculate area as base * base

}

void calcAreaRectangle(float& rHeight,float& rWidth,float& areaRectangle) // definition of calcAreaRectangle()

{ // it takes references of rHeight,rWidth and areaRectangle as parameters

areaRectangle=rHeight*rWidth; // calculate area as height * width

}

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

Output:

lease select: . Area of Circle . Area of Square Area of rectangle lease enter your choice :1 nter the radius of the circle :4 . Quit he area of circle is 50.24 lease select: . Area of Circle . Area of Square Area of rectangle lease enter your choice:2 nter the base of the squae:b . Quit he area of square is: 36 lease select: . Area of Circle . Area of Square Area of rectangle lease enter your choice :3 nter the height of the rectangle :6 nter the base of the rectangle :4 . Quit he area of rectangle is 24 lease select: . Area of Circle . Area of Square Area of rectangle . Quit lease enter your choice :5 Invalid choice lease select: . Area of Circle . Area of Square Area of rectangle . Quit lease enter your choice :0 ood Bye! rocess exited after 24.57 seconds with return value ress any key to continue -. .

Add a comment
Know the answer?
Add Answer to:
C++ Pr ogramming (CSC-115) Functions (pass by Reference) Programming project Using FUNCTIONS, write a C++ program...
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
  • Using Python Write the following well-documented (commented) program. Create a class called Shape that has a...

    Using Python Write the following well-documented (commented) program. Create a class called Shape that has a method for printing the area and the perimeter. Create three classes (Square, Rectangle, and Circle) which inherit from it. Square will have one instance variable for the length. Rectangle will have two instance variables for the width and height. Circle will have one instance variable for the radius. The three classes will have methods for computing the area and perimeter of its corresponding shape....

  • Java only please Write a program that displays the following menu: Geometry Calculator 1.       Calculate the...

    Java only please Write a program that displays the following menu: Geometry Calculator 1.       Calculate the Area of a Circle 2.       Calculate the Area of a Triangle 3.     Calculate the Area of a Rectangle 4.       Quit Enter your choice (1-4): If the user enters 1, the program should ask for the radius of the circle and then display its area. Use the formula:      area = ∏r2    Use 3.14159 for ∏. If the user enters 2 the program should ask for...

  • C++ programming For this assignment, write a program that will act as a geometry calculator. The...

    C++ programming For this assignment, write a program that will act as a geometry calculator. The program will be menu-driven and should continue to execute as long as the user wants to continue. Basic Program Logic The program should start by displaying a menu similar to the following: Geometry Calculator 1. Calculate the area of a circle 2. Calculate the area of a triangle 3. Quit Enter your choice(1-3): and get the user's choice as an integer. After the choice...

  • Menu-driven programs will display the menu options to the user and then prompt them for a...

    Menu-driven programs will display the menu options to the user and then prompt them for a menu choice. This program will display the following menu in the following format: Calculator Options: Calculate the area of a circle Calculate the area of a rectangle Calculate the area of a triangle Calculate the area of a trapezoid Calculate the area of a sphere Exit Enter your choice (1-6) Once the user enters a choice for the menu, the program should use a...

  • Geometric calclator use python to do this program. Write a program that displays the following menu:...

    Geometric calclator use python to do this program. Write a program that displays the following menu: 1. Calculate the area of circle 2. calculate the area of rectangle 3. calculate the area of triangle 4. Quit Enter your choice (1-4). if the user enters 1, your program should ask for the radius of the circle and then display its area. Use the formula to calculate the circle's area: Area = pi*r^2 Use 3.14149 for Pi and the radius of the...

  • Using C++, Write a program that will provide the user a menu from which the user...

    Using C++, Write a program that will provide the user a menu from which the user may select to calculate the area of one of four geometric shapes: a circle, a rectangle, a triangle, and a trapezoid. You should use the most appropriate SWITCH block for this program. The user will input all data needed to calculate the area. The program should output all data input by the user, the calculated area, and the geometric shape selected. Run this program...

  • In Java Exercise #2: (Java) Design and implement a program (name it ComputeAreas) that defines four...

    In Java Exercise #2: (Java) Design and implement a program (name it ComputeAreas) that defines four methods as follows: Method squareArea (double side) returns the area of a square. Method rectangleArea (double width, double length) returns the area of a rectangle. Method circleArea (double radius) returns the area of a circle. Method triangleArea (double base, double height) returns the area of a triangle. In the main method, test all methods with different input value read from the user. Document your...

  • (PYTHON) Write a program that displays the following menu:. , Write Algorithm for Code Geometry Calculator...

    (PYTHON) Write a program that displays the following menu:. , Write Algorithm for Code 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 - 4): If the user enters 1, the program should ask for the radius of the circle and then display its area. If the user enters 2, the program should ask for the length and width of...

  • 1. Write a program that determines the area and perimeter of a square. Your program should...

    1. Write a program that determines the area and perimeter of a square. Your program should accept the appropriate measurement of the square as input from the user and display the result to the screen. Area of Square = L (squared) Perimeter of Square = 4 * L 2.  Write a program that determines the area and circumference of a circle. Your program should accept the appropriate measurement of the circle as input from the user and display the result to...

  • Please use C++ and output have to look like that Create a menu driven C++ program...

    Please use C++ and output have to look like that Create a menu driven C++ program with functions. There must be four functions, calculating the size of area of circle, rectangle, triangle, and parallelogram. You are required to create those four functions and invoke them from the main program in order to reccive any credit. Please Submit: . A flowchart of your program with equations and expected results. 4 points) 2. Printout of your C++program with a heading comment, also...

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