Question: thank you in advance! Required Filename q3_string_scrambler.cpp Problem According to a Cambridge University study, most people can read words in sentences with scrambled letters, provided
Required Filename q3_string_scrambler.cpp Problem According to a Cambridge University study, most people can read words in sentences with scrambled letters, provided the first and last letters of words are the same. For example: tihs sneetcne is srcmalbed, cuold you udnretsnad it? (It said: "this sentence is scrambled, could you understand it?) You are curious to try this out yourself, so you decide to write a program that processes sentences as strings, scrambles them, and prints out the result. For this problem, we will focus on your string scrambling function, which will handle one word at a time. Rather than randomly moving letters around, you decide on a fixed set of rules. Summary Implement the function: string scrambleword(string word) Apply the following rules: Swap letters at odd indices with the letter one index after them. Remember that string indices start at 0, not 1, so the first letter has an even index, the second letter an odd index, and so on. Do not move the first or last letter, regardless of index. In a swap, make sure that 'I' is always given the first position; that is, do not swap if another letter would get a lower index than 'I'. Examples scrambleWord("rambunctious") = rmaubonituos scrambleWord("optimistic") = otpimisito scrambleWord("programmer") = porrgmaemr scrambleword("bountiful") = buotniful scrambleWord ("software") = sfowtrae scrambleWord ("quell") = geull scrambleWord ("unique") = uinuge scrambleword("irony") = forny scrambleWord("value") = vlaue scrambleWord("pique") = pique scrambleWord("doubt") = duobt scrambleWord("heart") - haert
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
