205k views
0 votes
We have a shape with " n " sides. Create a script that will prompt the user " n " times or " n×2 " times for (x,y) value of each vertex of the shape. Then, compute the distance between adjacent vertices. Then, display the result. The whole thing has to be done by using LOOP and ARRAY.

User JaChNo
by
6.5k points

1 Answer

3 votes

Final answer:

The script prompts the user for the (x,y) coordinates of each vertex of an "n" sided shape, computes the distances between adjacent vertices using loops and arrays, and then displays the results.

Step-by-step explanation:

The script utilizes a loop to prompt the user for the (x,y) coordinates of each vertex of a shape with "n" sides. It stores these coordinates in an array using a loop to ensure the correct number of inputs based on the number of sides.

Subsequently, it calculates the distance between adjacent vertices using the distance formula for each pair of coordinates. This computation involves accessing the coordinates from the array and applying the distance formula, storing the results in another array. Finally, the script displays the computed distances between adjacent vertices, showing the distance between each consecutive pair of vertices around the shape.

The use of loops ensures that the user is prompted the required number of times for input, allowing for flexibility in handling shapes with different numbers of sides. Arrays are employed to store the coordinates and computed distances systematically, facilitating the organized manipulation of data throughout the process.

By iterating through the vertices and applying mathematical operations within the loops, the script accurately calculates the distances between adjacent vertices without the need for repetitive manual calculations.

User Brejuro
by
7.4k points