Question
(programming c-string) Specifically you are not allowed to include string, cstdlib or math libraries. Also you are not allowed to use any built-in functions of
(programming c-string)
Specifically you are not allowed to include string, cstdlib or math libraries. Also you are not allowed to use any built-in functions of c-strings.
bool isSubstring(const char *s1, const char* s2)
{
/* returns true is s1 is a substring of s2 otherwise returns false Definition: s1 is a substring of s2 if s1 is found in s2. That is all characters of s1 are found TOGETHER in s2 in the SAME ORDER as they appear in s1 Example "set" is a substring of "massachussettes" But "ets" is not substring of "massachussettes" */
}
int countWords(const char* s)
{
/* Given a c-string that contains some words separated by spaces, return the number of words in the c-string.
}
//Test isSubstring function
cout << endl; flag = isSubstring(s1, s4);
if (flag)
cout << s1 << " is a substring of " << s4 << endl;
else
cout << s1 << " is not a substring of " << s4 << endl; char s5[] = "abort";
char s6[] = "abcabodefaborhuhabortabunny";
flag = isSubstring(s5, s6);
if (flag)
cout << s5 << " is a substring of " << s6 << endl;
else
cout << s5 << " is not a substring of " << s6 << endl;
//Test countWords function
cout << endl;
char s7[] = "";
c = countWords(s7);
cout << "There are " << c << " words in " << s7 << endl;
char s8[] = "Test";
c = countWords(s8);
cout << "There are " << c << " words in " << s8 << endl;
char s9[] = "Nice one";
c = countWords(s9);
cout << "There are " << c << " words in " << s9 << endl;
char s10[] = "This is a nice assignment and hopefully an interesting as well";
c = countWords(s10);
cout << "There are " << c << " words in " << s10 << endl;
the ideal output is:
massachussettes is not a substring of htsemsaesuatscs
abort is a substring of abcabodefaborhuhabortabunny
There are 0 words in
There are 1 words in Test
There are 2 words in Nice one
There are 11 words in This is a nice assignment and hopefully an interesting as well
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