Question

Please do it by C++ programming! By completing this project, you will demonstrate your understanding of:...

Please do it by C++ programming!

By completing this project, you will demonstrate your understanding of:

1) Arithmetic operations (addition, subtraction, multiplication, division, modulus)
2) Conditional statements (If, If-Else, If-ElseIf-Else, Conditional Operator, Switch)
3) Precondition, postcondition, and indexing loops (Do-While, While, For)
4) Standard text file operations (open, close, read, write)
5) Modularizing code by breaking into functions (including functions with input parameters, and ones that return a specific data type)

There is a number guessing game similar to MasterMind called Pico-Fermi-Bagel. In this game, the leader chooses a 3-digit number that must not contain individual digits that are the same, and must be a 3-digit number. (In other words, 999 is not ok (3 digits, but the digits repeat), 25 is not ok (2 digits – cannot lead off with a zero), 121 is not ok either (3 digits, but 2 of the digits are the same).) The leader does not reveal the number to the players. The players must guess the number. If the players guess no digits in the number, that is called a “Bagel” – because bagels look like zeros. If a guess contains one or more digits that are in the number, but not in the right placevalue, then each of those is a “Pico” – pico means little, and the answer is a “little right”. If the guess contains one or more digits that are in the number AND in the right placevalue, then each of those is a “Fermi” – Fermi was a famous scientist; look it up.

Example. The leader picks 451
Player guess 1: 120 – this is a Pico because the 1 is in the actual number, but in the wrong place value.
Player guess 2: 879 – this is a Bagel because none of the digits are in the number (we like bagels, they tell us a lot!)
Player guess 3: 615 – This is a PicoPico (the 1 and the 5 are in the final number, but in the wrong places).
Player guess 4: 541 – this is a PicoPicoFermi (the 1 is in the correct place, the 4 and 5 are in the number but in the wrong places. Now we know the answer on the next guess.
If you are unsure about how this game is played, email me a guess for a number and I will email you back an answer!

The project: Create a version of PicoFermiBagel.
• Your code must include a function that picks the 3-digit number, and a function that checks the user input.
• You must write a text file with the original number in it, and then all the user guesses and the computer responses. You must ask the user for the name of the file to save. So, given the example above, the text file would look something like this:
451
120: Pico
879: Bagel
615: Pico Pico
541: Pico Pico Fermi
451: Fermi Fermi Fermi
• Your code must have a function that checks for valid input (a positive 3-digit number input), and asks the user again for input if the number is not valid.
• Your code needs to have a way for the user to “quit” the game.
• Your code needs to have a way for the user to play again without restarting the program. In this case, the new game information should be added at the end of the file you have created.
You will have analysis, pseudocode, a way to test your program for valid result, and documentation (comments) in your code.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer Program code #include <iostream> # include <time . h> using namespace std; int main() srand (time (NULL) int n 100 + ri-1 while (pl > 0) pl[i] 01 /= =p1 % 10 ; 10; İf ((digit [3]-p1 [3])&& (digit [2]-p1 [2])&& (digit [1-71 [1]) ) cout<<fermielse coutくくBagel; cout<< \ nPlayer 3; ps-100 + rand () % 999; cout<<\t<<p3<<\n; i=1; while (p3 0) p12 [1] = p3$10; p3if ( (digit [1]-p12 [1] ) | | (digit [1] ==p12 [2] ) I l (digit [1]=-p12 [3] ) ) cout<<picofermi; else cout<<Bagel; returProgram code:

#include <iostream>

#include <time.h>

using namespace std;

int main()

{

    srand (time(NULL));

    int n=100 + rand() % 999;

    int digit[3],pl[3],pl1[3],pl2[3];

    int i=1,p1,p2,p3;

     cout<<"Number"<<n<<"\n";

   while (n > 0)

{

    digit[i] = n%10;

    n /= 10;

    i++;

   }

   if((digit[3]!=digit[2])&&(digit[3]!=digit[1])&&(digit[2]!=digit[1]))

   {

       cout<<"\nPlayer1";

       p1=100 + rand() % 999;

       cout<<"\t"<<p1<<"\n";

       i=1;

        while (p1 > 0)

       {

            pl[i] = p1%10;

            p1 /= 10;

           i++;

       }

       if((digit[3]==pl[3])&&(digit[2]==pl[2])&&(digit[1]==pl[1]))

       {

           cout<<"fermi";

       }

      else if((digit[3]==pl[1])||(digit[3]==pl[2])||(digit[3]==pl[3]))

       {

           cout<<"picofermi";

       }

      else if((digit[2]==pl[1])||(digit[2]==pl[2])||(digit[2]==pl[3]))

       {

           cout<<"picofermi";

       }

       else if((digit[1]==pl[1])||(digit[1]==pl[2])||(digit[1]==pl[3]))

       {

           cout<<"picofermi";

       }

       else

       {

           cout<<"Bagel";

       }

       cout<<"\nPlayer2";

       p2=100 + rand() % 999;

       cout<<"\t"<<p2<<"\n";

       i=1;

        while (p2 > 0)

       {

            pl1[i] = 2%10;

            p2 /= 10;

           i++;

       }

       if((digit[3]==pl1[3])&&(digit[2]==pl1[2])&&(digit[1]==pl1[1]))

       {

           cout<<"fermi";

       }

      else if((digit[3]==pl1[1])||(digit[3]==pl1[2])||(digit[3]==pl1[3]))

       {

           cout<<"picofermi";

       }

      else if((digit[2]==pl1[1])||(digit[2]==pl1[2])||(digit[2]==pl1[3]))

       {

           cout<<"picofermi";

       }

       else if((digit[1]==pl1[1])||(digit[1]==pl1[2])||(digit[1]==pl1[3]))

       {

           cout<<"picofermi";

       }

       else

       {

           cout<<"Bagel";

       }

       cout<<"\nPlayer3";

       p3=100 + rand() % 999;

       cout<<"\t"<<p3<<"\n";

       i=1;

        while (p3 > 0)

       {

            pl2[i] = p3%10;

            p3 /= 10;

           i++;

       }

       if((digit[3]==pl2[3])&&(digit[2]==pl2[2])&&(digit[1]==pl2[1]))

       {

           cout<<"fermi";

       }

      else if((digit[3]==pl2[1])||(digit[3]==pl2[2])||(digit[3]==pl2[3]))

       {

           cout<<"picofermi";

       }

      else if((digit[2]==pl2[1])||(digit[2]==pl2[2])||(digit[2]==pl2[3]))

       {

           cout<<"picofermi";

       }

       else if((digit[1]==pl2[1])||(digit[1]==pl2[2])||(digit[1]==pl2[3]))

       {

           cout<<"picofermi";

       }

       else

       {

           cout<<"Bagel";

       }

   }

else

     cout<<"not valid input";

      

   return 0;

}

Add a comment
Know the answer?
Add Answer to:
Please do it by C++ programming! By completing this project, you will demonstrate your understanding of:...
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
  • c++ launguage please help The game Pico Fermi Bagel is a number guessing game. The computer...

    c++ launguage please help The game Pico Fermi Bagel is a number guessing game. The computer picks a secret number: the secret number must be 3 digits, none of the digits can be the same, and it cannot start with a zero. 104 is OK, but 091 and 212 are not. The user tries to guess the secret number - if none of the digits in the user's number are in the secret number, then the program replies with BAGEL...

  • Using C programming REQUIREMENTS: This program is a letter guessing game where a simple Al opponent...

    Using C programming REQUIREMENTS: This program is a letter guessing game where a simple Al opponent generates a secret letter for the user to guess. The user must be able to take turns guessing the secret letter, with the Al responding to the user's guesses. After successfully guessing, the user must be allowed to play again. The Al must count how many turns the user has taken. Here is an example of a game in progress where the human user...

  • C++ Hangman (game) In this project, you are required to implement a program that can play...

    C++ Hangman (game) In this project, you are required to implement a program that can play the hangman game with the user. The hangman game is described in https://en.wikipedia.org/wiki/Hangman_(game) . Your program should support the following functionality: - Randomly select a word from a dictionary -- this dictionary should be stored in an ASCII text file (the format is up to you). The program then provides the information about the number of letters in this word for the user to...

  • Please help with this Intro to programming in C assignment! Intro to Programming in C-Large Program...

    Please help with this Intro to programming in C assignment! Intro to Programming in C-Large Program 3 - Hangman Game Assignment purpose: User defined functions, character arrays, c style string member functions Write an interactive program that will allow a user to play the game of Hangman. You will need to: e You will use four character arrays: o one for the word to be guessed (solution) o one for the word in progress (starword) o one for all of...

  • For your Project, you will develop a simple battleship game. Battleship is a guessing game for...

    For your Project, you will develop a simple battleship game. Battleship is a guessing game for two players. It is played on four grids. Two grids (one for each player) are used to mark each players' fleets of ships (including battleships). The locations of the fleet (these first two grids) are concealed from the other player so that they do not know the locations of the opponent’s ships. Players alternate turns by ‘firing torpedoes’ at the other player's ships. The...

  • Code in JAVA.................... Guess the Number In this activity, you will write a REST server to...

    Code in JAVA.................... Guess the Number In this activity, you will write a REST server to facilitate playing a number guessing game known as "Bulls and Cows". In each game, a 4-digit number is generated where every digit is different. For each round, the user guesses a number and is told the exact and partial digit matches. An exact match occurs when the user guesses the correct digit in the correct position. A partial match occurs when the user guesses...

  • This is for C programming: You will be given files in the following format: n word1...

    This is for C programming: You will be given files in the following format: n word1 word2 word3 word4 The first line of the file will be a single integer value n. The integer n will denote the number of words contained within the file. Use this number to initialize an array. Each word will then appear on the next n lines. You can assume that no word is longer than 30 characters. The game will use these words as...

  • In this project, you will write a complete program that allows the user to play a...

    In this project, you will write a complete program that allows the user to play a game of Mastermind against the computer. A Mastermind game has the following steps: 1. The codebreaker is prompted to enter two integers: the code length n, and the range of digits m. 2. The codemaker selects a code: a random sequence of n digits, each of which is in the range [0,m-1]. 3. The codebreaker is prompted to enter a guess, an n-digit sequence....

  • microcontrollers

    Question #2 (40 pts): Write a Code according to the circuit shown in Figure 1 and the given requirements below. Figure 1. Keypad circuit This code is going to work based on a number guess game.  The first player will enter a four-digit number by using the number pad. All the digits should be different. (It is not needed to be checked in software). The entered digits will be seen on the first line of the LCD screen during...

  • C++, data structure Write a program that plays a game called "guess the state, guess the...

    C++, data structure Write a program that plays a game called "guess the state, guess the capital". How do you play? The program randomly selects a state or a state capital. The program asks the player to guess the state's capital (or the capital's state). The program reads the user's guess; and, tells the user if its guess is right, or if the guess is wrong, tells the user that its guess is wrong and displays the correct answer. Before...

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