1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Vikentia [17]
4 years ago
14

Write the routines with the following declarations: void permute( const string & str ); void permute( const string & str

, int low, int high ); The first routine is a driver that calls the second and prints all the permutations of the characters in string str. If str is "abc", then the strings that are output are abc, acb, bac, bca, cab, and cba. Use recursion for the second routine.
Computers and Technology
1 answer:
fomenos4 years ago
5 0

Answer:

Here is the first routine:

void permute( const string &str ) {  // function with one parameter

 int low = 0;

 int high = str.length();

 permute(str, low, high);

}    

Or you can directly call it as:

 permute(str, 0, str.length());

Explanation:

The second routine:

void permute( const string &str, int low, int high)  

//function with three parameters

{ string str1 = str;

 if ( low == high ) {  //base case when last index is reached

   for (int i = 0; i <= high; ++i)

     cout << str1[i]; }  //print the strings  

 else {

   for (int i=low; i<high; ++i) {  // if base case is not reached

     string temp = str1;   //fix a character

     swap( str1[i], str1[low] ); //swap the values

     permute( str1, low + 1, high );  //calling recursive function (recursion case)

     swap( str1[i], str1[low] );     }  } } //swap again to go to previous position

In this function the following steps are implemented:

A character is fixed in the first position.

Rest of the characters are swapped with first character.

Now call the function which recursively repeats this for the rest of the characters.

Swap again to go to previous position, call the recursive function again and continue this process to get all permutations and stop when base condition is reached i.e. last index is reached such that high==low which means both the high and low indices are equal.

You can write a main() function to execute these functions.

int main() {

 string str;

 cout << "Enter a string: ";

 cin >> str;

 permute(str);  }

You might be interested in
You use a(n) ____ program to create, send, receive, forward, store, print, and delete e-mail messages.
tigry1 [53]

Answer:

B - E-Mail

Explanation:

This is a program to create, send, receive, forward, store, print, and delete e-mail messages.

3 0
3 years ago
You are working on a group project in which each member is required to collaborate on the write up the group wants to see what e
777dan777 [17]

Answer:

Track Changes?

Explanation:

5 0
3 years ago
What am I doing wrong?
Temka [501]

In your example, you're asking the user for a number and then you're setting total and nums equal to zero. This results in your first number being ignored by the program. I included the complete working code below:

num = int(input("Enter a number: "))

total = num

nums = 1

while (total <= 100):

   num = int(input("Enter a number: "))

   nums = nums + 1

   total = total + num

print("Sum: "+str(total))

print("Numbers Entered: "+str(nums))

I hope this helps!

8 0
3 years ago
Describe the steps that transform a program written in a high-level language such as C into a representation that is directly ex
Alla [95]

Answer:

First, you would want to translate from C-language Program (in text format) into the assembly language Program (still in text format, but in the corresponding architecture of the computer where the program will be run). The software tool you will use for this step is Compiler.

Then you would translate from the assembly language program (text format) into Machine Code Program (in binary format). The software tool used for this step would be Assembler.

7 0
2 years ago
You have been given an assignment to create a webpage that has a calming effect on the viewer. Which of these is most likely to
Elza [17]

Answer:

The answer should be D.

Explanation: Cool colors make someone feel calm,mainly blue and green

7 0
3 years ago
Read 2 more answers
Other questions:
  • MinMax is a function that takes five arguments and returns no value. The first three arguments are of type int. The last two arg
    14·1 answer
  • Which computer device helps you input data in the form of text, numbers, and commands?
    9·1 answer
  • How is a ink pen better than a digital pen.
    8·1 answer
  • What do you do to add a line or circle to your presentation?
    7·2 answers
  • The trade winds are the dominant surface winds from the subtropics to high latitudes. 1. True 2. False
    7·1 answer
  • Which of the following is the most significant outcome of the formation of the SMPTE?
    6·2 answers
  • You can remove selected text from a slide by pressing ctrl+x keyboard shortcut keys true or false
    7·1 answer
  • In a display device, response rate is the time it takes for one pixel to change from black to white then back to black.​
    12·1 answer
  • Virtualization:
    15·1 answer
  • A.)Distinguish between software suite and integrated software.
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!