Assignment 08

Due: Tuesday, May 4, 2021 at noon 100 pts

So, this assignment is going to be a little different. First, I'm using a font color that is truly awefull. Next, this is individual work - no more team work.

Background: Blah blah blah.

The Problem: In this program, you will create and display for the user a "magic skware". We purposely misspelled it because we're not sure if that's the proper term. Here's what you will create: your code will create a puzzle that is a N x N grid of integers with the property that the sums of the individual rows and the sums of the individual columns are given, and the "player" has to fill the grid with integers 1 ... 7 so that the sums are satisfied.

So, in this example, the player would have to fill each individual box with an integer 1, 2, ... , 7 so that the sum of the first row would be 44, the sum of the second column is 45, etc. Being as that this is a really big, hard to solve problem, your code is to actually to give the player most of the answer. That is, your code will show all but a few of the values in the grid. Here's an example of such a puzzle. Here the blanks have to be figured out so the sums are satisfied.

Specifications:

  • Your main function should welcome the user and ask if the user wishes to play a puzzle. If yes, user is prompted for size and a puzzle (a magic skware) is presented (described below).

  • Size of the grid is read in at run-time, an integer between 6 and 10, inclusive. Values outside this range are to be re-prompted.

  • After a puzzle is presented, your code should then output some statement like, "Here's your puzzle....solve it if you can!" Then output a succeeding statement, "Wanna solution?" Answering yes to this would prompt your code to solve the puzzle and output the solution. It will then use the == operator to compare the solution it generates to the copy of the puzzle your code will make (described below), and output a statement about that comparison (i.e. "generated solution matches (or doesn't match) the original solution"). It should be noted that it is possible to have two or more valid solutions to any given puzzle.

  • Your code should continue prompting the user "to do another" until a negative response. A size for the puzzle is prompted for each time.

  • For the initial presentation of the puzzles, five (5) values are left un-revealed when displaying the puzzle. All values are shown when displaying the entire solution.

  • Your code will use dynamic memory and a two-D array of pointers for the puzzle tableau.

  • The puzzle tableau is to be part of a class you will call magic_skware. If you like brevity, call it "skware".

  • Your only constructor is passed the size and it will fully construct the tableau with all entries and sums (without displaying it). This is really easy - randomly fill the table and add up the sums.

  • Every time a puzzle is created, use your copy constructor to create a copy called soln.

  • The class will have a member function called display_puzzle that will

    • randomly choose 5 (five) positions in the grid and replace the entries (answer values) with -1, effectively destroying the complete solution to the puzzle.

    • output the entire tableau with sums but does not print the -1 entries, printing a blank instead (see small example above).

  • The class will have a member function called solve that will solve the puzzle and then display it. This will be the messiest part of this assignment. Good luck.

  • The class is to have an appropriate destructor defined and used when appropriate.

  • The class is to have an appropriate copy constructor defined.

  • The class is to have an appropriate copy assignment operator defined.

  • The class is to have an overloaded == operator defined.

Comments: Think carefully how you should code this assignment. This program has the potential to generate many puzzles, puzzles that will each grab a lot of memory. It would be wise that you code so that each time a puzzle is generated, it is generated in its own scope so that, when that scope is exited by execution, that puzzle goes away before the next puzzle is generated. Remember, destructors are called automatically when the object goes out of scope. If you just keep generating puzzles in the same scope before the program ends, then you keep grabbing more and more memory from the system.

Of course, you are only to use what we have taught you in this course. Some of you might realize that a good way to solve the puzzle is by using recursion. But we didn't teach this, so don't use it. However, if you want to apply that technique to solving the general problem (no grid entries shown), have at it. But you must submit a solution using only what we have shown you for the above described program.

Also, there are different ways to solve the puzzles. Think a while before you start coding; you might think of a better way.

Optionals: If you are good...really good...you might be able to think of a way to code this program so as to be able to solve these puzzles without any of the entries in the grid given. Do it if you can.

Have fun and don't forget to ask if you have any questions.