This is the requirement and sample run of this problem. and I have the screen sh
ID: 3846880 • Letter: T
Question
This is the requirement and sample run of this problem. and I have the screen shoot of the two files if needed.
How to write the code to finish this problem?
Problem Statement Suppose there are Nelectric point charges at rest in a region of three-dimensional space. The k-th point charge has a charge value Qu and is located at the coordinate Pk E Crk, yk, zk The index k ranges from 1 to N. Write a C program that computes the electric field intensity E at an arbitrary position P (x, y, z) that is due to a given configuration of electric charges. The charge data are stored in an external text file. Note This exercise may seem difficult at first due to the extensive physics concepts. However, the final working equation is fairly straightforward and involves being able to add together array elements in a methodical manner. So, do not worry if you are unfamiliar with the details of the electric field theory; just follow along and look at the example calculation Electric Field Equations (Physics Background) The electric field' intensity E is a measure of the force acting on a unit positive point charge Q that is placed at a location within the field. The electric field is a vector quantity For this assignment, use a Cartesian system for defining coordinates in a three-dimensional space. Assume that in, ily, and iz are the unit vectors in the directions of the x, y, and z coordinate axes, respectively (Figure 1) Figure 1: 3-D unit vectorsExplanation / Answer
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <fstream>
#include <sstream>
using namespace std;
struct PointCharge
{
double q, x, y, z;
};
typedef PointCharge pc;
void read(string filename, vector<pc> &charges)
{
ifstream in(filename);
string line;
while ( getline(in, line) )
{
stringstream ss{line};
pc pc1{};
ss >> pc1.q >> pc1.x >> pc1.y;
charges.push_back(pc1);
}
};
double calc_field()
{
// I am bad at math mate, so if ya could point out the absolute formula.
}
int main(int argc, char const *argv[])
{
// Charges vector.
vector<pc> Cs;
double x, y, z;
if (argc > 1)
{
read(argv[1], Cs);
}
else
{
string filename{};
cout << "Enter charge file name: ";
cin >> filename;
read(filename, Cs);
}
for (size_t i = 0; i < Cs.size(); ++i)
{
cout << fixed;
cout << "[" << setw(2) << i+1 << "]"
<< " Q=" << setw(10) << setprecision(6) << Cs.at(i).q
<< " P=(" << setw(7) << setprecision(3) << Cs.at(i).x
<< ", " << setw(7) << setprecision(3) << Cs.at(i).y
<< ", " << setw(7) << setprecision(3) << Cs.at(i).z
<< ")" << endl;
}
cout << endl;
cout << "Enter test position coordinates (x y z): ";
cin >> x >> y >> z;
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.