Answer:
// This program is written in C++ programming language
// Comments are used for explanatory purpose
// Program starts here
#include<iostream>
using namespace std;
// Function starts here
string ascendingwords(string sentence)
{
// Calculate length of input text
int len = sentence.length() - 1;
// Create a begin and end variable
int begin, end = len + 1;
// Declare and initialize an output string
string output = "";
// Perform iteration while there's still some text in the input string
while(len >= 0)
{
if(sentence[len] == ' ')
{
begin = len + 1;
while(begin != end)
output += sentence[start++];
output += ' ';
end = len;
}
len--;
}
begin = 0;
while(begin != end)
output += sentence[begin++];
return output;
}
// Main method starts here
int main()
{
// Declare string
string sentence;
// Prompt user for input
cout<<"Enter a string: ";
cin>>sentence;
cout <<ascendingwords(sentence);
return 0;
}