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 : 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 r
o Volume of the Sphere V
r Hint: Be aware of the integer division problem.
The mathematical constant must be declared as a constant with the value of
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 : 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 Api r
The mathematical constant pi must be declared as a constant with the value of
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:
Area of the circle:
Volume of the sphere:
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.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
