You need to write a permute class that will take first and second strings to rearrange letters in first, followed by second. For example, if the first is “CAT” string and second is “MAN” string, then the program would print the strings TACMAN, ATCMAN, CTAMAN, TCAMAN, ACTMAN, and CATMAN. The first and second strings can be any length of string or a null.
The permute class uses a Note class as link list note to link all letters arrangement. The permute class has Note pointers, firstNote and lastNote, to point to the beginning and ending Notes of the link list as private data members. There are three other private data members (total, firstString and secondString) to store the total possible number of arrangements and strings pass into the class.
Write a driver to test the permute class to pass in any two strings of any sizes.
Other than mention in the following, you can add more classes, functions, and private data members to this program.
Note class
The Note class needs to have two private data members and a constructor. The two private data members are data and p pointer. The data’s data type is string and p pointer is Note. The Note class constructor has two parameters, one is string and the other is Note pointer.
Permute class
The Permute class has five private data members (*firstNote, *lastNote, total, firstString and secondString). The firstNote and lastNote pointers are point to Note. The total has integer data type. The firstString and secondString have string data type.
There should have at least three public member functions, Permute, permutation and print. The Permute function is the constructor which takes strings to initialize the private data members. The permutation function does the recursive call to arrange the strings and setup the link list. The print function will print out the private data member information.
Driver file
The driver file should declare a Permute eight elements pointer array. Instantiate eight Permute object with the following eight set of data and assign the object to the pointer array. Use a repetition to call the object’s print function to print out the private data member information. If the total of the permute private data member is less than 100 then print out the permutated letters four in a row, otherwise print out 9 in a row.
first = "", second="",
first = "", second ="CATMAN",
first = "C", second ="ATMAN",
first = "CA", second ="TMAN",
first = "CAT", second ="MAN",
first = "CATM", second ="AN",
first = "CATMA", second ="N",
first 1 = "CATMAN", second ="";
and here is the output of the should look like:
String 1 for this object is:
String 2 for this object is:
There is no permutation.
String 1 for this object is:
String 2 for this object is: CATMAN
The total possible permutation is 1
That is:
CATMAN
String 1 for this object is: C
String 2 for this object is: ATMAN
The total possible permutation is 1
That is:
CATMAN
String 1 for this object is: CA
String 2 for this object is: TMAN
The total possible permutation is 2
They are:
ACTMAN CATMAN
String 1 for this object is: CAT
String 2 for this object is: MAN
The total possible permutation is 6
They are:
TACMAN ATCMAN CTAMAN TCAMAN
ACTMAN CATMAN
String 1 for this object is: CATM
String 2 for this object is: AN
The total possible permutation is 24
They are:
MTACAN TMACAN AMTCAN MATCAN
TAMCAN ATMCAN CMTAAN MCTAAN
TCMAAN CTMAAN MTCAAN TMCAAN
ACMTAN CAMTAN MACTAN AMCTAN
CMATAN MCATAN TACMAN ATCMAN
CTAMAN TCAMAN ACTMAN CATMAN