Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Part B: The Cellid Type [35% = 23% test program + 2% code + 10% documentation) In Part B, you will add a structured record

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

Part B: The Cellid Type [35% = 23% test program + 2% code + 10% documentation) In Part B, you will add a structured record (struct) named CellId to identify a position on the game board by its row and column. You will also add and document some functions that work with CellIds. Put the record declaration and function prototypes in CellId.h and the function implementations in CellId.cpp. Note: The Cellid type is not encapsulated. Client code is expected to use the row and column fields directly By the end of Part B, you will have functions with the following prototypes: Cellid toCellid (int rowl, int column1); bool isOnBoard (const Cellid& cell_id); bool isOnBoard (const std::string& str); Cellid toCellid (const std::string& str); void printCellid (const Cellid& cell_id); II Perform the following steps: 1. In CellId.h, define the Cellid structured record to represent a cell position. It should have member fields named row and column, both of which should be ints. 2. Copy in the function prototypes. 3. In Cellid.cpp, include the , , and libraries as well as "BoardSize.h" and "CellId.h". Remember to put using namespace std;. The function prototypes use the string type, so you will need to include the library in Cellid.h as well. 4. In Cellid.cpp, add an implementation for the toCellid function that takes row and column parameters. First, it should create a local Cellid variable. Then it should set the CellId's row and column. Finally, it should return the CellId. 5. Add an implementation for the isOnBoard function that takes a constant reference to a CellId as a parameter. It should return a value indicating whether or not that Cellid is on the board. To be on the board, the cell row and column must both be greater than or equal to o and strictly less than BOARD_SIZE. 6. Add an implementation for the printCellid function. It should print the cell name to standard output (cout). Reminder: The cell name is always an uppercase letter, representing a row, followed by a digit, representing a column. Hint: You have functions that give the name for a row and the name for a column. 7. Add an implementation for the isOnBoard function that takes a constant reference to a string (const string&) as a parameter. It should return a value indicating whether or not that string names a cell on the board. To name a cell, the string must be composed of exactly 2 characters. If the length of the string is not 2, you should immediately return false. A cell name must consist of: an uppercase letter representing a row, followed by a digit representing a column. If the string names a cell and that cell is on the board, the function should return true. Otherwise, it should return false. Hint: If a cell is on the board, the row name will be at least 'A' and strictly less than 'A' BOARD_SIZE. Similarly, the column name will be at least 'o' and strictly less than 'o' BOARD_SIZE. 8. Add an implementation for the toCellid function that takes a constant reference to a string as a parameter. It should create, initialize, and return a CellId corresponding to the cell named in the parameter string. Hint: If you extract one character from the string to be the column number, you will have a character value such as '5', which is not equal to the integer 5. For a character stored in char variable ch, you need to compute ch 'O' to get the corresponding integer. 9. Add a precondition to the toCellid (const std::string& str) function that requires isOnBoard to return true when applied to the string parameter. Enforce the precondition using an assert. 0. Test your Cellid module using the Test CellId2.cpp program provided. You will need TestHelper.h and TestHelper.cpp. To compile, you should compile BoardSize.cpp, CellId.cpp, Test CellId2.cpp, and TestHelper.cpp together. Note: Whenever you use #include to include a .h file in your folder, always compile the corresponding .cpp file when creating your executable file. 1. Write interface specifications (comments in a certain format) for the functions in Cellid.h in the format described in class and in Section 4a of the online notes. For example, the comments in Player.h give interface specifications for the functions there. Hint: When documenting a precondition, the easiest and most helpful way is just to put the code from inside the assert. For example: // Pecondition(s): // n > 0 Note: Interface specifications are written for other programmers (or you in the future) who want to use your module and need to know how to do so. Assume that the client who wants to use your module can (and will look at your interface (.h) file but cannot look at your implementation (.cpp) file. Part B: The Cellid Type [35% = 23% test program + 2% code + 10% documentation) In Part B, you will add a structured record (struct) named CellId to identify a position on the game board by its row and column. You will also add and document some functions that work with CellIds. Put the record declaration and function prototypes in CellId.h and the function implementations in CellId.cpp. Note: The Cellid type is not encapsulated. Client code is expected to use the row and column fields directly By the end of Part B, you will have functions with the following prototypes: Cellid toCellid (int rowl, int column1); bool isOnBoard (const Cellid& cell_id); bool isOnBoard (const std::string& str); Cellid toCellid (const std::string& str); void printCellid (const Cellid& cell_id); II Perform the following steps: 1. In CellId.h, define the Cellid structured record to represent a cell position. It should have member fields named row and column, both of which should be ints. 2. Copy in the function prototypes. 3. In Cellid.cpp, include the , , and libraries as well as "BoardSize.h" and "CellId.h". Remember to put using namespace std;. The function prototypes use the string type, so you will need to include the library in Cellid.h as well. 4. In Cellid.cpp, add an implementation for the toCellid function that takes row and column parameters. First, it should create a local Cellid variable. Then it should set the CellId's row and column. Finally, it should return the CellId. 5. Add an implementation for the isOnBoard function that takes a constant reference to a CellId as a parameter. It should return a value indicating whether or not that Cellid is on the board. To be on the board, the cell row and column must both be greater than or equal to o and strictly less than BOARD_SIZE. 6. Add an implementation for the printCellid function. It should print the cell name to standard output (cout). Reminder: The cell name is always an uppercase letter, representing a row, followed by a digit, representing a column. Hint: You have functions that give the name for a row and the name for a column. 7. Add an implementation for the isOnBoard function that takes a constant reference to a string (const string&) as a parameter. It should return a value indicating whether or not that string names a cell on the board. To name a cell, the string must be composed of exactly 2 characters. If the length of the string is not 2, you should immediately return false. A cell name must consist of: an uppercase letter representing a row, followed by a digit representing a column. If the string names a cell and that cell is on the board, the function should return true. Otherwise, it should return false. Hint: If a cell is on the board, the row name will be at least 'A' and strictly less than 'A' BOARD_SIZE. Similarly, the column name will be at least 'o' and strictly less than 'o' BOARD_SIZE. 8. Add an implementation for the toCellid function that takes a constant reference to a string as a parameter. It should create, initialize, and return a CellId corresponding to the cell named in the parameter string. Hint: If you extract one character from the string to be the column number, you will have a character value such as '5', which is not equal to the integer 5. For a character stored in char variable ch, you need to compute ch 'O' to get the corresponding integer. 9. Add a precondition to the toCellid (const std::string& str) function that requires isOnBoard to return true when applied to the string parameter. Enforce the precondition using an assert. 0. Test your Cellid module using the Test CellId2.cpp program provided. You will need TestHelper.h and TestHelper.cpp. To compile, you should compile BoardSize.cpp, CellId.cpp, Test CellId2.cpp, and TestHelper.cpp together. Note: Whenever you use #include to include a .h file in your folder, always compile the corresponding .cpp file when creating your executable file. 1. Write interface specifications (comments in a certain format) for the functions in Cellid.h in the format described in class and in Section 4a of the online notes. For example, the comments in Player.h give interface specifications for the functions there. Hint: When documenting a precondition, the easiest and most helpful way is just to put the code from inside the assert. For example: // Pecondition(s): // n > 0 Note: Interface specifications are written for other programmers (or you in the future) who want to use your module and need to know how to do so. Assume that the client who wants to use your module can (and will look at your interface (.h) file but cannot look at your implementation (.cpp) file

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

Mastering Real Time Analytics In Big Data A Comprehensive Guide For Everyone

Authors: Lennox Mark

1st Edition

B0CPTC9LY9, 979-8869045706

More Books

Students also viewed these Databases questions

Question

Explain what is meant by the terms unitarism and pluralism.

Answered: 1 week ago