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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
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
Exploring SQL Server 2016: Fundamentals

Learn the fundamentals of Microsoft SQL Server, a relational database management system that stores and retrieves data when requested by other software applications.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.