Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I still have proplem with the second function when i ever i try test case 2 i get wrong output this is the code void

image text in transcribedimage text in transcribed

I still have proplem with the second function when i ever i try test case 2 i get wrong output this is the code

void NestedStatements(string S1, string S2, int& count) { count = 0; size_t pos = 0; while ((pos = S2.find(S1, pos)) != string::npos) { count++; pos += S1.length(); }

HW5: Function Overloading You are required to write two overloaded functions called NestedStatements that take in the following formal parameters list: - Function 1: takes as input two strings (i.e. S1 and S2 ) and returns true if the string S1 appears in the string S2 at least once. Otherwise, the function returns false. For example, if S1 = "eat" and S2 = "the weather is nice" then the function returns TRUE. Similarly, if S1 = "zoo" and S2 = "the zoo is closed" then the function also returns TRUE. - Function 2: takes as input two strings (i.e. S1 and S2) and an integer reference variable count, and saves the number of times the string S1 appears in the string S2 in the variable count. For example, if S1= "the" and S2= "the weather is nice" then the value of count at the end of the function is 2. Similarly, if S1 = "cloned" and S2= "the zoo is closed" then the value of count at the end of the function is 0. Do not write and submit the main subroutine, or any include statments, these are already written and hidden from you. However, if you want to test your solution in any IDE (e.g., CodeBlocks, CLion, onlinegdb.com), then you will need to write your own main there for testing purposes. IMPORTANT NOTES - Do not change the given functions headers. - Do not add any cout statements inside the functions. - Assume all the alphabetical characters in S1 and S2 are lowercase. Sample Testcase 2 (not graded, for student use only): Input: Suppose main calls NestedStatements as NestedStatements("ear", "heart, tears, ear, and earn", v1) Function Output: The value of v1 in the main after the call should be 4 The function does not print anything, only stores the value 4 in v1

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_2

Step: 3

blur-text-image_3

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

Database Support For Data Mining Applications Discovering Knowledge With Inductive Queries Lnai 2682

Authors: Rosa Meo ,Pier L. Lanzi ,Mika Klemettinen

2004th Edition

3540224793, 978-3540224792

More Books

Students also viewed these Databases questions

Question

What are the stages of project management? Write it in items.

Answered: 1 week ago