Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

USING C++ The program will prompt the user for the filename of the game he or she is currently working on and display the board

USING C++

The program will prompt the user for the filename of the game he or she is currently working on and display the board on the screen. The user will then be allowed to interact with the game by selecting which square he or she wishes to change. While the program will not solve the game for the user, it will ensure that the user has not selected an invalid number. If the user types 'S' in the prompt, then the program will show the user the possible valid numbers for a given square. When the user is finished, then the program will save the board to a given filename and exit.

Interface Design

Consider a game saved as myGame.txt:

7 2 3 0 0 0 1 5 9 6 0 0 3 0 2 0 0 8 8 0 0 0 1 0 0 0 2 0 7 0 6 5 4 0 2 0 0 0 4 2 0 7 3 0 0 0 5 0 9 3 1 0 4 0 5 0 0 0 7 0 0 0 3 4 0 0 1 0 3 0 0 6 9 3 2 0 0 0 7 1 4 

Note that '0' corresponds to an unknown value. The following is an example run of the program.

Program starts

An example of input is underlined.

Where is your board located? myGame.txt

With the filename specified, the program will display a menu of options:

Options: ? Show these instructions D Display the board E Edit one square S Show the possible values for a square Q Save and quit 

After this, the board as read from the file will be displayed:

 A B C D E F G H I 1 7 2 3| |1 5 9 2 6 |3 2| 8 3 8 | 1 | 2 -----+-----+----- 4 7 |6 5 4| 2 5 4|2 7|3 6 5 |9 3 1| 4 -----+-----+----- 7 5 | 7 | 3 8 4 |1 3| 6 9 9 3 2| |7 1 4 

Here, the user will be prompted for a command (the main prompt).

 Z

Please note that you will need a newline, a carat ('>'), and a space before the prompt.

The next action of the program will depend on the user's command. If the user types an invalid command, then the following message will be displayed:

ERROR: Invalid command

Show Instructions

If the user types '?', then the menu of options will be displayed again. These are the same instructions that are displayed when the program is first run.

Display the Board

If the user types 'D', then the board will be redrawn. This is the same as the drawing of the board when the program is first run.

Save and Quit

If the user types 'Q', then he or she will be prompted for the filename:

What file would you like to write your board to: newGame.txt

The program will display the following message:

Board written successfully

Then the program will terminate.

Edit One Square

If the user types 'E', then the program will prompt him for the coordinates and the value for the square to be edited:

What are the coordinates of the square: A1

If the value is invalid or if the square is already filled, then the program will display one of the following message and return to the main prompt:

ERROR: Square 'zz' is invalid
ERROR: Square 'A1' is filled

With a valid coordinate, then the program next prompts the user for the value:

What is the value at 'A1': 9

If the user types a value that is outside the accepted range (1 value 9) or does not follow the rules of Sudoku, then a message appears and the program returns to the main prompt:

ERROR: Value '9' in square 'A1' is invalid

Show Possible Values

If the user types 'S', then the program will prompt him for the coordinates and display the possible values:

What are the coordinates of the square: A1

The same parsing logic applies here as for the Edit One Square case. Once the user has selected a valid coordinate, then the program will display the possible values:

The possible values for 'A1' are: 1, 5, 8, 9

After the message appears, the program returns to the main prompt.

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

Recommended Textbook for

Real Time Database Systems Architecture And Techniques

Authors: Kam-Yiu Lam ,Tei-Wei Kuo

1st Edition

1475784023, 978-1475784022

More Books

Students also viewed these Databases questions