use C PartA String mash recursion Have a user input a string

use C++:

Part(A) String mash (recursion):

Have a user input a string. Then display this string smashed up as follows:

display the first character in the string, then the last, then the second, then the second to last, then the third... So if the string is “abcdef”, it will display: afbecd (input “abcdef”) YOU MUST USE RECURSION TO SOLVE THIS.

Example 1:

Enter anything: 1234

1423

Example2:

Enter anything:12345678

18273645

Example 3:

Enter anything: what does this sentence look like?

w?heakti ld okeoso lt heicsn esten

Part (B):

String unmash:

Ask them to enter a string and “unmash” it to give the string they would have originally entered for part A.

YOU MUST USE RECURSION TO SOLVE THIS.

Example 1:

Enter anything: 1423

1234

Example 2:

Enter anything: w?heakti ld okeoso lt heicsn esten

what does this sentence look like?

Solution

#include <iostream>

#include <string>

using namespace std;

void printLetters(string s);

int main()

{

string sequence;

cout << \"Enter a sequence: \";

getline(cin, sequence);

printLetters(sequence);

cout << endl;

system(\"pause\");

}

void printLetters(string s)

{

int a =s.length();

if (a == 0)

{

    return;

}

cout << s[0];

if(a>1)

cout<< s[a - 1];

s.erase(0, 1);

a = s.length();

if(a>1)

s.erase(a-1);

printLetters(s);

}

use C++: Part(A) String mash (recursion): Have a user input a string. Then display this string smashed up as follows: display the first character in the string,
use C++: Part(A) String mash (recursion): Have a user input a string. Then display this string smashed up as follows: display the first character in the string,

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site