Question: Assignment: Cell Wall In this assignment you will detect whether or not a particle lies inside, outside, or on a hypothetical circular cell wall. To

Assignment: Cell Wall

In this assignment you will detect whether or not a particle lies inside, outside, or on a hypothetical circular cell wall. To do this, you will need the radius of the circle and the (x,y) coordinate of the particle. Create the following menu:

 1) Enter coordinate of particle 2) Generate random particle 

Initialize the radius to a value of 10

If the user chooses 1:

Ask for an x

Ask for a y

Output "In", "On", or "Out" depending on where the coordinate is

If the user chooses 2:

generate a random number between 0 and 20 for each x and y

Seed your RNG in the beginning of the program with the number 2018 so your numbers match the tester

Note: the server builds your code on a 64-bit Linux machine, so your randoms might appear different than the server's. As long as you use the seed 2018 you will be fine.

output the coordinate as (x,y)

Output "In", "On", or "Out" depending on where the coordinate is

To determine In, On, or Out, use the following logic:The equation of a circle is x^2 + y^2 = r^2

Solving this equation for r, you get r = sqrt(x^2 + y^2)

since r = 10, this gives 10 = sqrt(x^2 + y^2)

if abs(sqrt(x^2 + y^2) - 10) < 0.01, we will consider x and y to be close enough to r and call that "On"

else if sqrt(x^2 + y^2) < 10, then it must be "In"

else it must be "Out". This last condition would be sqrt(x^2 + y^2) > 10, but we do not need to check for this since if it were not true then one of the earlier conditions would have been met.

Sample output:

1) Enter coordinate of particle 2) Generate random particle 1 x: 3 y: 4 In 
1) Enter coordinate of particle 2) Generate random particle 1 x: 0 y: 10 On 
1) Enter coordinate of particle 2) Generate random particle 1 x: 15 y: 15 Out 
1) Enter coordinate of particle 2) Generate random particle 2 (1,17) Out

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!