Question
C++ PROGRAM ACCORDING TO FOLLOWING GOOGLE TESTCASES+GIVEN FUNCTION PROTOTYPE Write a C++ program to find a string in a 3d character matrix. Your function should
C++ PROGRAM ACCORDING TO FOLLOWING GOOGLE TESTCASES+GIVEN FUNCTION PROTOTYPE
Write a C++ program to find a string in a 3d character matrix. Your function should check whether a string matches and return an 2d array which saves matched coordinates ( start till ending) in the matrix. The matching can be done on each slice of the 3D array ( row, column, diagonal direction).Note: slices can be in x, y and z direction. If no strings are found, the resulting 2D array will have -1 sizes and return false. The functions prototype are as follows:
FUNCTION PROTOTYPE :
char*** ConvertToDynamic(char arr[], int x, int y, int z); (This function takes a 1d array as argument and the 3 sizes and creates and return a 3d array)
bool MatchString3DArray(char*** mat, int xSize, int ySize, int zSize, char * input, int**&resultMat, int& colSize); (This function holds the main functionality of the 3d string matching) void DeleteArray(char***& arr, int x, int y, int z); (This function deletes the dynamically created array) Note: string library not allowed.
GOOGLE TEST:
//3D String Matching
TEST(StringMatching, XCheck) { char arr[28] = "sbtaicztieahrnltagtsjvehfyf"; char*** mat = ConvertToDynamic(arr, 3, 3, 4);
char* str = "tag"; int c = 3, ans[3][3] = { {1, 1, 1}, {2, 2, 2}, {0, 1, 2} }; int col, ** res;
ASSERT_EQ(1, MatchString3DArray(mat, 3, 3, 4, str, res, col)); ASSERT_EQ(c, col);
for (int i = 0; i
DeleteArray(mat, 3, 3, 4); ASSERT_EQ(NULL, mat);
}
TEST(StringMatching, YCheck) { char arr[28] = "sbtaicztieahrnltagtsjvehfyf"; char*** mat = ConvertToDynamic(arr, 3, 3, 4);
char* str = "yes"; int c = 3, ans[3][3] = { {2, 2, 2}, {2, 1, 0}, {1, 1, 1} }; int col, ** res;
ASSERT_EQ(1, MatchString3DArray(mat, 3, 3, 4, str, res, col)); ASSERT_EQ(c, col); for (int i = 0; i
TEST(StringMatching, ZCheck) { char arr[28] = "sbtaicztieahrnltagtsjvehfyf"; char*** mat = ConvertToDynamic(arr, 3, 3, 4);
char* str = "set"; int c = 3, ans[3][3] = { {0, 1, 2}, {0, 0, 0}, {0, 0, 0} }; int col, ** res;
ASSERT_EQ(1, MatchString3DArray(mat, 3, 3, 4, str, res, col)); ASSERT_EQ(c, col); for (int i = 0; i
DeleteArray(mat, 3, 3, 4); ASSERT_EQ(NULL, mat); }
TEST(StringMatching, DiagonalCheck) { char arr[28] = "sbtaicztieahrnltagtsjvehfyf"; char*** mat = ConvertToDynamic(arr, 3, 3, 4);
char* str = "zi"; int c = 2, ans[3][2] = { {0, 0}, {2, 1}, {0, 1} }; int col, ** res;
ASSERT_EQ(1, MatchString3DArray(mat, 3, 3, 4, str, res, col)); ASSERT_EQ(c, col); for (int i = 0; i
DeleteArray(mat, 3, 3, 4); ASSERT_EQ(NULL, mat); }
For example, Consider a 3d matrix of 334 size as shown below Let the input string be "man", Match found "True" 2 D array Similarly, if the string is "bat", the output will be : Match found "True" 2 D array if the string is " ms ", the output will be : Match found "True" 2 D array
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started