Question: Lab 4 : Writing User Defined Functions Objective The objective of this lab is to write user defined functions to calculate the area of a

Lab 4: Writing User Defined Functions
Objective
The objective of this lab is to write user defined functions to calculate the area of a circle and the volume
of a sphere. Additionally, you will practice writing proper preconditions and postconditions.
Requirements
Write a program that asks a user to enter a radius value.
Implement two user defined functions, circleArea, and sphereVolume to calculate the area of
the circle and volume of the sphere using the given radius.
Use these equations for the calculations where r is the radius:
o Area of the Circle A= r2
o Volume of the Sphere V =4
3 r3 Hint: Be aware of the integer division problem.
The mathematical constant must be declared as a constant with the value of 3.14159.
Both functions take one parameter of double type and return a double result.
Write adequate preconditions and postconditions comments for both functions.
The functions prototypes must be declared above the main function and the definitions must be
placed below the main function.
Write a main function that calls the two user defined functions.
Example Output
Submission
Submit the source code file (.cpp) to the courses blackboard webpage.
Evaluation Criteria
Correct user defined functions implementations.
Correct choice of data types.
Writing proper preconditions and postconditions for all functions.
Correct calculations of the area and the volume.
Code readability and proper commenting.
Tips
Test your program with various inputs.
Use meaningful variable names and add comments to explain your code.
If you encounter any issues, refer to your textbook or ask for help from your instructor or peers.
Good Lab 4: Writing User Defined Functions
Objective
The objective of this lab is to write user defined functions to calculate the area of a circle and the volume of a sphere. Additionally, you will practice writing proper preconditions and postconditions.
Requirements
- Write a program that asks a user to enter a radius value.
- Implement two user defined functions, circleArea, and sphereVolume to calculate the area of the circle and volume of the sphere using the given radius.
- Use these equations for the calculations where \( r \) is the radius:
- Area of the Circle \( A=\pi r^{2}\)
- The mathematical constant \(\pi \) must be declared as a constant with the value of 3.14159.
- Both functions take one parameter of double type and return a double result.
- Write adequate preconditions and postconditions comments for both functions.
- The functions' prototypes must be declared above the main function and the definitions must be placed below the main function.
- Write a main function that calls the two user defined functions.
Example Output
Enter the radius: 5.45
Area of the circle: 93.3131
Volume of the sphere: 678.075
Submission
- Submit the source code file (.cpp) to the course's blackboard webpage.
Evaluation Criteria
- Correct user defined functions implementations.
- Correct choice of data types.
- Writing proper preconditions and postconditions for all functions.
- Correct calculations of the area and the volume.
- Code readability and proper commenting.
Tips
- Test your program with various inputs.
- Use meaningful variable names and add comments to explain your code.
- If you encounter any issues, refer to your textbook or ask for help from your instructor or peers.
Lab 4 : Writing User Defined Functions Objective

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!