permutation function call help.

Doing an exercise that states...

A permutation of three objects, a, b, and c, is any arrangement of these objects in a row. For example, some of the permutations of these objects are abc, bca, and cab. The number of permutations of three objects is six. Suppose that these three objects are strings. Write a program that prompts the user to enter three strings. The program then outputs the six permu- tations of those strings

Found this page
http://forum.codecall.net/topic/64715-how-to-generate-all-permutations/
, but having trouble integrating..
any feedback help would be really appreciated.



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>

using namespace std;

int main(int argc, const char * argv[])
{
    string objects[3];
    for (int i = 0, k = 1; i < 3; i++, k++) {
        cout << "Please enter a string: " << endl;
        cin >> objects[i];
        if (k == 3) {
            cout << "We made it here: debug print" << endl;
            for (i = 0; i < 3; i ++) {
              //  enter permutation function call here...
            }
        }
    }

    return 0; 

}



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <iostream>

using namespace std;
void permut(string s);

int main(int argc, const char * argv[])
{
    string objects[3];
    for (int i = 0, k = 1; i < 3; i++, k++) {
        cout << "Please enter a string: " << endl;
        cin >> objects[i];
        if (k == 3) {
            cout << "We made it" << endl;
            for (i = 0; i < 3; i ++) {
                permut(objects[i]);
            }
        }
    }

    return 0; 

}

void permut(string s){
    do{
        cout<<s<<std::endl;
    }
    while(next_permutation(s.begin(),s.end()));
}
Last edited on
Topic archived. No new replies allowed.