Question
Code this assignment in C++ using the proper libraries This assignment is to write a program that reads a set of strings from the standard
Code this assignment in C++ using the proper libraries
This assignment is to write a program that reads a set of strings from the standard input (keyboard), generates all permutations of that the strings, and then display the results to the standard output (screen).
You may use any of the standard library types (e.g., the containers that we learned in the class) in your implementation, including library functions from the
Be sure to include the reference(s) that you learn the
A permutation is defined as an ordered arrangement of a set of objects. For example, the following set of three distinct strings would have six permutations:
Strings: ab c de
Permutations:
1. ab c de
2. ab de c
3. c ab de
4. c de ab
5. de ab c
6. de c ab
Here is some information about the algorithm library: http://www.cplusplus.com/reference/algorithm/
You may use the following code as a starting point. Youll
need to implement generate_permutations and print_permutations functions.
int main(int argc,char* argv[])
{
list
string aLine, aString;
//read in strings from stdin
cout<<"Enter strings, separated by a space:";
getline(cin, aLine);//read a line from keyboard
istringstream iss(aLine);//use
//parse each string
while(iss >> aString)
{
inputList.push_back(aString);
}
auto permutations = generate_permutations(inputList);
//print permutations to stdout
print_permutations(permutations);
return 0;
}
Extra Credits (10 points):
Assume that the input set of strings may contain duplicates, i.e. your input could be ab, c, ab. This set should produce only two permutations (ab c and c ab) since the second ab is a duplicate. Implement the extra functionality to handle duplicates in the input and generate the correct result.
Example test outputs:
Enter strings, separated by a space: 1 22 3
Permutations are:
1. 1 22 3
2. 1 3 22
3. 22 1 3
4. 22 3 1
5. 3 1 22
6. 3 22 1
Enter strings, separated by a space: a b cd ef
Permutations are:
1. a b cd ef
2. a b ef cd
3. a cd b ef
4. a cd ef b
5. a ef b cd
6. a ef cd b
7. b a cd ef
8. b a ef cd
9. b cd a ef
10. b cd ef a
11. b ef a cd
12. b ef cd a
13. cd a b ef
14. cd a ef b
15. cd b a ef
16. cd b ef a
17. cd ef a b
18. cd ef b a
19. ef a b cd
20. ef a cd b
21. ef b a cd
22. ef b cd a
23. ef cd a b
24. ef cd b a
The program does not handle the duplicates correctly (your result may differ depending on how the permutations are generated)
Enter strings, separated by a space: 1 22 1
Permutations are:
1. 1 22 1
2. 22 1 1
The program handles the duplicates correctly
Enter strings, separated by a space: 1 22 1
Permutations are:
1. 1 22
2. 22 1
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started