Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

ALL IN C++: Lab 1:Micro Sudoku For this lab, you will implement a simple number game. The goal of the game is to fill in

ALL IN C++:

Lab 1:Micro Sudoku For this lab, you will implement a simple number game. The goal of the game is to fill in a 3x3 board with the numbers 1 - 4 (inclusive), but a number cannot appear next to itself in a row or column. The numbers are read from a file and presented to the user two at a time. The user can choose one of the numbers or pass. There are three passes allowed in the game; the user loses the game on the fourth pass. The game is won if the board is successfully filled with numbers.

Program Specifications Your program should Show the user the board before each turn and when the game is over On each turn, display the two numbers the user can choose from. Let the user pick one of the numbers to place or pass. If the user chooses a number, ask where the user wants to put it. Use 0-based indexing.

If the user passes, and that is the fourth time the user passes, the game should imme- diately end. The user loses the game.

The game should end, and the player wins, if the entire board is filled with numbers. Each time the user places a number, you should validate the users input. Do not allow the user to pick an invalid location (row/column out of range), pick a place that already has a number, or put a number next to itself. For example, if the first row is [1, , 3], a valid move would be to put a 2 in the second spot. An invalid move would be to try to put a 1 or a 3 in the second spot, since the same number cannot appear next to itself. You should also validate any menu choices the user gives. For instance, do not allow the user to choose a number to place that isnt one of the available options. You never have to validate that the user has given you the proper datatype, though you can easily by using something like if(cin >> num). If the input cannot be stored in num, this statement is false. Hints and Tips Click here for an example of using 2D arrays Click here for an example of how to read from a file To align the board, check out the iomanip header (http://www.cplusplus.com/ reference/iomanip/)

1

A262: Lab 1

Check list Each of these items is worth 0.5 points of your grade. Your name (and your partners name, if you have one) must be in a comment at the top of your source file(s) Your code is generally well formatted, meaning your code is indented properly and each line of code gets its own line.

All output is grammatically correct with respect to capitalization and sentence struc- ture. Two exceptions that will be allowed to break standard grammar rules are sentence

fragments and punctuation at the end of a sentence. All output is free of typos, including spelling everything correctly. Beware of typos such as teh or DOuble CAptials Example Output Here is an example of what your programs output should look like. It is vitally important that your program takes input in the same order as shown here. User input is in blue. ---------------------------------------------------------------------- The goal of this game is to arrange numbers in the 3x3 grid so that the same number does not appear next to itself in either a row or a column. Each round, you will choose between two provided numbers, or you can pass. You can pass three times. The fourth time, you lose! ---------------------------------------------------------------------- Round 0 ------------- | | | | | | | | | | | | ------------- You got numbers 3, 3 Choose number (-1 to pass): 3 Enter row and column numbers: 0 0

2

A262: Lab 1

Round 1 ------------- | 3| | | | | | | | | | | ------------- You got numbers 4, 2 Choose number (-1 to pass): 4 Enter row and column numbers: 1 0

Round 2 ------------- | 3| | | | 4| | | | | | | ------------- You got numbers 4, 3 Choose number (-1 to pass): 4 Enter row and column numbers: 2 0 Value cannot be next to same value Enter row and column numbers: 1 1 Value cannot be next to same value Enter row and column numbers: 4 5 Invalid row or column Enter row and column numbers: 0 -4 Invalid row or column Enter row and column numbers: 0 1

Round 3 ------------- | 3| 4| | | 4| | | | | | | ------------- You got numbers 2, 4 Choose number (-1 to pass): 2 Enter row and column numbers: 1 1 3

A262: Lab 1

Round 4 ------------- | 3| 4| | | 4| 2| | | | | | ------------- You got numbers 1, 1 Choose number (-1 to pass): 1 Enter row and column numbers: 0 2

Round 5 ------------- | 3| 4| 1| | 4| 2| | | | | | ------------- You got numbers 3, 1 Choose number (-1 to pass): 3 Enter row and column numbers: 1 2

Round 6 ------------- | 3| 4| 1| | 4| 2| 3| | | | | ------------- You got numbers 1, 3 Choose number (-1 to pass): 3 Enter row and column numbers: 2 0

Round 7 ------------- | 3| 4| 1| | 4| 2| 3| | 3| | | ------------- You got numbers 2, 4

4

A262: Lab 1

Choose number (-1 to pass): 4 Enter row and column numbers: 2 1

Round 8 ------------- | 3| 4| 1| | 4| 2| 3| | 3| 4| | ------------- You got numbers 2, 2 Choose number (-1 to pass): 2 Enter row and column numbers: 2 2

You win!! ------------- | 3| 4| 1| | 4| 2| 3| | 3| 4| 2| ------------- Example of a Loss ---------------------------------------------------------------------- The goal of this game is to arrange numbers in the 3x3 grid so that the same number does not appear next to itself in either a row or a column. Each round, you will choose between two provided numbers, or you can pass. You can pass three times. The fourth time, you lose! ---------------------------------------------------------------------- Round 0 ------------- | | | | | | | | | | | | ------------- You got numbers 3, 3 Choose number (-1 to pass): 3 Enter row and column numbers: 0 0

5

A262: Lab 1

Round 1 ------------- | 3| | | | | | | | | | | ------------- You got numbers 4, 2 Choose number (-1 to pass): -1

Round 2 ------------- | 3| | | | | | | | | | | ------------- You got numbers 4, 3 Choose number (-1 to pass): -1

Round 3 ------------- | 3| | | | | | | | | | | ------------- You got numbers 2, 4 Choose number (-1 to pass): -1

Round 4 ------------- | 3| | | | | | | | | | | -------------

6

A262: Lab 1

You got numbers 1, 1 Choose number (-1 to pass): -1

You lose!! ------------- | 3| | | | | | | | | | | -------------

THIS IS THE STARTER CODE WITH THE .TXT FILE

image text in transcribed

B workspace/X CS262/ main.cpp gameBoard.txt x 1 #include 3 #includefstream 4 5 using namespace std; 6 3 8 int mai 10 1 11 Initialize file 12 ifstream ins("gameBoard.txt"); 13 10 1 11 3 12 1 13 1 15 ISet up the round, etc 16 // Other code... 17 18 I1 Read in two numbers from the file 19 int numl, num2; 20 insnumnum2; 21 cout

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

Discuss the key people management challenges that Dorian faced.

Answered: 1 week ago

Question

How fast should bidder managers move into the target?

Answered: 1 week ago