Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Task -> Implement the function specifications, i.e. the prototypes. Search a sentence for the occurrence of a pattern. Report the position where the pattern occurs.

Task -> Implement the function specifications, i.e. the prototypes.

Search a sentence for the occurrence of a pattern. Report the position where the pattern occurs. It might not occur, occur only once, or could occur many times. Find all the matches and output their position in the sentence. The position starts at index=0 at the beginning of the sentence.

See the sample test case for input and output formats.

Template

//System Libraries Here #include //cin,cout,getline() #include //strlen() using namespace std;

//User Libraries Here

//Global Constants Only, No Global Variables //PI, e, Gravity, or conversions

//Function Prototypes Begins Here //srch1 utility function Input->start position, Output->position found or not //srch1 is a simple linear search function, repeat in srchAll till all found //srch1 Input->sentence, pattern, start position Output-> position found //Remember arrays start at index/position 0 //srchAll Input->sentence, pattern Output->position array int srch1(const char [],const char [],int);//Search for 1 occurrence void srchAll(const char [],const char [],int []);//Search for all occurrences void print(const char []);//Print the character arrays void print(const int []); //Print the array of indexes where the pattern found

//Program Execution Begins Here int main(int argc, char** argv) { //Declare all Variables Here const int LINE=81; //Size of sentence or pattern to find char sntnce[LINE],pattern[LINE]; //80 + null terminator int match[LINE]; //Index array where pattern was found //Input a sentence and a pattern to match cout<<"Match a pattern in a sentence."<

C++ Please

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

Modern Database Management

Authors: Fred R. McFadden, Jeffrey Slater, Mary B. Prescott

5th Edition

0805360549, 978-0805360547

More Books

Students also viewed these Databases questions

Question

1. Identify three approaches to culture.

Answered: 1 week ago

Question

2. Define communication.

Answered: 1 week ago