Question: Design an object-oriented fishing game using the following two classes as specified in Unified Modeling Language (UML). + indicates public, - indicates private, and the

Design an object-oriented fishing game using the following two classes as specified in Unified Modeling Language (UML). + indicates public, - indicates private, and the data type of a return value or a parameter is indicated by a : following its name.

Fish

- name : string

- value : int

+ Fish():

+ Fish(name:string, value:int):

+ setName(name:string):void

+ setValue(value:int):void

+ getName() : string

+ getValue() : int

Player

- inventory : Fish*

- numFish : int

+ Player():

+ ~Player():

+ goFish() : void

+ addFish(fish : Fish) : void

+ getTotalScore() : void

+ printInventory() : void

+ sortInventory() : void

Each Fish object will have a name and a point value associated with it.

It will have a getName() and getValue() function to access its private variables.

It will have a setName() and setValue() function to mutate its private variables.

It will have a default constructor for when the array is first created.

It will have a constructor that takes a name and value for when a new Fish is created and added to the array.

The Player object will hold:

inventory, a pointer to a dynamically allocated array of Fish objects.

numFish will hold the number of fish in the array, initially 0.

The default constructor will create each of these initial values.

The destructor will delete the Fish array using delete []

goFish() : void

Create a 1 in 4 chance that a fish will be caught

If a fish is caught, create 1 of 5 randomly selected fish objects:

Make a common fish, 60/100 times will be caught

Another fish is 20 / 100

Next, 14 / 100

Next 5 / 100

Finally, 1 / 100, an ultra rare fish

Give each of the 5 fish types their own name, and a value that corresponds to its rarity

Once the fish is caught and its type decided, call addFish() with the newly constructed fish object as its argument

If the user caught a fish, notify them of its name and value, otherwise say they didn't catch anything.

addFish(fish : Fish) : void

increment numFish by 1

allocate a new temporary array with size equal to numFish

Copy all of the fish from inventory to the temp array

Assign the new fish to the end of the temp array

delete[] the inventory pointer to free up the old array

Assign the inventory pointer to equal the address of the temp array

getTotalScore() : void

Output total sum of the value of the fishies

printInventory() : void

Output the names and point values of each fish. Use iomanip to make it into a nice two column table.

sortInventory() : void

Sort the fish inventory by name. Hint : look at the name for comparison, but swap the entire object when swapping.

Create an outer game loop that repeatedly asks the user if they would like to go fishing (y or n), then call goFish(), then sortInventory(), then printInventory(), then getTotalScore().

You can write the class definitions and main all in one file if you choose to. If you place your class declarations in header files and class definitions in separate cpp files, make sure you submit the entire project folder as a zip.

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