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

can anyone help me. whats wrong with my code. fix it please. here is my code//\\

ID: 3604721 • Letter: C

Question

can anyone help me. whats wrong with my code. fix it please.

here is my code//

h27.cpp

-----------------

#include <string>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <stdio.h>

// Other headers if necessary
using namespace std;

#include "h27.h"

// Add your code here
void reverse(char * s)
{
char * strptr = s;
char * beg = s;
char * end = &s[0];
char * ch;

while(*end != '')
{
end++;
}
end--;

while(beg < end)
{
ch = beg;
beg = end;
end = ch;
beg++;
end++;

}
cout << end << endl;
}

//h27.h

#ifndef H27_H_
#define H27_H_

/**
* Reverses the C-style string pointed to by s.
*
* @param s a pointer to the character in a C-style string.
*
* NOTE: for this assignment, you can only use ++, --,
* = (assignment), ==,!= (comparison) and pointer subtraction
* (p1 - p2). You cannot use pointer arithmetic (s + i), or
* array notation (s[i]). In fact, you cannot have ANY integer
* variables or literals in your code. You also cannot use ANY
* standard library functions including strlen.
*/
void reverse(char * s);

#endif
// DO NOT CHANGE ANY OF THESE LINES
#define strlen(s) static_assert(false, "strlen not allowed");
#define strcat(d, s) static_assert(false, "strcat not allowed");
#define strcpy(d, s) static_assert(false, "strcpy not allowed");
#define string static_assert(false, "string not allowed");

Your Turn There are two assignments for this chapter. To complete these, follow along with the examples in the preceding section, and apply them to these problems. Problem 1 For the first problem, upload the starter code (H27) to your workspace. Then read through the instructions here to write the reverse() function. The function reverses (in place) a C-style character string s. You must use pointers and the increment and dec- rement operators only Do not use pointer arithmetic (that is p n) or array notation in your function. (In oth er words, there will be no int variables or literals in your function: only pointers along with assignment, comparison, pointer subtraction, + and/or - - you may, of course, use a temporary char variable, which you'l need to exchange the elements of the string and a temporary pointer) If you get stuck, please ask questions on Piazza.

Explanation / Answer

#include <string>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <stdio.h>
// Other headers if necessary
using namespace std;

#include "h27.h"
int main(){

char Cstring[50];
cout<<"enter a word: ";
cin>>Cstring;
string results = reverse(Cstring);
cout <<results;

}

void reverse(char * s)
{
char * strptr = s;
char * beg = s;
char * end = &s[0];
char * ch;
while(*end != '')
{
end++;
}
end--;
while(beg < end)
{
ch = beg;
beg = end;
end = ch;
beg++;
end++;
}
cout << end << endl;
}

//h27.h
#ifndef H27_H_
#define H27_H_
/**
* Reverses the C-style string pointed to by s.
*
* @param s a pointer to the character in a C-style string.
*
* NOTE: for this assignment, you can only use ++, --,
* = (assignment), ==,!= (comparison) and pointer subtraction
* (p1 - p2). You cannot use pointer arithmetic (s + i), or
* array notation (s[i]). In fact, you cannot have ANY integer
* variables or literals in your code. You also cannot use ANY
* standard library functions including strlen.
*/
void reverse(char * s);
#endif
// DO NOT CHANGE ANY OF THESE LINES
#define strlen(s) static_assert(false, "strlen not allowed");
#define strcat(d, s) static_assert(false, "strcat not allowed");
#define strcpy(d, s) static_assert(false, "strcpy not allowed");
#define string static_assert(false, "string not allowed");

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at drjack9650@gmail.com
Chat Now And Get Quote