Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

a Java or C++ program that will perform the following sequence of operations: 1. Ask the user to input a string. 2. Reverse the first

a Java or C++ program that will perform the following sequence of operations:

1. Ask the user to input a string.

2. Reverse the first word and the last word using a stack/s.

3. Swap the positions of the reversed words.

4. Display the new string.

Sample output:

Input a string :

This is the new normal.

Output : lamron is the new sihT.

If you are going to use the Stack Class, only the following methods are allowed:

empty(), peek(), pop(), and push().

The new string must be stored in another variable.

If the string contains only one word, reverse the word.

If there is a period at the end, do not process it. It must stay in its position.

For sample runs, use the following inputs :

1.) string : This is the new normal.

2.) string : position.

3.) string : the quick brown fox

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Transport Operations

Authors: Allen Stuart

2nd Edition

978-0470115398, 0470115394

Students also viewed these Programming questions