Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

It\'s not really well known, but Mario (now famous for his work with Nintendo) a

ID: 3767923 • Letter: I

Question

It's not really well known, but Mario (now famous for his work with Nintendo) appeared in a very early computer game called "Leap Line." Mario was placed on a one-dimensional track, and he could move along the track using two kinds of movement. He could take one step forward or he could jump two steps forward. There was no backwards jumping, and no jumping more than 2 steps. Also, Mario was blindfolded, so he could not see the track The track had two kinds of objects on it: coins, and mushrooms. Mario could collect the coin if he stepped on it, and he would lose a coin if he stepped on a mushroom. The goal of the game was to get as many coins as possible. Mario should try to collect coins and should try to jump over mushrooms. The tricky part is that Mario is blind-folded. That means he had to decide to step or jump without knowing what was ahead of him. A track could have any number of coins or mushrooms, even many mushrooms in a row. See the examples below! There's no guarantee that the best score will be positive, either Well represent the track with a 1-D array of integers. The array can be any length, but the length is known. The array will have a zero (0) as the first element, because that's where Mario starts, and a zero (0) as the last element, because Mario has to end up there; Mario cannot jump off the track! Every element after the first will be either +1 (coin) or -1 (mushroom). o If Mario is at element i, he collects the coin if there is one, or loses a coin if there's a mushroom. It does not matter if Mario got there by a step or a jump o When Mario takes a step, he moves from element i to element i+1 o When he jumps, he moves from element i to element i+2, leaping over element i+1 o Mario has to end on the last element of the array; he cannot leap over the last one Here are a couple of example arrays int int int easy[5] {0,-1,1,-1,0): medium [10] {0,-1,1,-1,1,-1,-1,-1,1,0); challenging [15] = {0,-1,1,-1,1,1,-1,1,-1,1,1,-1,-1,-1,0); The best score for the easy problem is 1, if Mario jumps twice. If Mario stepped through this track, his final score would be -1. The best score for the medium problem is 2, as Mario can't jump over all the mushrooms when there are three in a row. If Mario just stepped through this one, his score would be -2, as he would have collected every coin, but stepped on every mushroom. The best score for the challenging example is 5. Our task in this question is to calc ulate the maximum possible score for any given track, with any arrangement of coins and mushrooms. We will do so using a recursive function. To give you a good start, we'll provide the function header: // Given a track array) with a given size int ) Assume Mario starts at location loc (int) in the track This function returns the maximum score Mario can get / starting at loc going to the end of the track (size-1) int coreFrom(int track[i, int size, int 1oc) you fill this part in! It will be recursive, but track and size will not change. Only Mario's location will change. And, in main, when you want to find the maximum score for a complete track, you'll call it like this, with Mario's initial location set to 0, like this cout

Explanation / Answer

Complete Program:

#include <iostream>
#include <string>
using namespace std;

int maximumScoreFrom(int track[], int size, int loc)
{
if(loc == size - 1)
  return track[loc];
else
  return std::max(track[loc], maximumScoreFrom(track, size, loc + 1));
}

int main()
{
int easy[5] = {0, -1, 1, -1, 0};

cout << "Best score (easy): " << maximumScoreFrom(easy, 5, 0) << endl;

system("pause");
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote