Question: Purpose: To practice recursion with a simple example.Moosetopias most famous rocket scientist, Zeno, has invented a new kind of space ship which will enableinterstellar travel

Purpose: To practice recursion with a simple example.Moosetopias most famous rocket scientist, Zeno, has invented a new kind of space ship which will enableinterstellar travel across the large distances of space very quickly. The technology is very complicated, andinvolves a lot of tedious messing about in hyperspace, but the actual motion of the ship is quite simple: If the distance to the destination is greater than 1 meter, the ship will "fold space" and "jump" to aposition half way to the destination. It takes exactly one minute for the ships computer to do thecalculations prior to the jump. The jump itself is instantaneous. Any distance of 1 meter or less will take exactly one minute, using normal impulse rockets.For example, if the ship has to travel 10 meters, it will jump 5 meters after the first minute, 2.5 meters thesecond minute, 1.25 meters the 3rd minute, and 0.625 meters the fourth minute. Finally, the remaining0.625 meters takes one more minute. Thus the total time to travel 10 meters is 5 minutes. (That seemsvery slow, and it is for small distances; the true value of this method only reveals itself for large distances.)Write a recursive function called spaceTime() that calculates the time needed for Zenos ship to travel agiven distance. In the same file, write a program that asks the user for a distance in meters (console input)then call your spaceTime() function to calculate the time required to travel the given distance.Test your function out on all of the following examples: Average distance to the nearest coffee shop: 537 meters (about a typical Moosetopia city block). Average distance from Moosetopia to its biggest moon: 3.84e8 meters (about 400 thousand km). Average distance between our earth and our sun: 1.49e11 meters (about 150 million km). Approximate distance between the sun and the closest star: 4.0e16 meters (about 4 light-years). Size of the observable universe: 8.8e26 meters (about 93 Giga-light-years)Sample RunYour program output might look something like the following: Zeno s drive requires :-11 minutes to travel 537 meters to Zeno s nearest coffee shop-30 minutes to travel 384000000.0 meters from Moosetopia to its biggest moon-39 minutes to travel 149000000000.0 meters from our earth to our sun-57 minutes to travel 4 e +16 meters from our sun to the nearest star-91 minutes to travel 8.8 e +26 meters across the observable universe

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 Programming Questions!