Question

In C++ program Fishing Game Simulation   For this assignment, you will write a program that simulates a fishing game. In this game, a six-sided die is rolled to determine what the user has caught. Eac...

In C++ program

Fishing Game Simulation  

For this assignment, you will write a program that simulates a fishing game. In this game, a six-sided die is rolled to determine what the user has caught. Each possible item is worth a certain number of fishing points. The points will not be displayed until the user has finished fishing, and then a message is displayed congratulating the user depending on the number of fishing points gained.  

Here are some suggestions for the game’s design:

  • Each round of the game is performed as an iteration of a loop that repeats as long as the player wants to fish for more items.
  • At the beginning of each round, the program will ask the user whether he or she wants to continue fishing.
  • The program simulates the rolling of a six-sided die.
  • Each item that can be caught is represented by a number generated from the die. For example, 1 for “a huge fish,” 2 for “an old shoe,” 3 for “a little fish,” and so on.
  • Each item the user catches is worth a different amount of points.
  • The loop keeps a running total of the user’s fishing points.
  • After the loop has finished, the total number of fishing points is displayed, along with a message that varies depending on the number of points earned.

To implement this game, create a class named FishingGame that includes the appropriate functions for carrying out the above requirements.


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

class Die
{
public:
        static int rollDie(int numSides)
        {
                if (numSides < 1)
                        return 0;

                return 1 + rand() % numSides;
        }

        static int rollD6()
        {
                return rollDie(6);
        }
};


class FishingGame
{
private:
        int score;

public:
        FishingGame()
        {
                score = 0;
        }

        int calculateScore(int fish)
        {
                // Determine number of points for fish
                // and return it.

                return 0;
        }

        string castLine()
        {
                int fish = Die::rollD6();

                // TODO: Determine a number of points for the fish.
                //       Call the calculateScore function and add
                //       results to score.

                // TODO: Return a description of the fish.
                //       Examples: "a big fish", "an old shoe", etc.
                return "";
        }

        int getScore()
        {
                // Return the score.
                return 0;
        }

        string getFeedback()
        {
                // If player earned a good score, congratulate him/her.
                // else encourage him/her to try again.
                return "";
        }
};


int main()
{
        FishingGame game; // Create the game object.

        // Repeat until user is ready to quit.
        {
                // Cast a line.
                cout << "You caught " << game.castLine() << endl;

                // prompt user to keep playing or quit
        }

        // Display score.
        // Display feedback.


        // Keep this stuff at the end.
        cout << endl;
        system("pause");
        return 0;
}
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Thanks for the question.
Here is the completed code for this problem. Let me know if you have any doubts or if you need anything to change.
Thank You !!
=========================================================================================

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

class Die
{
public:
static int rollDie(int numSides)
{
if (numSides < 1)
return 0;

return 1 + rand() % numSides;
}

static int rollD6()
{
return rollDie(6);
}
};


class FishingGame
{
private:
int score;

public:
FishingGame()
{
score = 0;
}

int calculateScore(int fish)
{
int scores[] ={10,2,50,1,4,2};
               score+=scores[fish-1];
return 0;
}

string castLine()
{
int fish = Die::rollD6();
               string treasure[]={" A big fish","An old shoe","A golden penny","A nail","A fish net","An oyster"};
// TODO: Determine a number of points for the fish.
// Call the calculateScore function and add
// results to score.
// TODO: Return a description of the fish.
// Examples: "a big fish", "an old shoe", etc.
calculateScore(fish);
return treasure[fish-1];
}

int getScore()
{
// Return the score.
return this->score;
}

string getFeedback()
{
// If player earned a good score, congratulate him/her.
// else encourage him/her to try again.
if(this->score>100){
    return "You scored a good score!";
           }else{
              return "Better luck catching fish next time";
           }
}
};


int main()
{
FishingGame game; // Create the game object.
char playAgain='n';
// Repeat until user is ready to quit.
do
{
// Cast a line.
cout << "You caught " << game.castLine() << endl;

// prompt user to keep playing or quit

cout<<"Do you want to play again (y/n)? ";
cin>>playAgain;
}while(playAgain!='n');

// Display score.
cout<<"Your total score from fishing is: "<<game.getScore()<<endl;
// Display feedback.
       cout<<game.getFeedback();

// Keep this stuff at the end.
cout << endl;
system("pause");
return 0;
}

=========================================================================================

thanks !

Add a comment
Know the answer?
Add Answer to:
In C++ program Fishing Game Simulation   For this assignment, you will write a program that simulates a fishing game. In this game, a six-sided die is rolled to determine what the user has caught. Eac...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 12. Coin Toss Simulator Write a class named Coin. The Coin class should have the following field ...

    12. Coin Toss Simulator Write a class named Coin. The Coin class should have the following field .A String named sideUp. The sideUp field will hold either "heads" or "tails" indicating the side of the coin that is facing up The Coin class should have the following methods .A no-arg constructor that randomly determines the side of the coin that is facing up (heads" or "tails") and initializes the aideUp field accordingly .A void method named toss that simulates the...

  • For this lab you will write a Java program that plays the dice game High-Low. In...

    For this lab you will write a Java program that plays the dice game High-Low. In this game a player places a bet on whether the sum of two dice will come up High (totaling 8 or higher), Low (totaling 6 or less) or Sevens (totaling exactly 7). If the player wins, they receive a payout based on the schedule given in the table below: Choice Payout ------ ------ High 1 x Wager Low 1 x Wager Sevens 4 x...

  • question 2 in C programming please PE-05b-01 (Six-sider) write a counter-controlled program that prompts the user...

    question 2 in C programming please PE-05b-01 (Six-sider) write a counter-controlled program that prompts the user to enter the number of times n to roll a six-sided die. The program should print to the screen the iteration of the loop and result for each roll 1 ) How many times would you like to roll? 3 roll 6 6 5 1 2) PE 05b 02 (Flash Cards) Write a counter-controlled program that creates addition problems for an elementary kid to...

  • Create a new program, WordGuessingGame. Using a while loop, create a game for the user. The...

    Create a new program, WordGuessingGame. Using a while loop, create a game for the user. The game requires the user to guess a secret word. The game does not end until the user guesses the word. After they win the game, they are prompted to choose to play again. The secret word that user must guess is "valentine". It is a case-sensitive analysis With each guess... If the guess does not have an equal number of characters, tell the user...

  • Football Game Scores Write a C++ program that stores the following data about a football game...

    Football Game Scores Write a C++ program that stores the following data about a football game in a structure: Field Name Description visit_team string (name of visiting team) home_score int visit_score int The program should read the number of games from a data file named “games.txt”, dynamically allocate an array of structures for the games using one structure for each game, and then read the information for each game from the same file (visiting team, home score, visiting team’s score)....

  • Write a c++ program that simulates a million of games in craps. I am having a...

    Write a c++ program that simulates a million of games in craps. I am having a trouble getting to loop a million of times. I am trying to use a const for a million. This is the code so far. #include <iostream> #include <cstdlib>// contains prototypes for functions srand and rand #include <ctime>// contains prototype for function time #include <iomanip> using namespace std; int rollDice(); // rolls dice, calculates and displays sum void printstats(); int totroll = 0, games, point,...

  • (C++) Hey guys we just went over loops and it got me confused, it has me...

    (C++) Hey guys we just went over loops and it got me confused, it has me scrathcing my head for the past two days. I would appreciate any help you guys have to offer. Few places I have a hard time is get input and determine winner(cummulative part). Write a program that lets the user play the Rock, Paper, Scissors game against the computer. The computer first chooses randomly between rock, paper and scissors, but does not display its choice....

  • Professor Dolittle has asked some computer science students to write a program that will help him...

    Professor Dolittle has asked some computer science students to write a program that will help him calculate his final grades. Professor Dolittle gives two midterms and a final exam. Each of these is worth 100 points. In addition, he gives a number of homework assignments during the semester. Each homework assignment is worth 100 points. At the end of the semester, Professor Dolittle wants to calculate the median score on the homework assignments for the semester. He believes that the...

  • Write a C/C++ program that simulate a menu based binary number calculator. This calculate shall have the following three...

    Write a C/C++ program that simulate a menu based binary number calculator. This calculate shall have the following three functionalities: Covert a binary string to corresponding positive integers Convert a positive integer to its binary representation Add two binary numbers, both numbers are represented as a string of 0s and 1s To reduce student work load, a start file CSCIProjOneHandout.cpp is given. In this file, the structure of the program has been established. The students only need to implement the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT