Question: I need help completing the following C++ program. #include #include #include // Reverse string q in place char* reverse_(char* q) { // fill in code

I need help completing the following C++ program.

#include #include #include // Reverse string q in place char* reverse_(char* q) { // fill in code here } // Make a new string that is the reverse of string q dont forget to delete[] it in main char* reverse_new_(char* q) { // fill in code here } // Find the first occurrence of c in s char* strchr_(char* s, char c); // fill in code here } // Find the last occurrence of c in s char* strrchr_(char* s, char c) { // fill in code here } // Concatenate up to n characters of t onto s char* strncat_(char* s, const char* t, size_t n) { // this will help you on replace_str_ // fill in code here } // Find the first occurrence of string t in s char* strstr_(char* s, const char* t) { // fill in code here } // Replace all occurrences of c with d char* replace_(char* s, char c, char d) { // fill in code here } // Replace all occurrences of string t with string u // Hint: make a temporary buffer that is the same as s

// use strstr_ to find the substring t (if any) // then use strncat_ and strcat_ to copy the buffers across // finally: delete[] the temporary buffer char* replace_str_(char* s, char* t, char* u) { // fill in code here } void msg_print(const std::string& msg, const std::string s) { std::cout << msg << s << std::endl; } #define BUF_SIZE 100 void msg_print(const std::string& msg, const std::string s) { std::cout << msg << s << std::endl; } int main() { std::cout << "LAB: (More advanced) C++/C string functions to implement... " << "\tchar* reverse_(char* s) " << "\tchar* reverse_new_(char* s) " << "\tchar* strchr_(char* s, char c) " << "\tchar* strrchr_(char* s, char c) " << "\tchar* strstr_(char* s, const char* t) " << "\tchar* strncat(char* s, const char* t, size_t n) " << "\tchar* replace_(char* s, char c, char d) " << "\tchar* replace_str_(char* s, const char* t, size_t n) ";

char orig[BUF_SIZE] = "indianapolis";

msg_print("before reversing...", orig); reverse_index_(orig); msg_print("and after...", orig); reverse_(orig); msg_print("and after reverse_ptr...", orig);

msg_print(" find p...", strchr_(orig, 'p')); msg_print("find first i...", strchr_(orig, 'i')); msg_print("find last i...", strrchr_(orig, 'i'));

strcpy(orig, "mississippi"); std::cout << " orig is now: " << orig << " ";

char* p = replace_(orig, 'i', 'X'); std::cout << "after replacing i with X, orig is: " << orig << " ";

strcpy(orig, "mississippi"); std::cout << " orig is back to: " << orig << " ";

p = replace_str_(orig, "ss", "KETCHUP"); std::cout << "after replacing 'ss' with 'KETCHUP', orig is now: " << p << " ";

std::cout << " ...done "; return 0;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!