Question 2 (15 marks) A total charge Q (C, Coulombs) is uniformly distributed ar
ID: 3873414 • Letter: Q
Question
Question 2 (15 marks) A total charge Q (C, Coulombs) is uniformly distributed around a ring-shaped conductor with radius a (m). A charge q (C, Coulombs) is located at a distance x from the center of the ring (see below). The force exerted on the point charge by the ring is given by 9 3/2 iree space Develop a program that gets from the user, the charge that exists on both the ring and the point charge to compute the force exerted on the point charge by the ring For the main function o Obtains the data from the user and save them in appropriate variables o Calls the function force to compute the force exerted on the point charge by the ring. o Display results to the user in a message (see the following example) that includes data input by the user. Format the output values to display at most the number of digits in the fractional part of the real values shown the message example The charge on the ring is 2e-005 Coulombs The charge on the point is 2e-005 Coulombs The radius of the ring is 0.90 m The distance between the center of the ring and the point is 0.30 m The force exerted on the point is 1.26 N For the function force o Define parameters to receive the data input by the user. o Define local variable for storing the force F. o Use a symbolic constant for the values of eo (e.g. EO). Note that the math header file provides the symbolic constant M-PI for the value of o Use the functions from the math library for computing the power expressions o Instead of using a single instruction to compute the force value, use a number of instructions to "accumulate" values into the variable F as follows. Note that these are not true mathematical equations but show how F as a computer variable can accumulate intermediate values during the computation.Explanation / Answer
//Program to compute the force exerted on the point charge by the ring
#include <iostream>
#include <math.h>
#ifndef M_PI
# define M_PI 3.14159265358979323846
#endif
using namespace std;
//Function to compute the force given the parameters
// q=the point charge; Q=the charge of the ring, x=the distance between the center of the ring and the point; a=the //radius of the ring
float force(float q, float Q, float x, float a)
{
float F, E0 = 8.85*pow(10, -12);
F = 1/(4*M_PI*E0);
F *= q*Q*x;
F /= pow((x*x+a*a),1.5);
return F;
}
int main() {
//inputs are q, Q, a, x
float q, Q, a, x;
cin>>Q>>q>>a>>x;
cout<<"The charge on the ring is "<<Q<<" Coulombs. ";
cout<<"The charge on the point is "<<q<<" Coulombs. ";
cout<<"The radius of the ring is "<<a<<" m. ";
cout<<"The distance between the center of the ring and the point is "<<x<<" m. ";
float f = force(q, Q, x, a);
cout<<"The force exerted on the point is "<< f<<" N.";
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.