Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

need three files: SudokuRowChecker.cpp SudokuRowChecker.h User_main.cpp Pointers Continued (Sudoku). The purpose of this assignment is to practice dealing with string data. The goal is to

need three files:

SudokuRowChecker.cpp

SudokuRowChecker.h

User_main.cpp

Pointers Continued (Sudoku).

The purpose of this assignment is to practice dealing with string data. The goal is to work with data declared aschar *(C-string) and also asstring. I think you'll like working with strings much better. Please recall that string is officially known asstd::string.

Sudoku Row Checker

Sudoku is a logic-based number placement puzzle. The objective is to fill a 99 grid so that each column, each row, and each of the nine 33 boxes (also called blocks or regions) contains the digits from 1 to 9 only one time each. For those of you not familiar with this game, you can learn more about it here:https://en.wikipedia.org/wiki/Sudoku(Links to an external site.)

The Sudoku Row Checker class is can be used to validate a string of information. Using string operations, it should verify that each number 1 to 9 is used only one time. Following the class specifications shown below, implement the Sudoku Row Checker class. Implement a suitable testing suite asides from the ones already provided that proves your calculations are correct. You may choose to createee any number of additional methods, but you are required to implement all of the public methods shown below.

SudokuRowChecker

public: SudokuRowChecker( ); // same function name, but with different arguments. You must implement both versions of the setData() function. void setData( const char * s ); void setData( std::string s ); void clear(); bool isValid( ) const; private: string sudokuRow; 

Sample Testing Driver Code

 // test 1, invalid string SudokuRowChecker c1; std::string s1 = "12345678901"; c1.setData(s1); if(c1.isValid()){ std::cout << "1.1. Invalid string, 11 characters string; test failed" << std::endl; } else { std::cout << "1.1. Invalid string, 11 characters string; test passed" << std::endl; } // test 2, invalid c-string SudokuRowChecker c2; std::string s2 = "12345678901"; c2.setData(s2.c_str()); if(c2.isValid()){ std::cout << "2.1. Invalid string, 11 characters c-string; test failed" << std::endl; } else { std::cout << "2.1. Invalid string, 11 characters c-string; test passed" << std::endl; } // test 3, make sure checker is considered invalid after default constructor SudokuRowChecker c3; if(c3.isValid()){ std::cout << "3.1. Invalid string, empty string after initialization; test failed" << std::endl; } else { std::cout << "3.1. Invalid string, empty string after initialization; test passed" << std::endl; } // test 4, make sure checker is considered invalid after setting empty string SudokuRowChecker c4; string s4 = ""; c4.setData(s4); if(c4.isValid()){ std::cout << "4.1. Invalid string, empty string; test failed" << std::endl; } else { std::cout << "4.1. Invalid string, empty string; test passed" << std::endl; } // test 5, make sure checker is considered invalid after setting empty string SudokuRowChecker c5; char s5[] = ""; c5.setData(s5); if(c5.isValid()){ std::cout << "5.1. Invalid string, empty c-string; test failed" << std::endl; } else { std::cout << "5.1. Invalid string, empty c-string; test passed" << std::endl; } // test 6, make sure checker is considered valid with correct string SudokuRowChecker c6; string s6 = "123456789"; c6.setData(s6); if(c6.isValid()){ std::cout << "6.1. Valid string; test passed" << std::endl; } else { std::cout << "6.1. Valid string; test failed" << std::endl; } // test 7, make sure checker is considered valid with correct string SudokuRowChecker c7; char s7[] = "123456789"; c7.setData(s7); if(c7.isValid()){ std::cout << "7.1. Valid string; test passed" << std::endl; } else { std::cout << "7.1. Valid string; test failed" << std::endl; } // test 8, invalid, string shorter than it should be SudokuRowChecker c8; string s8 = "1234"; c8.setData(s8); if(c8.isValid()){ std::cout << "8.1. Invalid string, string too short; test failed" << std::endl; } else { std::cout << "8.1. Invalid string, string too short; test passed" << std::endl; } // test 9, invalid, string shorter than it should be SudokuRowChecker c9; char s9[] = "1234"; c9.setData(s9); if(c9.isValid()){ std::cout << "9.1. Invalid string, string too short; test failed" << std::endl; } else { std::cout << "9.1. Invalid string, string too short; test passed" << std::endl; } // test 10, invalid, correct length, duplicate characters SudokuRowChecker c10; string s10 = "000000008"; c10.setData(s10); if(c10.isValid()){ std::cout << "10.1. Invalid string, duplicate characters in string; test failed" << std::endl; } else { std::cout << "10.1. Invalid string, duplicate characters in string; test passed" << std::endl; } // test 11, invalid, correct length, duplicate characters SudokuRowChecker c11; char s11[] = "000000008"; c11.setData(s11); if(c11.isValid()){ std::cout << "11.1. Invalid string, duplicate characters in c-string; test failed" << std::endl; } else { std::cout << "11.1. Invalid string, duplicate characters in c-string; test passed" << std::endl; } // test 12, check clear SudokuRowChecker c12; char s12[] = "123456789"; c12.setData(s12); c12.clear(); if(c12.isValid()){ std::cout << "12.1. Invalid string, clear() should empty data; test failed" << std::endl; } else { std::cout << "12.1. Invalid string, clear() should empty data; test passed" << std::endl; } return 0; 

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

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions