Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

You will be using loops to calculate the time it takes to ferry a herd of llamas across an arbitrarily-sized body of water using three

You will be using loops to calculate the time it takes to ferry a herd of llamas across an arbitrarily-sized body of water using three boats of various speeds and cargo capacities.

Description:

After graduating from the University, you find yourself as a middle-aged llama farmer. Not the career you expected, but hey, it definitely pays the bills. One day, you need to transport your enormous llama herd across a lake. Luckily, you have three boats (of various speeds and cargo capacities) and a team of expert llama boat operators. Write a program to calculate the amount of time it will take you to transport your llama herd across the lake. Task 1 Start your program by asking the user for: The number of llamas in the users herd The length of lake to cross in meters The llama capacity of boat 1 The speed of boat 1 in meters per second The llama capacity of boat 2 The speed of boat 2 in meters per second The llama capacity of boat 3 The speed of boat 3 in meters per second If any value entered by the user is negative, prompt the user to enter the value again using a while loop. Task 2 Now its time to simulate! Using the values you collected from the user in Task 1, write a program to generate a table of the following values: The current time in seconds The position of each boat relative to the starting shore The number of llamas delivered While the herd is being transported, all boats repeat the same steps: Collect as many llamas from the shore as possible, up to the boats llama capacity Travel at top speed across the lake Deliver the llamas Travel at top speed back across the lake to collect more llama This is repeated until the entire herd of llama has crossed the lake. (Note that if the number of llamas left to be collected from the shore is less than a collecting boats llama capacity, all the remaining llamas are loaded onto the boat.) The position of each boat can be calculated using the equation: new position = old position + velocity * time elapsed Remember that boats change direction as soon as they reach the shore! Assume that the loading and unloading of llamas is instantaneous and that the boats can turn around instantaneously. Also assume that each boat always carries its maximum number of llamas and that the speed of each boat in meters per second will never exceed the numerical value of the length of the lake in meters. At the end of the simulation, print out the total time it takes to deliver the entire llama herd in seconds. Sample Output 1 Enter the number of llamas in your herd 5 Enter the length of the lake to cross (in m) 50 Enter the speed of the first boat (in m/s) 10 Enter the cargo capacity of the first boat (in llamas) 1 Enter the speed of the second boat (in m/s) 15 Enter the cargo capacity of the second boat (in llamas) 1 Enter the speed of the third boat (in m/s) 5 Enter the cargo capacity of the third boat (in llamas) 1 time boat1 boat2 boat3 llamas_delivered 1 10 15 5 0 2 20 30 10 0 3 30 45 15 0 4 40 40 20 1 5 50 25 25 2 6 40 10 30 2 7 30 5 35 2 8 20 20 40 2 9 10 35 45 2 10 0 50 50 4 11 10 35 45 4 12 20 20 40 4 13 30 5 35 4 14 40 10 30 4 15 50 25 25 5 delivery made in 15 seconds!

Note: this is a programming foundation class question and we have to write it in C++ language.

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

The World Wide Web And Databases International Workshop Webdb 98 Valencia Spain March 27 28 1998 Selected Papers Lncs 1590

Authors: Paolo Atzeni ,Alberto Mendelzon ,Giansalvatore Mecca

1st Edition

3540658904, 978-3540658900

More Books

Students also viewed these Databases questions

Question

3. Identify cultural universals in nonverbal communication.

Answered: 1 week ago