Question
3 THE FINDLAST FUNCTION Write the function findLast(). The function has two parameters: a const char * s1 pointing to the first character in a
3 THE FINDLAST FUNCTION Write the function findLast(). The function has two parameters: a const char * s1 pointing to the first character in a C-style string, and a const char * s2. Return a pointer to the last appearance of s2 appearing inside s1 and nullptr (0) if s2 does not appear inside s.
here is the support file, thank you
/**
CS 150 C-Strings
Follow the instructions on your handout to complete the
requested function. You may not use ANY library functions
or include any headers, except for
*/
#include
///////////////// WRITE YOUR FUNCTION BELOW THIS LINE ///////////////////////
// function here
///////////////// WRITE YOUR FUNCTION ABOVE THIS LINE ///////////////////////
// These are OK after the function
#include
#include
using namespace std;
void CHECK(const char*, const char *, const string&);
void studentTests()
{
cout << "Student testing. Add code in this function." << endl;
cout << "-------------------------------------------------------------" << endl;
CHECK("Aardvark", "ar", "ark");
CHECK("Aardvark", "a", "ark");
CHECK("Aardvark", "r", "rk");
CHECK("Aardvark", "K", "nullptr");
cout << endl;
cout << "--done--" << endl;
}
int main()
{
studentTests();
}
#include
void CHECK(const char * s1, const char * s2, const string& expected)
{
string msg = "findLast(\"" + string(s1) + "\", \"" + string(s2) + "\")";
char d1[1024], d2[1024];
strcpy(d1, s1);
strcpy(d2, s2);
auto p = findLast(d1, d2);
string actual = (p ? string(p) : "nullptr");
if (expected == actual)
cout << " + " + msg + "->OK" << endl;
else
cout << " X " + msg + " expected<\"" + expected + "\">, found <\"" + actual + "\">" << endl;
}
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