Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

LAB: C++/C common string functions part 2: reverse, reverse new strchr strrchr,

ID: 3885355 • Letter: L

Question

LAB: C++/C common string functions part 2: reverse, reverse new strchr strrchr, strncat strstrreplace, replace str Code and Algorithm Design This lab, based on K and R (aka: THE C PROGRAMMING LANGUAGE by Kemighan and Ritchie). is designed to give more practice in working with common C library functions used in C++C (please refer to Chapter 5.5 when needed, or related sections (marked in the text). char reverse (char* q): char reverse_new (const char q) / make a new string that is reversed char strchr_(chars, char c): char strrchr (char s, char c): /I reverse a string in place / find the first occurrence of c find the last occurrence of c .II concatenate up to n characters from t onto the end ofs char strncat (char* s. const char* t. size t n): char replace (char s. char c, char d); I replace all occurrences of c with d char replace str_(char s. char t.char u): .1 replace alt occurrences of substring t with new substring u All of these functions should be imalemented with pointers. Students will also show each of the algorithms using spreadsheets (as in the previous lab). Don't forget to check: when needed. nclude

Explanation / Answer

here you have the first four methods declared in the question you have provided.

char* reverse_(char *q) {
   char tmp;
   int i, l = strlen(q);
   for (i = 0; i < l/2; i++) {
       tmp = q[i];
       q[i] = q[l - 1 - i];
       q[l - 1 - i] = tmp;
   }
   return q;
}

char* reverse_new_(const char *q) {
   char* newString;
   int i, l = strlen(q);
   newString = char[strlen(q) + 1];
   for (i = 0; i < l; i++) {
       newString[i] = q[l - 1- 1];
   }
   newString[l] = q[l] ;
   return newString;
}

char* strchr_ (char* s, char c) {
   int i, l = strlen(q);
   for (i = 0; i < l; i++) {  
       if (s[i] == c)
           return s + i;
   return NULL;
}

char* strrchr_ (char* s, char c) {
   int i, l = strlen(q), index = -1;
   for (i = 0; i < l; i++) {  
       if (s[i] == c)
           index = i;
   if (index >= 0)
       return s + index;
   return NULL;
}

due to chegg protocol, we can answer 4 questions at a time only, so remauining four goes unanswered. please co-operate