Question: Modify the C + + and header files attached in the program and write the code for the followingfunctions:a . Move board up : move

Modify the C++ and header files attached in the program and write the code for the followingfunctions:a. Move board up : move_up(int board[][5], int numrows)b. Move board down : move_down(int board[][5], int numrows)c. Move board left : move_left(int board[][5], int numrows)d. Move board right : move_right(int board[][5], int numrows)
#include
#include
#include
using namespace std;
void move_left(int board[][5], int numrows =5)
{
for (int row =0; row <5; row++){
for (int col =0; col < numrows -1; col++){
if ( board[row][col]==0){
board[row][col]== board[row][col +1];
board[row][col +1]=0;
}
}
}
}
void move_right(int board[][5], int numrows =5)
{
for (int row =0; row <5; row++){
for (int col = numrows -1; col >0; col--){
if ( board[row][col]==0){
board[row][col]== board[row][col -1];
board[row][col -1]=0;
}
}
}
}
void move_up(int board[][5], int numrows =5)
{
for (int col =0; col <5; col++){
for (int row =0; row < numrows -1; row++){
if ( board[row][col]==0){
board[row][col]== board[row +1][col];
board[row +1][col]=0;
}
}
}
}
void move_down(int board[][5], int numrows =5)
{
for (int col =0; col <5; col++){
for (int row = numrows -1; row >0; row--){
if ( board[row][col]==0){
board[row][col]== board[row -1][col];
board[row -1][col]=0;
}
}
}
}
void print_board(int board[][5], int numrows =5)
{
cout << endl <<"\t-----------------------------------------"<< endl;
for (int r =0; r < numrows; r++)
{
for (int c =0; c <5; c++)
{
if(board[r][c]>0)
cout <<"\t|"<< right << setw(6)<< setfill('')<< board[r][c];
else
cout <<"\t|"<< right << setw(6)<< setfill('')<<"";
//cout << board[r][c]<<"\t|\t";
}
cout <<"\t|"<< endl;
cout <<"\t-----------------------------------------"<< endl;
}
cout <<"\t"<< endl << endl;
}
void insert_random(int board[][5], int numrows =5)
{
int r, c;
//count empty
int empty_count =0;
for (int r =0; r < numrows; r++)
{
for (int c =0; c <5; c++)
{
if (board[r][c]==0)
empty_count++;
}
}
if (empty_count >0)
{
while (true)
{
//generate random location r, c
r = rand()% numrows;
c = rand()% numrows;
//check if empty
if (board[r][c]==0)
{
//add number randomly {2,4}
board[r][c]=2*(1+(rand()%2));
break;
}
}
}
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!