Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Computer Engineering Expert

Start with the base code given below. Get it to compile and run as shown. THEN, make the modifications shown below.

Important notes:

  • The modifications are the assignment!
  • This assignment will require you to think, research and explore, it is not a step-by-step!
  • Work on this assignment on your own!

BASE CODE:

#include

#include

#include

using namespace std;

const int NUM_ROWS = 8;

const int NUM_COLS = 8;

// **************** CLASS: CELL *******************

class Cell {

     char piece;

     char color;

public:

     Cell();

     void place(char color, char piece);

     string getPiece();

};

Cell::Cell() {

     piece = ' ';

     color = ' ';

}

void Cell::place(char newColor, char newPiece) {

     assert((newColor == 'W') || (newColor == 'B'));

     color = newColor;

     assert((newPiece == 'R') || (newPiece == 'K') ||

(newPiece == 'B') || (newPiece == 'Q') ||

(newPiece == 'K') || (newPiece == 'N') ||

(newPiece == 'P'));

     piece = newPiece;

}

string Cell::getPiece() {

     string result = "";

     result = result.append(1, color);

     result = result.append(1, piece);

     return result;

}

// **************** CLASS: BOARD *******************

class Board {

     Cell board[NUM_ROWS][NUM_COLS]; // <-- Not a good idea in the long run

     void displayLine();

public:

     Board();

     void displayBoard();

};

Board::Board() {

     board[0][0].place('B', 'R');

     board[0][1].place('B', 'N');

     board[0][2].place('B', 'B');

     board[0][3].place('B', 'Q');

     board[0][4].place('B', 'K');

     board[0][5].place('B', 'B');

     board[0][6].place('B', 'N');

     board[0][7].place('B', 'R');

     for (int c = 0; c < NUM_COLS; c++) {

          board[1][c].place('B', 'P');

     }

     board[NUM_COLS - 1][0].place('W', 'R');

     board[NUM_COLS - 1][1].place('W', 'N');

     board[NUM_COLS - 1][2].place('W', 'B');

     board[NUM_COLS - 1][4].place('W', 'K');

     board[NUM_COLS - 1][3].place('W', 'Q');

     board[NUM_COLS - 1][5].place('W', 'B');

     board[NUM_COLS - 1][6].place('W', 'N');

     board[NUM_COLS - 1][7].place('W', 'R');

     for (int c = 0; c < NUM_COLS; c++) {

          board[NUM_COLS-2][c].place('W', 'P');

     }

}

void Board::displayLine() {

     cout << endl;

     for (int x = 0; x < NUM_COLS; x++) {

          cout << "    | ";

     }

     cout << endl;

     for (int x = 0; x < NUM_COLS; x++) {

          cout << "----| ";

     }

     cout << endl;

}

void Board::displayBoard() {

     cout << endl << "CURRENT BOARD:" << endl << endl;

     for (int r = 0; r < NUM_ROWS; r++) {

          for (int c = 0; c < NUM_COLS; c++) {

              cout << " " << board[r][c].getPiece() << " | ";

          }

          displayLine();

     }

     cout << endl << endl;

}

int main() {

     Board board;

     board.displayBoard();

     return 0;

}

OUTPUT FROM BASE CODE:

CURRENT BOARD:

 BR |  BN |  BB |  BQ |  BK |  BB |  BN |  BR |

    |     |     |     |     |     |     |     |

----| ----| ----| ----| ----| ----| ----| ----|

 BP |  BP |  BP |  BP |  BP |  BP |  BP |  BP |

    |     |     |     |     |     |     |     |

----| ----| ----| ----| ----| ----| ----| ----|

    |     |     |     |     |     |     |     |

    |     |     |     |     |     |     |     |

----| ----| ----| ----| ----| ----| ----| ----|

    |     |     |     |     |     |     |     |

    |     |     |     |     |     |     |     |

----| ----| ----| ----| ----| ----| ----| ----|

    |     |     |     |     |     |     |     |

    |     |     |     |     |     |     |     |

----| ----| ----| ----| ----| ----| ----| ----|

    |     |     |     |     |     |     |     |

    |     |     |     |     |     |     |     |

----| ----| ----| ----| ----| ----| ----| ----|

 WP |  WP |  WP |  WP |  WP |  WP |  WP |  WP |

    |     |     |     |     |     |     |     |

----| ----| ----| ----| ----| ----| ----| ----|

 WR |  WN |  WB |  WQ |  WK |  WB |  WN |  WR |

    |     |     |     |     |     |     |     |

----| ----| ----| ----| ----| ----| ----| ----|

MODIFICATIONS:

Add three lines to main as shown below. Modify the program by adding whatever is necessary to get it to work as shown in the output below.

NEW MAIN:

int main() {

     Board board;

     board.displayBoard();

     string piece = board.take(0, 1);

     board.place(2, 2, piece.at(0), piece.at(1));

     board.displayBoard();

     return 0;

}

NEW OUPUT:

CURRENT BOARD:

 BR |  BN |  BB |  BQ |  BK |  BB |  BN |  BR |

    |     |     |     |     |     |     |     |

----| ----| ----| ----| ----| ----| ----| ----|

 BP |  BP |  BP |  BP |  BP |  BP |  BP |  BP |

    |     |     |     |     |     |     |     |

----| ----| ----| ----| ----| ----| ----| ----|

    |     |     |     |     |     |     |     |

    |     |     |     |     |     |     |     |

----| ----| ----| ----| ----| ----| ----| ----|

    |     |     |     |     |     |     |     |

    |     |     |     |     |     |     |     |

----| ----| ----| ----| ----| ----| ----| ----|

    |     |     |     |     |     |     |     |

    |     |     |     |     |     |     |     |

----| ----| ----| ----| ----| ----| ----| ----|

    |     |     |     |     |     |     |     |

    |     |     |     |     |     |     |     |

----| ----| ----| ----| ----| ----| ----| ----|

 WP |  WP |  WP |  WP |  WP |  WP |  WP |  WP |

    |     |     |     |     |     |     |     |

----| ----| ----| ----| ----| ----| ----| ----|

 WR |  WN |  WB |  WQ |  WK |  WB |  WN |  WR |

    |     |     |     |     |     |     |     |

----| ----| ----| ----| ----| ----| ----| ----|

CURRENT BOARD:

 BR |     |  BB |  BQ |  BK |  BB |  BN |  BR |

    |     |     |     |     |     |     |     |

----| ----| ----| ----| ----| ----| ----| ----|

 BP |  BP |  BP |  BP |  BP |  BP |  BP |  BP |

    |     |     |     |     |     |     |     |

----| ----| ----| ----| ----| ----| ----| ----|

    |     |  BN |     |     |     |     |     |

    |     |     |     |     |     |     |     |

----| ----| ----| ----| ----| ----| ----| ----|

    |     |     |     |     |     |     |     |

    |     |     |     |     |     |     |     |

----| ----| ----| ----| ----| ----| ----| ----|

    |     |     |     |     |     |     |     |

    |     |     |     |     |     |     |     |

----| ----| ----| ----| ----| ----| ----| ----|

    |     |     |     |     |     |     |     |

    |     |     |     |     |     |     |     |

----| ----| ----| ----| ----| ----| ----| ----|

 WP |  WP |  WP |  WP |  WP |  WP |  WP |  WP |

    |     |     |     |     |     |     |     |

----| ----| ----| ----| ----| ----| ----| ----|

 WR |  WN |  WB |  WQ |  WK |  WB |  WN |  WR |

    |     |     |     |     |     |     |     |

----| ----| ----| ----| ----| ----| ----| ----|

 

 

Computer Engineering, Engineering

  • Category:- Computer Engineering
  • Reference No.:- M91424052
  • Price:- $30

Guranteed 24 Hours Delivery, In Price:- $30

Have any Question?


Related Questions in Computer Engineering

In 2005 team dad used a toyota truck with a system of

In 2005, Team DAD used a Toyota truck with a system of spinning lasers as its "visual" system. What advantages and or disadvantage does such a system have compared to camera-based systems?

Question what is the syntax of the while construct in the c

Question : What is the syntax of the "while" construct in the c programming language? Show how the while construct can give the functionality of the "for" construct, for (init-phrase; test-cond; incr-phrase)

Roberto is the network administrator for an international

Roberto is the network administrator for an international law firm with offices and customers in North America, South America, Africa, and the Middle East. The lawyers frequently contact each other via e-mail, use the In ...

Question suppose a network with 109 hostnames not including

Question : Suppose a network with 10^9 hostnames (not including the names of the nameservers themselves) uses non-recursive DNS. Assume that there is a single root nameserver, multiple local nameservers, and M levels of ...

With respect to tm4c123 arm cortex m4 processorhow many

With respect to TM4C123 ARM Cortex M4 Processor How many machine cycles are required to process first line of ISR after an interrupt occurs? What are the other benefits of NVIC to process interrupt more efficiently?

Question write a 2 page briefing paper in which you present

Question: Write a 2 page briefing paper in which you present a summary of the issues (including a description of the types of intellectual property which may have been stolen). You should then summarize your research int ...

Question 1 designing team and team identityusing the

Question: 1. Designing Team and Team Identity. Using the Internet, team should read at least 5 academically reviewed articles on designing. 2. Please do not change the wording of the original summary. Include the team me ...

Mary kate is a project manager in the it department for a

Mary Kate is a project manager in the IT department for a university. She has been asked to manage a project to create faculty intranet. The university has multiple campuses in various locations, and professors and other ...

Question summary using an organization of your

Question: Summary: Using an organization of your choice: Develop a Complete Disaster Recovery Plan to be submitted to the executive board of your company. Please note that this is a formal writing, all references (peer-r ...

Create a menu form you will create a menu form using form

Create a Menu Form You will create a menu form using Form Design view. Add three command buttons for the three forms in the database, and then add three command buttons for the three reports in the database. a. Open the ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As