Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need help with C++ Homework After adding data points using a .txt file it should look like this I have written some code already, but

Need help with C++ Homework

image text in transcribed

After adding data points using a .txt file it should look like this

image text in transcribed

I have written some code already, but need help with the method to output the number of squares completed at the last token.

 SBoard.hpp #include  //For console i/o #include  //For `string` type #include  //For reading file #include  //For `sscanf()` #include  //For absolute value `abs()` using namespace std; //Eliminate need for `std::` class SBoard { private: char grid[10][10]; int tokens_placed; public: // // Default constructor // SBoard() { //Initialize board for (int i = 0; i  9 || column  9) //Do not place token return -1; //Otherwise place token grid[row][column] = 'x'; //Increment number of tokens placed tokens_placed++; //Return number of squares completed by this move return squaresCompleted(row, column); } // // Squares completed // int squaresCompleted(int row, int col) { //Initialize square count int square_count = 0; //Check column, in row, for an 'x' for (int i = 0; i = 0 && grid[row-a][col] == 'x') { //When found check other column if (grid[row-a][i] == 'x') { //There's a square square_count++; } } //Check higher value row for 'x' if (row + a  

SBoard.cpp

#include  #include  #include "SBoard.hpp" using namespace std; SBoard sboard; //initialize object name int main() { sboard.readPlacementsFromFile("4squares.txt"); sboard.printBoard(); // Display number of tokens placed cout  

Basically, I need to move all the functions to the .cpp file, which should have all the function definitions.. and have the .hpp file have member variables and function headers

and also need to

cout

based on the txt file "4squares.txt"

Write a class called SBoard that represents a 10x10 grid, where a token may be placed at any (row, column) coordinates It should have two data members: a 2D array of char for the grid, and an int to keep track of how many tokens have been placed. It should have a default constructor that initializes all elements of the array to being empty (you can use whatever characters you want to represent that a square is empty or has a token), and also initializes the number of tokens placed (at the beginning there are no tokens on the board) It should have a method named getNumTokens that returns the number of tokens placed so far It should have a method named placeToken that takes two ints (the row and column, in that order). If that location already has a token, or if the row or column are out of the range 0-9, then a token should not be placed and the method should return -1. Otherwise, a token should be placed there and the method should return the number of squares completed by placing that token (where only the four corners are needed to complete a square). For example, if we have the following grid, where x marks each existing token then playing a token at the spot marked # will complete four squares-a 2x2, a 3x3, a 4x4, and a 5x5 (1x1 doesn't count) It should have a method named readPlacementsFromFile that takes a string (the name of the file to read). The file will have the following format: 2 1 2 3 3 0 7 3 Where the left number on each line is the row and the right number is the column. The method should place a token at the coordinates given in each row of the file. To do this, it will call the placeToken method (ignoring the return value). Remember to close the file It's not required, but you'll probably find it useful for testing and debugging to have a method that prints out the board Whether you think of the array indices as being [rowl[column] or [column][row] doesn't matter as long as you're consistent. The files must be named: SBoard.hpp and SBoard.cpp Count 3 Count 4 x..x 5x5 4X4 3x3 2x2 Count2 Count 1 placeToken returns 4

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

Databases And Information Systems 1 International Baltic Conference Dbandis 2020 Tallinn Estonia June 19 2020 Proceedings

Authors: Tarmo Robal ,Hele-Mai Haav ,Jaan Penjam ,Raimundas Matulevicius

1st Edition

303057671X, 978-3030576714

More Books

Students also viewed these Databases questions

Question

What are the best practice recommendations for wired LAN design?

Answered: 1 week ago