Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

For this assignment, implement and use the methods for a class called LoShuMagic

ID: 3777746 • Letter: F

Question

For this assignment, implement and use the methods for a class called LoShuMagicSquare that will be used to verify solutions for Lo Shu Magic Squares in C++.

The data members for the class are:

an integer symbolic constant that holds the maximum number of rows in a two dimensional array. Use a value of 3.

an integer symbolic constant that holds the maximum number of columns in a two dimensional array. Use a value of 3.

a two-dimensional array of integers with 3 rows and 3 columns that will hold the possible solution

Constructor:

This class has one constructor that should initialize the two-dimensional array of integers. It takes no arguments.

The array should be initialized to hold 0s in all 9 elements.

Methods:

void fillSquare( const char [] )

This is a public method that will fill the two-dimensional array data member with information that is read from a file. It takes 1 argument: an array of constant characters that represents the name of a file that holds the information to place into the array. It returns nothing.

This method should open the file that's name is passed in via the argument and verify that it opened correctly. Once the file has been correctly opened, a nested loop should be used to read the values into the array. After all of the values have been placed in the array, the file should be closed.

The input file contains exactly 9 numbers, arranged in 3 rows of 3 columns each, and separated by whitespace. For example:

void printSquare()

This is a public method that will display the two-dimensional array to the screen as 3 rows or 3 columns (the same way the numbers appear in the input file). It takes no arguments and returns nothing.

bool isMagic()

This is a public method that will determine if the two-dimensional array contains a valid Lo Shu Magic Square solution. It takes no arguments and returns a boolean: true if the solution is valid or false if the solution is not valid.

As mentioned earlier, a valid solution is one where all 9 digits are used one time and all of the rows, columns, and diagonals add up to the same value.

For main() use:

There are 4 input files that are being referenced in main(). They are:

loshu_puzzle1.txt

---------

loshu_puzzle2.txt

---------

loshu_puzzle3.txt

---------

loshu_puzzle4.txt

---------

Helpful info:

The Lo Shu Magic Square is an arrangement of the digits 1 through 9 in a 3x3 grid such that:

each digit is only used one time

the sum of the each row, column, and diagonal all add up to the same value.

Explanation / Answer

#include<stdio.h>
#include<conio.h>

void Board();
void PlayerX();
void PlayerO();
void Player_win();
void check();
int win=0,wrong_X=0,wrong_O=0,chk=0;

char name_X[30];
char name_O[30];
int pos_for_X[3][3];
int pos_for_O[3][3];
int pos_marked[3][3];

void main()

               }
               printf(" ");
               clrscr();
               printf(" Enter the name of the player enjoying for 'X': ");
               fflush(stdin);
               gets(name_X);
               printf(" Enter the name of the player enjoying for 'O': ");
               fflush(stdin);
               gets(name_O);
               Board();
               for(;;)
              
}
void PlayerO()

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote