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

Complete the code for the following jumbleString function. It accepts a string a

ID: 3626534 • Letter: C

Question

Complete the code for the following jumbleString function. It accepts a string and display a randomized version of the same string. The algorithm is to generate two random numbers <= the length of the string and swap the characters at the indexes of the random numbers. It does this as many times as there are characters in the strin. It then displays the jumbled string.

______ jumbleString ( string str)
{
int size=str.______;
// jumble the characters in str
for ( int x=___; ___<____; ____)
{
int index1 = rand() % _______;
int index2 = rand() % _______;
char temp = _____ [ ______ ];
____ [ ____ ] = ____ [ ____ ];
____ [ ____ ] = temp;
}
cout << "The jumbled string is << _______ << endl;
return;
}

Explanation / Answer

void jumbleString ( string str)
{
int size=str.size();
// jumble the characters in str
for ( int x=0; x
{
int index1 = rand() % size;
int index2 = rand() % size;
char temp = str [index1];
str [index1] = str [index2];str [ index2] = temp;
}
cout << "The jumbled string is << str << endl;
return;
}

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