Trusted by millions of Kenyans
Study resources on Kenyaplex

Get ready-made curriculum aligned revision materials

Exam papers, notes, holiday assignments and topical questions – all aligned to the Kenyan curriculum.

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

Answer Attachments

Exams With Marking Schemes

Related Questions