Question: Q 2 . ( 5 0 marks ) Write a C + + program for a string decoder. 1 ) The program prompts the user

Q2.(50marks) Write a C++ program for a string decoder. 1) The program prompts the user to enter a string, for example: p(ab(dfe)ghk)q. There are nested words enclosed within parentheses. 2) The decoder's job is to extract and reverse each nested word, removing the parentheses in the process. 3) If a nested structure has other nested structures within it, it should be decoded from the inner structure first and then to outer one. 4) Write a recursive function decodeLanguage that returns the decoded strings and print it out in the main function. Here are some detailed examples: p(ab(dfe)ghk)q removing the inner most parentheses, we get p(abefdghk)q; p(abefdghk)q removing the outer parentheses pkhgdfebaq, which is the final output a(b(c)d)e will output adcbe abcde will output abcde Hints: - Find the innermost parentheses first and reverse the string inside them. - Recursively decode and replace until no parentheses remain in the string.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!