Answered step by step
Verified Expert Solution
Question
1 Approved Answer
(C++), write this code in C++ only please and make sure that all of outputs must be the same with the following instruction. Also, you
(C++),
write this code in C++ only please and make sure that all of outputs must be the same with the following instruction.
Also, you shouldn't use any pointer.
I attached the Connect-4 code at the bottom, which you need to use for this question.
--------------------------------------------------------------------------------------------
Here's the Connect 4 code.
#includeusing namespace std; const int RSIZE = 6; const int CSIZE = 7; const char BLANK = '.'; const char P1 = 'X'; const char P2 = 'O'; char winner(char board[RSIZE][CSIZE]); string play(char board[RSIZE][CSIZE], int col, char who); bool fourInARow(char board[RSIZE][CSIZE], int i, int j, int dr, int dc); void print(char board[RSIZE][CSIZE]); int main() { char board[RSIZE][CSIZE]; for(int i=0; i> ans; string dump; getline(cin, dump); if('1' = 0 && cj = 0 && board[i][j] == board[ci][cj]) // in the board bounds and in a streak { sum++; ci += dr; cj += dc; } ci=i-dr; cj=j-dc; while(ci = 0 && cj = 0 && board[i][j] == board[ci][cj]) // count in the opposite direction too { sum++; ci -= dr; cj -= dc; } return sum >= 4; } string play(char board[RSIZE][CSIZE], int col, char who) { for(int i=RSIZE-1; i >= 0; i--) { if(board[i][col] == BLANK) { board[i][col] = who; return ""; } } return "That column is full (idiot)."; } void print(char board[RSIZE][CSIZE]) { cout General comments: Both parts of this homework relate to the Connect-4 code posted on the website. The general purpose of Connect-4 is to be the first person to get 4-in-a-row. This game has historically been played where you slid chips into columns, so the play is always the lowest available row in the column. See this for more details if you are unfamiliar with the rules For both part A and B of this homework you should not add any couts in your final submission. You may add temporary couts to help debug, but please ensure these are all removed when you do the final submission. Also for both parts, I do not care what "message" you tell the user for the modifications (do whatever you want for this). Also please do not put 'In' characters in the "message" variable Problem A: Saving a game (20 points) Add functionality so the user can type 's' to save the game. When this "save" option is selected, you should put the board exactly as it is shown into the file "save.txt". If "save.txt" already exists, override it with the current board. Note: like in the example, you should still be able to play the game normally after saving. Example 1 (user input is underlined, but many newlines are skipped) General comments: Both parts of this homework relate to the Connect-4 code posted on the website. The general purpose of Connect-4 is to be the first person to get 4-in-a-row. This game has historically been played where you slid chips into columns, so the play is always the lowest available row in the column. See this for more details if you are unfamiliar with the rules For both part A and B of this homework you should not add any couts in your final submission. You may add temporary couts to help debug, but please ensure these are all removed when you do the final submission. Also for both parts, I do not care what "message" you tell the user for the modifications (do whatever you want for this). Also please do not put 'In' characters in the "message" variable Problem A: Saving a game (20 points) Add functionality so the user can type 's' to save the game. When this "save" option is selected, you should put the board exactly as it is shown into the file "save.txt". If "save.txt" already exists, override it with the current board. Note: like in the example, you should still be able to play the game normally after saving. Example 1 (user input is underlined, but many newlines are skipped)
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