C++: Task

Word Scrambler

Program Overview:

Write a program that prompts the user to enter in a phrase and then proceeds to shuffle and reorganize the letters within that phrase. When finished, the word should appear scrambled yet all letters in the scrambled phrase will appear the same number of times as before.

For example, the user entering “abcdefgh“ may change into “fghcdeab”.

You are to write a function called Split, which takes in a String parameter, separates the parameter into three portions: left, middle, and right. The function then recombines these portions so the new ordering is oldRight – middle - oldLeft and returns this recombined String.

For example. splitting the word “turtles “ into chunks of length 2 (left), 2(middle), and 3(right) would yield ”lesrttu”.

T / U / R / T / L / E / S
0 / 1 / 2 / 3 / 4 / 5 / 6

Every time Split is called, two random numbers will determine the size of the chunks into which the text should be split and then recombined. The random numbers should be selected such that each section has a random number of letters (but has a minimum of one letter).

The number of times the phrase should be split is entered by the user. If the user decides to scramble the default number of times instead of specifying their own amount, then the default number of times a word should be split and recombined is five. You should display all intermediate permutations of the phrase.

Note: You MUST make use of the substr method in order to receive full credit on this assignment.

Sample Output – User input is underlined

How would you like to shuffle the phrase?

1) Default Amount

2) Specify a number of times

1

Enter the phrase to scramble: french toast

Permutation #1: toastchfren

Permutation #2: frenh toastc

Permutation #3: ch toastfren

Permutation #4: entfrch toas

Permutation #5: toash entfrc

Again? 1=Yes, 2=No:1

------CLEAR THE SCREEN

How would you like to shuffle the phrase?

1) Default Amount

2) Specify a number of times

2

Enter the phrase to scramble: sunny-side up

How many mixes?10

Permutation #1: pside usunny-

Permutation #2: y-sunnpside u

Permutation #3: u y-sunnpside

Permutation #4: npsidey-sunu

Permutation #5: nu unpsidey-s

Permutation #6: snpsidey-nu u

Permutation #7: nu uy-snpside

Permutation #8: npsidesnu uy-

Permutation #9: u uy-idesnnps

Permutation #10: sesnnpu uy-id

Again? 1=Yes, 2=No:2

Goodbye.

Adding in Trials:

Add a new option to your menu to add some testing trials in:

How would you like to shuffle the phrase?

1) Default Amount

2) Specify a number of times

3) Run some trials

Now when the user selects 3, you will ask them how many letters the test string should have. Based on the number they enter, create a string of that many letters, where each letter is different:

If they say 4 -> abcd

If they say 5 -> abcde

If they say 6 -> abcdef

Etc. Note – do not do this by pre-creating all the strings in advance – build it based on the number of letters requested at the time of request.

Then ask the user how many trials they want to conduct. You will then run this many trials. Each trial consists of shuffling the letters until you get back to the original string. Display the permutations as you go. Also keep track of how many it took.

You should clearly label the sections between permutations.

Also – you should calculate the average number of permutations required over the trials to reshuffle to the original word.

Sample Output – User input is underlined

How would you like to shuffle the phrase?

1) Default Amount

2) Specify a number of times

3) Run some trials

3

What size of string to test?4

How many trials? 5

*****TRIAL: 1 *************

Permutation #1: dcab

Permutation #2: abcd

*****TRIAL: 2 *************

Permutation #1: dbca

Permutation #2: abcd

*****TRIAL: 3 *************

Permutation #1: dbca

Permutation #2: acdb

Permutation #3: bdac

Permutation #4: acdb

Permutation #5: bdac

Permutation #6: cdab

Permutation #7: bdac

Permutation #8: cdab

Permutation #9: bdac

Permutation #10: cabd

Permutation #11: dabc

Permutation #12: bcad

Permutation #13: adcb

Permutation #14: bcad

Permutation #15: dabc

Permutation #16: cabd

Permutation #17: dbca

Permutation #18: abcd

*****TRIAL: 4 *************

Permutation #1: dbca

Permutation #2: cabd

Permutation #3: bdac

Permutation #4: acdb

Permutation #5: dbca

Permutation #6: abcd

*****TRIAL: 5 *************

Permutation #1: dbca

Permutation #2: abcd

Average permutations required: 6

Again? 1=Yes, 2=No: