Answered step by step
Verified Expert Solution
Question
1 Approved Answer
I am including my code that I have already written, I just cannot figure out what to write in the boolean function winner ( )
I am including my code that I have already written, I just cannot figure out what to write in the boolean function winner in order for my game to announce that it is over and show number of moves.
Game::Game
numMoves ;
int num ;
for int i ; i ; i
for int j ; j ; j
gameBoardij num;
void Game::displayGame
for int i ; i ; i
for int j ; j ; j
cout gameBoardij;
cout endl;
bool Game::winner
for int i ; i ; i
for int j ; j ; j
if gameBoardij
return false;
void Game::swapPositionsint num int num
int row row;
int col col;
for int i ; i ; i
for int j ; j ; j
if gameBoardij num
row i;
col j;
if gameBoardij num
row i;
col j;
int storeNum gameBoardrowcol;
gameBoardrowcol gameBoardrowcol;
gameBoardrowcol storeNum;
displayGame;
cout endl;
numMoves;
int Game::getMoves
return numMoves;
void Game::addRows
int sum ;
for int i ; i ; i
for int j ; j ; j
sum gameBoardij;
cout "Row i: sum endl;
sum ;
void Game::addColumns
int sum ;
for int i ; i ; i
for int j ; j ; j
sum gameBoardji;
cout "Column i: sum endl;
sum ;
void Game::addDiagonals
int sum;
int sum;
for int i ; i ; i
for int j ; j ; j
if i j
sum gameBoardij;
if i j
sum gameBoardij;
cout "Diagonal Left: sum endl;
cout
"Diagonal Right: sum endl;
int main
Game all;
cout "Let's Play All endl;
cout To win, swap numbers until each line equals endl;
cout endl;
alldisplayGame;
cout endl;
while allwinner
int num;
int swapNum;
cout "Enter a digit to move: ; cin num;
cout "Enter a digit to swap with: ; cin swapNum;
allswapPositionsnum swapNum;
cout "Board not complete!" endl;
alladdRows;
alladdColumns;
alladdDiagonals;
cout "Board complete!" endl;
cout "Number of moves: allgetMoves;
return ;
I need assistance with making the boolean function show that each line's sum is now equal to in order to end the program. Output should look like picture.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started