Write a program that will:
• Display a program description to the user before asking for any input
• Read the base length and height of a right pyramid as input from the user
• Display all of the inputs back to the user, formatted to 2 decimal place as shown in the sample. The decimals of the two values should line up.
• Calculate the volume of the right pyramid using the above formula
o Notice that the square of the base is used in all three formulas. Compute and store this value separately. Then use the stored value in all the formulas.
• Calculate the slant height of the right pyramid using the above formula
• Calculate the surface area of the right pyramid using the above formula
o Use the pre-defined sqrt function from the cmath library in both the slant height and surface area calculations.
• Write and call a separate, user-defined function to output the calculation results:
o The function should have thee input parameters: surface area, slant height, and volume
o From within the user-defined function, display surface area, slant height, and volume of the right pyramid formatted as shown below, each rounded to 2 decimal places. The decimals of the three values should line up, and also line up with the input values displayed from main.
o No calculations should be performed from within this function.
Sample Input and Output
Documentation
1) Be sure to include top of program comments as specified in course Content section 1.8:
Your name, the course, and the assignment number
What the Program Does including:
What is Input
Processing Performed
What is Output
Right Pyramid Calculations
Enter pyramid base length (in inches): 1.111
Enter pyramid height (in inches): 1.111
RESULTS:
For a Right Pyramid with
Base Length of 1.11 inches
Height of 1.11 inches
Pyramid Slant Height is 1.24 inches
Pyramid Surface Area is 3.99 square inches
Pyramid Volume is 0.46 cubic inches
Press any key to continue . . .
2) You must also include a comment above each user-defined function that includes:
What the function does
The name and a description of any parameters that are input to the function
3) For readability, make sure you have:
- a SPACE before and after each operator (+, -, *, /, =)
- a SPACE after each comma in your code
- blank lines between sections of your code
4) Remember that dividing one integer by another integer will produce an integer result.
Example: 1 / 3 = 0
So if you want floating point results, be sure that one of the operands is a floating point value.
Example: 1 / 3.0 = 0.3333...
5) Comment any constants/variables whose names are not completely descriptive.
Submission
This programming assignment is due by midnight Sunday. Submit your program source code
(both of the .cpp files) to the Prog Assn 2 dropbox (located under the Dropbox tab in the online
course). Both files should be attached to one submission for programming assignment 2.
Before submitting your program files, you MUST name them as follows:
Lastname-wk2-prog1.cpp
Lastname-wk2-prog2.cpp
For example:
Smith-wk2-prog1.cpp
Smith-wk2-prog2.cpp
Write a program that:
• Defines the vacuum permeability value as a program constant using scientific notation.
• Uses a separate, user-defined function to output a program description header to the user
before prompting for input. This header should contain your name. For example:
• Reads the number of turns in each coil, as input from the user
• Reads the radius of the coil loops (in meters), as input from the user
• Reads the current in the coils (in amperes), as input from the user
• Calculates the magnetic field
o Use the pre-defined pow function from the cmath library to calculate the
fractional value raised to a power, used in the calculations.
• Displays one or two blank lines after reading all the inputs, before displaying the results
• Displays all data using the format given in the following sample output, which meet the
following specifications:
The number of turns in the coils should be displayed first.
The coil radius and current should be displayed in fixed format, carried out to 3
decimal places. Their decimals should line up.
The vacuum permeability constant and calculated magnetic field should be
displayed in scientific format, carried out to 5 decimal places. Their decimals
should line up.
All unit values should line up.
NOTE: You are not required to validate any of the user input. You may assume that the user will
enter a valid answer for each question.
Additionally, the program must:
• Compile without errors,
• Include appropriate mnemonic constant and variable declarations,
• Prompt the user for data in a meaningful way,
• Pause the program after the data is displayed, and
• Adhere to the documentation standards for this course (see course Content section 1.8)
Magnetic Field within Helmholtz coils
by
Mr. Joe Electric
Sample Input and Output:
The data in this example calculates the magnetic field in the center of a Helmh