Question

In: Computer Science

Write a C++ program that inputs (cin) a word from the keyboard and generates several different...

Write a C++ program that inputs (cin) a word from the keyboard and generates several different scrambles of the word without using vectors. The input word can be from 4 to 10 letters in length. The number of scrambles produced depends on the number of letters in the word. e.g. the 4 letter word “lose” would have 4 different scrambles produced and the seven letter word “edition” would have seven different scrambles.

Here is a candidate example:     

Input: FLOOR

                Scrambles: ROOLF, OOLFR, OLFRO, LOORF, OORFL

Your program must use the same block of code for each input word. There is also the rand() random number generator available.

Test you program with these words:

salt
asteroid
manipulate

Solutions

Expert Solution

Here you go:

#include <iostream>

#include <algorithm>

#include <ctime>

#include <cstdlib>

#include <string>

using namespace std;

int main()

{

    srand(time(0));

    int i,len=0;

    string input;

    cout<<"Input: ";

    cin>>input;

    len=input.length();

    std::string output = input;

    if(output.size() >=4 && output.size() <=10){

    for(i=0; i<len; i++)

    {

            std::random_shuffle(output.begin() , output.end());

            std::cout << output << ' ';

        }

    }

    else

    {

        return 0;

    }

}

========================================================

A sign of thumbs up would be appreciated.


Related Solutions

write a python program that inputs 10 integer values from the keyboard and then displays their...
write a python program that inputs 10 integer values from the keyboard and then displays their sum. use for loop
write this program in c++ using iostream library.( cin>>n; cin>> arr[n] and so on) Write a...
write this program in c++ using iostream library.( cin>>n; cin>> arr[n] and so on) Write a function that converts an array so that in the first half settled with elements from odd positions, and in the second half - with elements from the even positions.Positions are counted from the first index.The program have to use pointer. example: input: 7 1 2 3 4 5 6 7 output: 1 3 5 7 2 4 6 8
this has to be coded in c ++ • Write a program which generates a DIFFERENT...
this has to be coded in c ++ • Write a program which generates a DIFFERENT random number between 1 and 100 everytime you run the program. Please go online and see how poeple are trying to solve this. You can submit their code. Make sure you include a comment which shows from where the code was taken. You do not need to understand the code but if you can, thats great. This program will be used in the upcoming...
Write a C++ program to read in a list of 10 integers from the keyboard. Place...
Write a C++ program to read in a list of 10 integers from the keyboard. Place the even numbers into an array called even, the odd numbers into an array called odd, and the negative numbers into an array called negative. Keep track of the number of values read into each array. Print all three arrays after all the numbers have been read. Print only the valid elements (elements that have been assigned a value). a. Use main( ) as...
(C++) Write a program that reads a list of integers from the keyboard and print out...
(C++) Write a program that reads a list of integers from the keyboard and print out the smallest number entered. For example, if user enters 0 3 -2 5 8 1, it should print out -2. The reading stops when 999 is entered.
Write an interactive C program that asks a user to enter a sentence from the keyboard,...
Write an interactive C program that asks a user to enter a sentence from the keyboard, and prints the sentence with all the words spelled backwards. Note: you may assume that each sentence will have at most 50 characters and each word is separated by a space. Sample code execution: bold information entered by user enter a sentence: hello ece 175 class olleh ece 571 ssalc continue (q to quit)? y enter a sentence: May the force be with you...
Write a C++ program that accepts a positive integer number from the keyboard . The purpose...
Write a C++ program that accepts a positive integer number from the keyboard . The purpose of the program is to find and the display all the square pair numbers between 1 and that number. The user should be able to repeat the process until he/she enters n or N in order to terminate the process and the program. Square numbers are certain pairs of numbers when added together gives a square number and when subtracted also gives a square...
Using c++, write a program that reads a sequence of characters from the keyboard (one at...
Using c++, write a program that reads a sequence of characters from the keyboard (one at a time) and creates a string including the distinct characters entered and displays the string on the screen. The input terminates once the user enters a white-space character or the user has entered 50 distinct characters. Do not use C-Strings. 2. Use the following function to append character “ch” to the string “s”: s.push_back(ch); 3. Read the input characters one by one, i.e. do...
Write a C++ program to read characters from the keyboard until a '#' character is read....
Write a C++ program to read characters from the keyboard until a '#' character is read. Then the program will find and print the number of uppercase letters read from the keyboard.
Write using C++ a) Inputs two 1D arrays of doubles A[i] and B[i] from the keyboard...
Write using C++ a) Inputs two 1D arrays of doubles A[i] and B[i] from the keyboard with a maximum size of 1000. The elements are input one at time alternating between A and B (ie A[0],B[0],A[1],B[1], …, A[i],B[i]) until a value of less than -1.0e6 is input or i >= 1000. Then the program continues to part b). b) Calculates C = A + B, where + is vector addition (ie C[i] = A[i] + B[i]), and prints each element...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT