Get premium membership and access questions with answers, video lessons as well as revision papers.

Create a function called reverse() that takes two parameters. The first parameter called str, is a pointer to a string that will be reversed upon...

      

Create a function called reverse() that takes two parameters. The first parameter called str, is a pointer to a string that will be reversed upon return from the function. The second parameter is called count, and it specifies how many characters of str to reverse(). Give count a default value that, when present, tells reverse() to reverse the entire string.(use C++ language)

  

Answers


Davis

#include
#include
using namespace std;
void reverse(char *str, int count = 0);
int main()
{
char *s1 = "Am a computer student";
char *s2 = "Computer makes me digital";
reverse (s1); //reverse the whole strig
reverse(s2, 7); //reverse the first 7 characters.
cout << s1 << '\n';
cout << s2 <<'\n';
return 0;
}
void reverse(char *str, int count)
{
int i
char temp;
if(!count) count = strlen(str)-1;
for(i=0, j=count; itemp = str[i];
str[i] = str[j];
str[j] = temp;
}
Githiari answered the question on June 8, 2018 at 19:26


Next: Overload the >> and << shift operators relative to the coord class so that the following types of operations are allowed: ob << integer ob >> integer make sure your operators shift the x and y values by the amount specified.
Previous: Create a function in C++ called order() that takes two integer reference parameters. If the first argument is greater than the second argument, reverse the...

View More Computer Science Questions and Answers | Return to Questions Index


Learn High School English on YouTube

Related Questions