Question
Please Solve below problem in C++ Create a new C++ project with the title Homework 2 and using Console Application similar to the previous homework.
Please Solve below problem in C++
Create a new C++ project with the title Homework 2 and using Console Application similar to the previous homework.
If any instruction is not followed, there will be some point deduction.
A. Add the "#include" directive for iostream and for the string class at the top of your program.
B. Add comments with description at the top of the code.
/*
Homework 2
Author: _______
Purpose: _______
*/
All the following code should be put inside the main() function brace.
C. Define the following variables to hold the sphere data:
- Variable radius: type double
- Variable surfaceArea: type double
- Variable volume: type double
D. Define a named constant with the name PI and initialize it with the exact value 3.14159. Use this constant for later calculation in following steps.
Do not use the C++ M_PI constant in cmath.
E. Define a named constant of string type AREA_STR that contains exactly the following text (no extra space).
"Surface area of the sphere with radius"
Define a named constant of string type VOLUME_STR that contains exactly the following text (no extra space).
"Volume of the sphere with radius"
F. Display the literal string "This program calculates the surface area and volume of a sphere." to the output console.
You can use multiplication to calculate the square and cube of a number
G. Provide code to ask the user to enter the sphere radius, then read the input into the radius variable.
Enter the sphere radius: XXX
H. Provide a line of code to calculate the sphere surface area using the radius variable and PI, and store the result in the surfaceArea variable.
I. Provide a line of code to calculate the sphere volume using the radius variable and PI, and store the result in the volume variable.
J. Provide a line of code to display this text to output console:
Surface area of the sphere with radius XX is YY.
using the named constant AREA_STR, radius and the surfaceArea variable. The value XX comes from the radius variable. The value YY comes from the surfaceArea variable.
You can add extra space characters to the output line, but you must use the AREA_STR constant to avoid duplicating text.
K. Provide code to display an output line
Volume of the sphere with radius XX is YY.
using the named constant VOLUME_STR, the radius variable and the volume variable. The value XX comes from the radius variable. The value YY comes from the volume variable.
You can add extra space characters to the output line, but you must use the VOLUME_STR constant to avoid duplicating text.
Put "return 0;" at the end of the main function before the closing brace.
L. Build and test your code
The following are some expected output with different user inputs. Note that each program run only calculates results for one radius input.
Run 1
Run 2:
Run 3:
Notice the spaces and dots in the text output.
If your output is not correct, it can only mean that the previous steps are not done right. Then review and fix your code.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started