Question
A Frog Hopping competition is when a frog hops from the starting point to a random ending point. The frog attempts to hop to a
A Frog Hopping competition is when a frog hops from the starting point to a random ending point. The frog attempts to hop to a goal within a specified number of hops. You will write two methods for this program.
Write the method hopDistance() which returns an integer representing the distance (positive or negative) a frog hops. A Positive distance represents a move toward the goal. A negative distance represents a move away from the goal. The returned distance may vary from call to call so use a random number between -10 and 15. Each time a frog hips, its position is adjusted by the value returned by a call to hopDistance() method.
The frog hops until one of the following conditions becomes true:
The frog has reached or passed the goal.
The frog has reached a negative position.
The frog has taken the maximum number of hops without reaching the goal.
You will also write the method FrogSimulation() which will take in the parameters goalDistance and numberOfHops.
Here is the Starter Code for you to use. Copy and paste it into your program and complete the two methods.
+++++++++++++++++++++++++++++++++++++++++++++++
#include
int randRange(int low, int high){ return rand() % (high - low + 1) + low; }
//returns the distance (positive or negative) of a single hop between -10 and 15 int hopDistance(){ return 0; }
//The frog hops until one of the following conditions becomes true: //The frog has reached or passed the goal. //The frog has reached a negative position. //The frog has taken the maximum number of hops without reaching the goal. bool FrogSimulation(int goalDistance, int numberOfHops){
return true; }
int main(){ srand(time(NULL)); int distance = randRange(20, 30); int hops = randRange(5, 10); if(FrogSimulation(distance, hops)){ cout << "The frog successfully completed the competition!"; }else{ cout << "The frog did not complete the competition!"; } return 0; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started