Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

(C++ only) write this code in C++ only please and make sure that all of outputs must be the same with the following instruction. Also,

(C++ only)

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 transcribedimage text in transcribedimage text in transcribedimage text in transcribed

#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]); ---------------------------------------------------------------------------------------------------------------- Source code for this question 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   Problem B: Loading games (20 points) Add functionality to either the base connectFour.cpp or your answer to part A to press '' to load a game from "save.txt". If this file does not exist, you should not change the current board. Otherwise, you should change the board and let the user play the saved board normally. Note: You may assume the the "save.txt" is in a valid board for the game. Example 1 (user input is underlined, note that the game would continue but I do not show more): 1234567 Which column do you wish to play in? Or (s)ave/(1) oad? 1234567  Problem B: Loading games (20 points) Add functionality to either the base connectFour.cpp or your answer to part A to press '' to load a game from "save.txt". If this file does not exist, you should not change the current board. Otherwise, you should change the board and let the user play the saved board normally. Note: You may assume the the "save.txt" is in a valid board for the game. Example 1 (user input is underlined, note that the game would continue but I do not show more): 1234567 Which column do you wish to play in? Or (s)ave/(1) oad? 1234567

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

More Books

Students also viewed these Databases questions