Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

pls code in c++, Code begins below at A hypothetical, circular.... Use #include , #include , #include , and #include at the beginning ---------- A

pls code in c++, Code begins below at A hypothetical, circular....

Use #include , #include , #include , and #include at the beginning

----------

A hypothetical, circular cell has a radius of 10 units and is centered on the origin (0, 0). This program will determine whether a particle with coordinates (x, y) lies inside, outside or on the cell wall.

image text in transcribed

The coordinates of the particle are either entered manually by the user, or chosen at random.

Preamble

The program should begin by prompting the user to choose a method of particle location selection:

Select particle location by: [E] entering coordinates [R] random generation 

If E (uppercase or lowercase) is entered, the user will be prompted to enter the X- and Y-coodinates of the particle, as detailed below.

If R (uppercase or lowercase) is entered, the program will randomly choose values for X and Y from the range -12..12, as detailed below.

If any other character is entered, the program will output a message saying that the option is unknown, and will do nothing else. For example:

Select particle location by: [E] entering coordinates [R] random generation q Unknown option: q 

Selecting the Particle Coordinates

If the user chooses to enter the coordinates of the particle manually, the program should prompt the user for each coordinate, X and Y, one at a time.

If the user chooses to generate random coordinates, the program should choose random values for each coordinate, X and Y, in the range -12..12 inclusive.

NOTE: To be sure that the Random Number Generator uses numbers that are consistent with the test program, seed your RNG with the value 314159.

Once the particle location has been determined, the program will output the location (displaying values to 2 decimal places).

Computing the distance from the Origin

Next, the program will compute the distance of the particle from the origin, to determine whether it lies inside, on, or outside the cell wall.

image text in transcribed

The distance from the origin can be computed using a rearrangement of the Pythagorean Theorem: x^2 + y^2 = d^2. Solving for distance d we get d = sqrt(x^2 + y^2).

Deciding Inside, On, or Outside

We will use a tolerance ("epsilon") of 0.0001 for deciding if the distance "equals" the radius of the cell, thus determining that the particle lies on the cell wall.

If that is not the case, then a distance less than the radius means the particle must be inside the cell wall, or a distance more than the radius means the particle must be outside the cell wall.

Example Output

Here are a few sample runs

Select particle location by: [E] entering coordinates [R] random generation E Enter X-coordinate: 4.5 Enter Y-coordinate: -9.2 Particle is at (4.50,-9.20) Outside cell wall 
Select particle location by: [E] entering coordinates [R] random generation e Enter X-coordinate: 8.0 Enter Y-coordinate: 6.0 Particle is at (8.00,6.00) On cell wall 
Select particle location by: [E] entering coordinates [R] random generation e Enter X-coordinate: 6.28 Enter Y-coordinate: 2.71828 Particle is at (6.28,2.72) Inside cell wall 
Select particle location by: [E] entering coordinates [R] random generation r Particle is at (7.00,-2.00) Inside cell wall
6 3 4 5 8

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions