Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Background? The purpose of this assignment is to practice dealing with string data. The goal is to work with data declared as char * and

Background?

The purpose of this assignment is to practice dealing with string data. The goal is to work with data declared as char * and also as string. Somehow, I think you'll like working with string much better. Please recall that string is officially known as std:: 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 with:

https://en.wikipedia.org/wiki/Sudoku.

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 create any number of additional methods, but you are required to implement all of the public methods shown below.

 

SudokuRowChecker( );

void setData( const char * s );

void setDataString( std::string s );

void clear();

bool isValid( ) const;

string sudokuRow;

Here is the given code:

main.cpp tests.h

/** ------------------- **/ /** DO NOT MODIFY START **/ /** ------------------- **/ #include #include "sudoku_row_checker.h" #include "tests.h"

using namespace std;

void personalTests();

int main() { SudokuRowChecker checker; string input="", cont="y"; while (cont == "y"){ cout << "1) setData 2) setDataString 3) unittests 4) personalTests "; cin >> input; switch(stoi(input)){ case 1: cout << "checker <--- "; cin >> input; checker.setData(input.c_str()); checkAndClear(checker); break; case 2: cout << "checker <--- "; cin >> input; checker.setDataString(input); checkAndClear(checker); break; case 3: cout << " 1) setData 2) setDataString 3) clear "; cin >> input; unittests(stoi(input)); break; case 4: personalTests(); break; } cout << "Continue(y/n)? "; cin >> cont; } } /** ----------------- **/ /** DO NOT MODIFY END **/ /** ----------------- **/

void personalTests(){ cout << "Running My Tests... "; }

#include #include "sudoku_row_checker.h" #include "string.h"

using namespace std;

void checkAndClear(SudokuRowChecker c){ if (c.isValid()) { cout << "valid "; } else { cout << "invalid "; } c.clear(); }

void checkEmptyChar(){ cout << "UnitTest/setDataString/Emptystring: "; SudokuRowChecker c1 = SudokuRowChecker(); char s[] = ""; c1.setData(s); checkAndClear(c1); }

void checkEmptyString(){ cout << "UnitTest/setDataString/Emptystring: "; SudokuRowChecker c1 = SudokuRowChecker(); c1.setDataString(""); checkAndClear(c1); } void checkClear(){ cout << "UnitTest/clear/true: "; SudokuRowChecker c = SudokuRowChecker(); c.setDataString("123456789"); checkAndClear(c); cout << "UnitTest/clear/true + clear: "; c.setDataString("123456789"); c.clear(); checkAndClear(c); } void unittests(int funcNum){ switch(funcNum){ case 1: { checkEmptyChar(); break; } case 2: { checkEmptyString(); break; } case 3: { checkClear(); break; } } }

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

Fundamentals Of Database System

Authors: Elmasri Ramez And Navathe Shamkant

7th Edition

978-9332582705

More Books

Students also viewed these Databases questions