Question: Required Filename 43_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
Required Filename 43_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 setnnece is srcmalbed, colud 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. Objective Implement the function: string scramble Word(string word) Apply the following rules: -Swap letters at odd indices with the letter one index before 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 scramble Word("rambunctious")=rabmnutcious scramble Word("optimistic") = opitimtsic scramble Word("programmer") = prgoarmmer scramble Word("bountiful") = bonuitul scramble Word("software") = sotfawre scramble Word("quell") = qulel scramble Word("unique") = unique scramble Word("irony") =imoy scrambleWord("value")= vaule scrambleWord("pique") = piuqe scramble Word("doubt") - dobut scramble Word("heart") = herat
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
