Answered step by step
Verified Expert Solution
Link Copied!

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.

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

--------------------------------------------------------------------------------------------

Here's the Connect 4 code.

#include  using 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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Databases And Information Systems Second East European Symposium Adbis 98 Poznan Poland September 1998 Proceedings Lncs 1475

Authors: Witold Litwin ,Tadeusz Morzy ,Gottfried Vossen

1st Edition

3540649247, 978-3540649243

More Books

Students also viewed these Databases questions