CSCI 6901: Fundamentals of Programming - Functions and Arrays - IT Computer Science Assignment Help

Download Solution Order New Solution

Assignment  Task

Problem 1: Function Testing

On the Blackboard site is a program called Balloon.cpp. This is meant to be a “balloon throwing” game, where the player enters an angle and a velocity, and the game computes the distance the balloon travels (modified by a random wind value) and determines whether it lands within a range of 10 meters of a target. Currently, it is not working properly and your boss has assigned you the task of fixing it.

It uses a function called between to determine whether the distance the balloon travels falls within a given range. Your boss suspects the problem might be in the between function, but does not know for sure since there are so many complex calculations and random values.

Being a smart programmer, you know that the best way to find out is to test the between function separately using a function driver.

Write a simple main that acts as a function driver for the between function (and copy the between function into that file). As described in lecture, the driver should:

  • Prompt for values to pass to the function.
  • Call the between function with these values.
  • Print out the value returned by the function (this will be a 1 or a 0 since the function returns a Boolean value).

Use this testing tool to determine whether the between function is working correctly. If it is not working correctly, find and fix the error.

Note: You will be turning in your driver and the fixed between function (not the balloon game itself).

Make sure to add the following to the documentation of the function:

  • The nature of the problem that you fixed.
  • The test case you used to find the error.

 

Problem 2: Function Debugging

On the Blackboard site is a program called Buckets.cpp. This program pours water from one bucket to another, and then prints how much is in each bucket afterwards.

It uses a function called pour to actually do the pouring, subtracting an amount of water from the bucket we are pouring from, and adding it to the bucket we are pouring into.

However, when you run the code, you should notice that the amount of water in the buckets does not change.

Modify the pour function so that it does actually modify the amount of water in each bucket. Hint: This is a very simple change!

Note: You are not to use global variables! There is a better solution.

 

Problem 3: Designing Functions REVISED

In the previous assignment you wrote a program to play a simple Pokemon game. However, you did so as a single main program. In this problem you will create functions as part of a simplified version of this game with a single type of Pokémon, based on the last digit of your Banner ID:

On the site is a program called Pokemon.cpp. If you examine it, you will see that it is incomplete in three sections. You will create a function for each of these:

  • A function that prompts for whether the player wants to use a net or a freeze ray, and returns either n or f depending on what was chosen. As before, if the user does not enter one of these options, they should be prompted again until they do.
  • A function that handles the case where the player throws a net.

It should take the Pokémon speed as a parameter.

As before, it should generate a random number between 1 and 10. If that number is at least the Pokémon strength then the net succeeds, otherwise it fails.

It should print a message (the same as in the last assignment) telling whether the net capture succeeded or failed. It should return whether the capture succeeded or failed so the main program knows whether or not to increment the number of Pokémon captured.

  • A function that handles the case where the player uses a freeze ray.

It should take the Pokémon strength as a parameter.

As before, it should generate a random number between 1 and 10. If that number is at least the Pokémon strength then the freeze ray succeeds, otherwise it fails.

It should print a message (the same as in the last assignment) telling whether the freeze ray succeeded or failed. It should return whether the capture succeeded or failed so the main program knows whether or not to increment the number of Pokémon captured.

One key design decision is how these last two functions return whether the capture succeeds or fails. There are several good options for what type of information the functions return.

Note: You are not to use global variables!

As always, make sure these functions are well documented. In particular, each should have a header that describes what the function does, what it takes as input, and what it returns as a result.

 

Problem 4: Upgrading the Scheduler Program

On the Blackboard site is a program called Schedule.cpp. It is the same program that we used in class to introduce arrays. You are to add two new features to this program.

Total courses

When the user chooses the view option, the program displays the schedule of courses. You are to add code to this function to display the total number of courses in the schedule as well. For example:

You are to implement this by looping through the array and computing a running total of the courses found.

 

Preventing duplicate courses

Currently, the user may enter the same course over and over at different times:

You are to prevent this from happening. Specifically, when the user enters a course number, you are to search the schedule to see if that course number is already in the array.

If it is in the array, an error message should be printed:

 

Problem 5: Another Pokémon Game

Since your previous Pokémon game was so successful, you have been asked to create another. In this game, the player will search a set of rooms for Pokémon.

So that everyone gets to create a slightly different game, you will be assigned a different Pokémon based on the last digit of your Banner ID. Each has a different creation probability.

You are also to use the name of your Pokémon in your user interface. For example, since my last digit is 2 I will be using Nidoran in my examples.

Note: You are not to create a general purpose game for all Pokémon in this question. It should be “hardwired” for the specific Pokémon corresponding to your Banner ID.

Array Representation

There will be 5 rooms that Pokémon may be hiding in. However, you are to make this number a constant so the number of rooms can be changed in the future.

You are to use an array to represent the rooms. Each element of the array will be the number of Pokémon hiding in that room (there may be more than one in a room at a time).

For example, if there is 1 Pokémon in room 0, 2 in room 2and 1 in room 3 the array would look like this:

Game Start and End

At the beginning of the game a Pokémon should be placed in one of the rooms at random. In other words, that random room should have a value of 1 while the rest have a value of 0.

The game will run for 10 turns. You will be keeping track of the number of Pokemon found during the game, and print this out at the end of the game:

 

Creating Pokemon

Each turn there is a probability a new Pokemon will be generated in some random room, given in the above table for each type of Pokemon. If n is the number in the table, then the odds are n out of 10 that a Pokemon will be generated this turn. For example, since I have Nidoran, 4 out of 10 chance one is generated this turn.

Hint: There is a simple way to do this with the rand() function. Generate a random number, compute mod 10, and see if the result is < n>

if (rand() < 4>

When a new Pokemon is created, a message should be printed of the form:

 

Looking in rooms for Pokémon

Each turn the player will be asked which room they want to look into next. If they enter an illegal room number (something that is not a legal index in the array), they should be asked again until they enter a legal value:

If there are no Pokémon in that room, print a message of the form:

However, if there is at least one Pokemon in that room, you should do the following:

· Add the number of Pokemon in that room to the total found so far.

· Set the number of Pokemon in that room to 0.

· Print a message telling the player the number of Pokemon they found:

Sensing Pokémon in adjacent rooms

To make this more than just a simple guessing game, if there are any Pokémon in an adjacent room a message should be printed:

For instance, this message would be printed if the player looks in room 2 and there are Pokemon in room 1 or in room 3.

 

Functions

As with any program from this point on, you should break it down into separate functions where possible (but not use global variables). At a minimum, you should have a function to generate new Pokemon at random, and to allow the player to look into a room. This is an important part of your grade.

Hints

· I strongly suggest that you create a function that prints out the contents of the array (that is, the number of Pokemon in each room), called each turn. You can comment it out when you are done as the player should not know this, but you will find it extremely useful to know this during testing and debugging!

· I also strongly suggest that you build and debug the game incrementally. For example, don’t worry about adjacent rooms until after you can successfully look into the current room.

 

Problem 6: Another Pokémon Game in 2D

You are to modify the Pokémon search game from Problem 5 into a two-dimensional version. In this version of the game:

  • The board is a 5x5 two-dimensional array that stores the number of Pokémon currently in each room:

  • The player will enter the row and the column of the room they want to search. As before, you need to make sure that both are legal indices.
  • It will still print a message if there is a Pokémon in an adjacent room. In this case we define “adjacent” as being either directly above, blow, right, or left of the room selected. For example, if x marks the room selected, then a marks the adjacent rooms:

Important note: You are not to attempt this problem until you have completed, tested, and turned in the onedimensional version in Problem 5.

 

This CSCI 6901–IT Computer Science Assignment has been solved by our IT Computer Science Experts at My Uni Paper. Our Assignment Writing Experts are efficient to provide a fresh solution to this question. We are serving more than 10000+ Students in Australia, UK & US by helping them to score HD in their academics. Our Experts are well trained to follow all marking rubrics & referencing Style. Be it a used or new solution, the quality of the work submitted by our assignment experts remains unhampered.

You may continue to expect the same or even better quality with the used and new assignment solution files respectively. There’s one thing to be noticed that you could choose one between the two and acquire an HD either way. You could choose a new assignment solution file to get yourself an exclusive, plagiarism (with free Turn tin file), expert quality assignment or order an old solution file that was considered worthy of the highest distinction.

Get It Done! Today

Country
Applicable Time Zone is AEST [Sydney, NSW] (GMT+11)
+

Every Assignment. Every Solution. Instantly. Deadline Ahead? Grab Your Sample Now.