2023 The topic of this assignment was chosen so that you won t allow mathematical equations | Assignment Collections
Computer Science 2023 Dev C++ Compiler Solution
2023 The topic of this assignment was chosen so that you won t allow mathematical equations | Assignment Collections
The topic of this assignment was chosen so that you won’t allow mathematical equations and scientific notation to intimidate you. No knowledge is required to complete the assignment beyond knowing how to perform mathematical operations within a formula.
NOTE: Use the double precision data type for all floating point variables in these programs (instead of the single precision float data type).
Program #1
Electro-magnetic force describes the influence that one electrical charge has on another when neither charge is moving.
The equation for this electro-magnetic force in Newtons is: , where the constant
and where: π is the constant Pi, whose value to 10 decimal places is 3.1415926535
E0 is a constant known as the permittivity of free space with value = 8.854 x 10-12 coulombs2 per Newton meters2
q1 and q2 represent the charges of two objects in coulombs
r represents the distance between the centers of the objects in meters
K is Coulomb’s constant, in Newton meters2 Coulombs-2
For the Curious: Electrical charges can either attract or repel each other, as q1 and q2 may be either positive or negative. When the have same signs, they repel each other. When they have opposite signs, they attract each other.
Program Requirements:
Write a program to compute the electro-magnetic force between 2 charged objects. The program shall: Define a constant, using scientific notation, for the permittivity of free space. Define another constant, using fixed notation, for Pi carried out to 10 decimal places.
Use a separate, user-defined function to output the program description header to the user before prompting for input. This header should contain your name. For example:
Read user input 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.
o Read the charges of two objects, as input from the user. o Read the distance between the centers of the two objects, as input from the user. Calculate the electro-magnetic force between the objects. Display several 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 charges of both objects, and the distance between the objects, are displayed first, in fixed format, carried out to 3 decimal places. Their decimals should all line up. The permittivity of free space, the calculated Coulomb’s constant, and the calculated electro-magnetic force are 1ll displayed in scientific format, carried out to 4 decimal places. Their decimals should line up. All unit descriptions also line up.
Additionally, the program must: Compile without errors Include appropriate mnemonic constant and variable declarations Prompt the user for data in a meaningful way Adhere to the documentation standards for this course (see course Content section 1.8)
(see sample input/output on next page)
Calculation of Electro-magnetic Force between two Objects By Mr. YOUR NAME
Sample Input and Output:
Notes: This output example provides convenient test data that can be used to verify the calculations in your program. The representation of the following number uses scientific notation: o 8.854 x 10-12 is the same as 0.000000000008854, and is represented in C++ scientific notation as 8.854E-12. o The minus sign in 8.854E-12 indicates a negative exponent (i.e. a fraction). o By default, the exponent in scientific notation is displayed using 3 digits, like this: 8.854E-012. o The number of digits in the scientific notation can be changed via the setprecision output manipulator (i.e. the same method as fixed notation). Users can also input values at the keyboard using scientific notation
(see next page for program 2 requirements)
Calculation of Electro-magnetic Force between two Charged Objects By Mr. YOUR NAME
Enter charge of object 1 (in coulombs): 1.1 Enter charge of object 2 (in coulombs): 2.2
Enter distance between the centers of the two objects (in meters): 10
RESULTS:
Charge of first object: 1.100 coulombs Charge of second object: 2.200 coulombs Distance between objects 10.000 meters
Permittivity of Free Space: 8.8540e-012 coulombs^2 per Newton meters^2 Coulomb’s Constant: 8.9877e+009 Newton meters^2 Coulombs^-2
Electromagnetic Force: 2.1750e+008 Newtons
Program #2
A right circular cone has a circular base, and the line from the center of the base to the tip of the cone forms a right angle with the base.
If you know the height (h) of a cone and the radius (r) of the base of the cone, then you can calculate the slant height (s), surface area (a), and volume (v) of the cone using the following formulas.
Slant Height: s = √ Surface Area: A =
Volume: v =
Note that the slant height is the hypotenuse of the right triangle, whose other two sides are the height and the radius of the base.
Again, don’t let the equations intimidate you. These formulas simply perform addition, multiplication, division, squaring, and finding a square root.
Requirements:
Write a program that will: Display a program description to the user before asking for any input. Defines a constant for PI, using fixed notation, carried out to 5 decimal places (value for Pi was given in program 1). Read the radius of the base of a right circular cone, as input from the user. Read the height of a right circular cone, as input from the user.
Calculate the square of the radius, and store its value in a variable. (This value is used in all of the formulas. Use the stored value in all the formulas.) o Use the pre-defined pow function from the cmath library for squaring. Calculate the slant height of the right circular cone, using the above formula. o Use the pre-defined sqrt function from the cmath library to implement this calculation. Calculate the surface area of the right circular cone, using the above formula. Calculate the volume of the right circular cone, using the above formula. From the main function, display a few blank lines, and then a RESULTS header. From the main function, display the base radius and height of the right circular cone, rounded to 2 decimal places as shown in the sample output. The decimals of both values should line up. Write and call a separate, user-defined function to output the calculation results: o The function should have thee input parameters: slant height, surface area, and volume o From within the user-defined function, display surface area, slant height, and volume of the right circular cone 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) Comment any constants/variables whose names are not completely descriptive.
Program for Right Circular Cone calculations
Enter cone radius (in inches): 5.5 Enter cone height (in inches): 10
RESULTS: For a Right Circular Cone with Radius of 5.50 inches Height of 10.00 inches
Cone Slant Height is 11.41 inches Cone Surface Area is 292.23 square inches Cone Volume is 316.78 cubic inches
2) 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
3) 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
4)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
5) 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…
Submission
This programming assignment is due by midnight Monday. 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
We give our students 100% satisfaction with their assignments, which is one of the most important reasons students prefer us to other helpers. Our professional group and planners have more than ten years of rich experience. The only reason is that we have successfully helped more than 100000 students with their assignments on our inception days. Our expert group has more than 2200 professionals in different topics, and that is not all; we get more than 300 jobs every day more than 90% of the assignment get the conversion for payment.