Answered step by step
Verified Expert Solution
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
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 v1Step 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