1 Calculate Areas calculateAreas.cpp contains several functions: calculateSquare, calculateCircle, calculateRight Triangle, printResult, and runProgram. runProgram is...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
1 Calculate Areas calculateAreas.cpp contains several functions: calculateSquare, calculateCircle, calculateRight Triangle, printResult, and runProgram. runProgram is a void function with no parameters. It is simply the function that the main function will call. printResult will take two arguments: the shape whose area is to be printed and the value of that shape's area. It will print the result of the given calculation. calculateAreas will display a menu to the user, read in the user's choices based on the menu, act on the user's choices, and (eventually) end the program when the user decides. calculateSquare will take the length of a square's side as an argument and return the area of a square with that given side length. The formula for the area of a square is A = s where A is area and s is the side length. Figure 1: Square of area 36 calculateCircle will take the length of a circle's radius as an argument and return the area of a circle with that given radius. The formula for the area of a circle is A = x where A is area, r is the radius length, and is defined as MPI in the cmath library. O Figure 2: Circle of area 36m calculateRight Triangle will take the length of a right triangle's base and the height of a right triangle and return the area of a right triangle with those given dimensions. The formula for the area of a right triangle is A = xbxh where b is the length of the base of the triangle and h is the height of the triangle. Figure 3: Right Triangle of area 18 1.1 Sample Run Sample Run ./calculate Areas.out Enter a shape calculate the area of (1: square, 2: circle, 3: right triangle, 4: quit): 1 Enter the length of the square's sides: 4 The area of the square is 16.00. Enter a shape calculate the area of (1: square, 2: circle, 3: right triangle, 4: quit): 2 Enter the radius of the circle: 2 The area of the circle is 12.57. Enter a shape calculate the area of (1: square, 2: circle, 3: right triangle, 4: quit): 3 Enter the length of the base and height of the triangle: 3 4 The area of the triangle is 6.00. Enter a shape calculate the area of (1: square, 2: circle, 3: right triangle, 4: quit): 4 #include "calculateAreas.h" #include #include // access to M PI constant #include #include #include using namespace std; int main(int argc, char* argv[]) { runProgram (); return 0; } void runProgram () { } } Author: Purpose: Functions to calculate areas of various geometric shapes void printResult( string shape, double area) { } return; void calculateAreas () { } return; } double calculateSquare ( double side) { return -1; return 0; double calculateCircle( double radius ) { return -1; double calculateRightTriangle( double base, double height ) { return -1; #ifndef CALCULATEAREAS H #define CALCULATEAREAS H #include using namespace std; Author: Purpose: Functions to calculate areas of various geometric shapes */ void runProgram (); void printResult( string shape, double area ); void calculate Areas (); double calculateSquare ( double side ); double calculateCircle( double radius ); double calculateRightTriangle ( double base double height ); #endif 1 Calculate Areas calculateAreas.cpp contains several functions: calculateSquare, calculateCircle, calculateRight Triangle, printResult, and runProgram. runProgram is a void function with no parameters. It is simply the function that the main function will call. printResult will take two arguments: the shape whose area is to be printed and the value of that shape's area. It will print the result of the given calculation. calculateAreas will display a menu to the user, read in the user's choices based on the menu, act on the user's choices, and (eventually) end the program when the user decides. calculateSquare will take the length of a square's side as an argument and return the area of a square with that given side length. The formula for the area of a square is A = s where A is area and s is the side length. Figure 1: Square of area 36 calculateCircle will take the length of a circle's radius as an argument and return the area of a circle with that given radius. The formula for the area of a circle is A = x where A is area, r is the radius length, and is defined as MPI in the cmath library. O Figure 2: Circle of area 36m calculateRight Triangle will take the length of a right triangle's base and the height of a right triangle and return the area of a right triangle with those given dimensions. The formula for the area of a right triangle is A = xbxh where b is the length of the base of the triangle and h is the height of the triangle. Figure 3: Right Triangle of area 18 1.1 Sample Run Sample Run ./calculate Areas.out Enter a shape calculate the area of (1: square, 2: circle, 3: right triangle, 4: quit): 1 Enter the length of the square's sides: 4 The area of the square is 16.00. Enter a shape calculate the area of (1: square, 2: circle, 3: right triangle, 4: quit): 2 Enter the radius of the circle: 2 The area of the circle is 12.57. Enter a shape calculate the area of (1: square, 2: circle, 3: right triangle, 4: quit): 3 Enter the length of the base and height of the triangle: 3 4 The area of the triangle is 6.00. Enter a shape calculate the area of (1: square, 2: circle, 3: right triangle, 4: quit): 4 #include "calculateAreas.h" #include #include // access to M PI constant #include #include #include using namespace std; int main(int argc, char* argv[]) { runProgram (); return 0; } void runProgram () { } } Author: Purpose: Functions to calculate areas of various geometric shapes void printResult( string shape, double area) { } return; void calculateAreas () { } return; } double calculateSquare ( double side) { return -1; return 0; double calculateCircle( double radius ) { return -1; double calculateRightTriangle( double base, double height ) { return -1; #ifndef CALCULATEAREAS H #define CALCULATEAREAS H #include using namespace std; Author: Purpose: Functions to calculate areas of various geometric shapes */ void runProgram (); void printResult( string shape, double area ); void calculate Areas (); double calculateSquare ( double side ); double calculateCircle( double radius ); double calculateRightTriangle ( double base double height ); #endif
Expert Answer:
Related Book For
Posted Date:
Students also viewed these algorithms questions
-
Let A, B be sets. Define: (a) the Cartesian product (A B) (b) the set of relations R between A and B (c) the identity relation A on the set A [3 marks] Suppose S, T are relations between A and B, and...
-
Bhushan Building Supplies entered into the following transactions. Prepare journal entries under the perpetual inventory system. June 1 Purchased merchandise on account from Brij Builders Materials,...
-
Create a professional presentation to serve as an executive overview detailing all the aspects of the plan. Remember that your presentation is the first item the team will look at, so try to capture...
-
The circuit shown in Fig. contains two batteries, each with an emf and an internal resistance, and two resistors. Find (a) The current in the circuit (magnitude and direction); (b) The terminal...
-
Figure P28.26 shows part of the rotation of an electric motor, during which the magnetic dipole moment of the loop points to the left or has some component to the left. If the entire rotation were...
-
The income statement for Rhino Company for the current year ended June 30 and balances of selected accounts at the beginning and the end of the year are as follows: Prepare the Cash Flows from...
-
11. A planet is revolving around the sun in an elliptical orbit. The mass of planet is m, angular momentum of planet about sun is L, and length of semi major axis is a and eccentricity are e. Time...
-
Hastings Company bases its variable overhead performance report on the actual direct labour- hours of the period. Data concerning the most recent year, which ended on December 31, are as follows:...
-
Consider two 7 per cent $100 government bonds that differ only in date of maturity. One matures in 2 years and the other matures in 4 years. Both bonds are selling at par and pay annual interest. ...
-
Explain why companies regard economic value added as a useful tool for assessing managerial performance.
-
Is tension in a group always undesirable?
-
What kinds of organisation are likely to use JIT production?
-
Explain what is meant by a transfer price.
-
Explain the meaning of overtrading.
-
Why social shoppers are susceptible to social commerce fraud? Provide a clear example (which may be fictional).
-
The Alert Company is a closely held investment-services group that has been very successful over the past five years, consistently providing most members of the top management group with 50% bonuses....
-
The thickness, in mm, of metal washers is measured on samples of size 5. The following table presents the means, ranges, and standard deviations for 20 consecutive samples. The means are = 2.505, =...
-
The lens equation says that if an object is placed at a distance p from a lens, and an image is formed at a distance q from the lens, then the focal length f satisfies the equation 1/ f = 1/p +1/q....
-
For the lettuce yield data, (page 494) it is thought that the yields from fertilizer A might have a larger variance than the yields from fertilizer B. a. Compute the sample variances s2A and s2B of...
-
Redo the preceding exercise, this time using the mathematics scores. Preceding Exercise Use the reading comprehension data in Exercise 6.18 to test the null hypothesis that the population mean of X...
-
Which of the following is a cash outflow? (a) Proceeds from borrowing. (b) Repayments of debt principal. (c) Payment for taxes. (d) Both (b) and (c).
-
Which of the following is not a cash inflow? (a) Proceeds from borrowing. (b) Returns on interest-earning assets. (c) Payment of dividends. (d) Returns on equity securities.
Study smarter with the SolutionInn App