Use the structure below to answer the following questions a) What is the purpose
ID: 3683105 • Letter: U
Question
Use the structure below to answer the following questions a) What is the purpose of the following statement: b) How do we access the mass property of the second element in the array? How do w access the x coordinate? c) Write the statement(s) necessary to initialize every element and its properties to zero. d) Write the prototype of a function that takes two c Particles as parameters and returns the electric force (float) between them. e) How would you use the function in (d) to calculate the electric force between the first and last elements of the my Particles array? f) Refer to the following piece of code i. What is the intent of the code? ii. Will the code work? Why or why not? iii. How would we fix the code to have the expected intent?Explanation / Answer
a) struct sParticle myParticles[10]; will create array of structure of sParticle, here 10 structure variables will be created.
b)
myParticles[1].m;
myParticles[1].position.x;
c)
for(i=0;i<10;i++)
{
myParticles[i].m=0;
myParticles[i].q=0;
myParticles[i].position.x=0;
myParticles[i].position.y=0;
myParticles[i].position.z=0;
}
d)
float myfun(struct cParticles x, struct cParticles y);
e)
float myfun(cParticles x, cParticles y)
{
float force=x.q-y.q;
return force;
}
f)
i. The intent of the code is to change the position of the particles.
ii. The code will not work because we cannot directly initialize the element.
iii.
newPosition.position.x=2;
newPosition.position.y=2;
newPosition.position.z=2;
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.