Combinations (Row Wise)

Hey,

I want to make automated measurements varying several parameters. The User will be made to enter the different different values each row, e.g.:

a1 b1 c1
a2 b2 c2 d2 e2
a3 b3      d3      f3

Is there any way for generating list of Arrays containing all combinations in row direction like that:

a1 b1 c1
a1 c1 b1
b1 a1 c1
c1 b1 a1
..
..
a2 c2 d2 b2 e2
..
..
a3 b3 f3 d3

At the end the output should be directly to the printer or to a PDF file.
Is it possible?

Regards.
Rahul SehrawatAsked:
Who is Participating?
 
Infinity08Commented:
What you seem to be looking for, are permutations, not combinations.

And fortunately, there's a standard algorithm for that :

        http://cplusplus.com/reference/algorithm/next_permutation/

Check the code sample at that reference page to see how it's used.
0
 
ssnkumarCommented:
> Is there any way for generating list of Arrays containing all combinations in row direction
You can try this code sample:
 
#include <iostream>
#include <string>
using namespace std;

string orig_str;

void find_all_combinations(int l, string next_combination, bool done[])
{
    if (l == orig_str.length()) { // If we have reached the last char in the string
        cout << next_combination << endl;
    } else {
        int i;

        for (i = 0; i < orig_str.length(); i++) {
            if (!done[i]) {
                done[i] = true;
                find_all_combinations(l + 1, orig_str[i] + next_combination, done);
                done[i] = false;
            }
        }
    }
}

int main (int argc, char *argv[])
{
        bool done[4] = {false, false, false, false};

        orig_str = string(argv[1]);
        find_all_combinations(0, "", done); // 0 indicates we are starting at first char in the string
}

Open in new window


And for creating pdf file, you can try pdflib (http://www.pdflib.com) or FPDF (http://www.fpdf.org/).
0
 
Rahul SehrawatAuthor Commented:
Hey,

Thanks for the response. But this code doesnt seem to work. It says Invalid Null Pointer.

I am trying to run in on Visual C++.
0
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

 
ssnkumarCommented:
I used GNU C++ compiler to compile the code.
I don't have VC++ to test.

So, where is it telling "Invalid NULL Pointer"!?
This code doesn't use any pointers - so, where is it finding the NULL pointer!?
0
 
sarabandeCommented:
the code posted used a pointer at

orig_str = string(argv[1]);

Open in new window


what means it crashes if the string which should get assigned to orig_str was not passed as first argument from commandline.

in visual studio you could add a commandline argument at menu project - properties - configuration properties - debugging. but probably it would be better to get the input string from user input rather than from commandline.

to print the output you could write the results to a text file (extension .txt) and the call ShellExecute with operation "print" on that file. that would output to the default printer which also could be a pdf 'printer'.

Sara

0
 
Rahul SehrawatAuthor Commented:
I cant really cant get it working. Any other possible solutions. :(
0
 
Infinity08Commented:
>> I cant really cant get it working. Any other possible solutions. :(

What did you try ? How does it not work ? Did you try the standard algorithm - it's quite straightforward to use ...
0
 
Rahul SehrawatAuthor Commented:
somehow managed to do it :)
0
 
Infinity08Commented:
I'm glad to hear that :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.