Access over 40 Millions of academic & study documents

5 (C++ Program Please) Develop a function called reCount, with the

Content type
User Generated
Showing Page:
1/3
5. (C++ Program Please) Develop a function called
reCount, with the prototype: bool reCount(const char *S,
char *P);
Functionally, it accepts two c-strings, and it searches
string S for the occurrence of the pattern string, P: if found
at least once it will return true.
Example:
char *acid = \"UTTAGUATGUUU\";
bool found;
found = reCount(acid, \"TAG); // found will be true
found = reCount(acid, \"TGA\"); // found will be false
found = reCount(acid, \"GUUU\"); // found will be true
Solution
bool reCount(const char *S, char *P)
{int i,j,temp;
for(i=0;S[i]!=\'\';i++)
{
j=0;
if(S[i]==P[j])
{
temp=i+1;
while(S[i]==P[j])
{

Sign up to view the full document!

lock_open Sign Up
Showing Page:
2/3
i++;
j++;
}
if(P[j]==\'\')
{
cout<<\"The substring is present in given string
\"<<temp<<\"n\";
return true;
exit(0);
}
else
{
i=temp;
temp=0;
}
}
}
if(temp==0)
{ cout<<\"The substring is not present in given strinn\";
return false;
}
}

Sign up to view the full document!

lock_open Sign Up
Showing Page:
3/3

Sign up to view the full document!

lock_open Sign Up
Unformatted Attachment Preview
5. (C++ Program Please) Develop a function called reCount, with the prototype: bool reCount(const char *S, char *P); Functionally, it accepts two c-strings, and it searches string S for the occurrence of the pattern string, P: if found at least once it will return true. Example: char *acid = \"UTTAGUATGUUU\"; bool found; found = reCount(acid, \"TAG); // found will be true found = reCount(acid, \"TGA\"); // found will be false found = reCount(acid, \"GUUU\"); // found will be true Solution bool reCount(const char *S, char *P) {int i,j,temp; for(i=0;S[i]!=\'\';i++) { j=0; if(S[i]==P[j]) { temp=i+1; while(S[i]==P[j]) { i++; j++; } if(P[j]==\'\') { cout ...
Purchase document to see full attachment
User generated content is uploaded by users for the purposes of learning and should be used following Studypool's honor code & terms of service.
Studypool
4.7
Indeed
4.5
Sitejabber
4.4