subsets of array

M

Marcus Kwok

Markus Schoder said:
It seems you are trying to enumerate all possible sets of integers with
a given number of elements whereas the original question was about the
subsets of a given set of integers (represented as an array), no?

E.g. the result for {1,2} would be the list {}, {1}, {2}, {1,2}. There
are by the way 2^n subsets of a set with n elements.

Yes, this is known as the Power Set.
 
T

TJW

BobR said:
BigBrian wrote in message ...

#include <iostream> // C++
#include <ostream> // std::endl

void Weiner(int array = 43){
std::cout<<"33 33 33 75 78 79 76 80 32 33 101 114 "
"101 104 32 112 108 101 104 32 111 110 "
"32 115 116 101 103 32 101 100 117 116 "
"105 116 116 97 32 110 97 32 104 116 105 "
"119 32 116 111 105 100 105 32 110 65 "<<std::endl;
Weiner(array+1);
return;
}

int main(){
Weiner(42);
return 0;
}

Please forgive a C programming who has been lurking for a while
to refresh his OO memory ... but what specifically will this print
and why? I see the recursive call, but am not used to initializing
variables in a function declaration ... will array be 43 always or
42, 43, 44, ... and with cout << will the integers be translated
into ASCII characters?

Sorry to ruin a good joke that I don't get ...

Thanks,
TJW
 
M

MeDevil

TJW ha scritto:
Please forgive a C programming who has been lurking for a while
to refresh his OO memory ... but what specifically will this print
and why? I see the recursive call, but am not used to initializing
variables in a function declaration ... will array be 43 always or
42, 43, 44, ... and with cout << will the integers be translated
into ASCII characters?

Sorry to ruin a good joke that I don't get ...

Thanks,
TJW


<snip> but what specifically will this print and why?
it will print always a string... (the one between the two <<)

<snip> will array be 43 always or 42, 43, 44,
that's a default argument. if you don't provide it, the specified value
will be used.
array will be at the first call 42, then 43 and so on, until a stack
overflow will crash all...

<snip> and with cout << will the integers be translated into ASCII
characters?
they are already ascii characters... in fact that is a const array of
char (a string) :p

MeDevil
 
B

BobR

TJW wrote in message ...
Please forgive a C programming who has been lurking for a while
to refresh his OO memory ... but what specifically will this print
and why? I see the recursive call, but am not used to initializing
variables in a function declaration ... will array be 43 always or
42, 43, 44, ... and with cout << will the integers be translated
into ASCII characters?

Sorry to ruin a good joke that I don't get ...
Thanks,
TJW

I agree with the explanation that MeDevil gave you, so, I won't repeat it
here.
[ If you still 'don't get it', ask more. ]

To help you 'decode' the message, here is the code I used to get the numbers:

std::string Rev("< the secret string was here >");
std::reverse(Rev.begin(), Rev.end());
for(size_t i(0); i < Rev.size(); ++i){
std::cout<<int( Rev.at(i) )<<" ";
}
std::cout<<std::endl;

You could get back the 'ASCII' with something like:
std::cout<<char(65)<<char(110)<<std::endl; // etc.

The default parameter in the arg list (int array = 43) is just for
distraction, it don't do nuthin' <G>

Coming to C++ from C? Do you know about Mr. Eckel's book? (It was pretty much
designed to take you from C to C++)
Get "Thinking in C++", 2nd ed. Volume 1(&2) by Bruce Eckel
(available for free here. You can buy it in hardcopy too.):
http://www.mindview.net/Books/TICPP/ThinkingInCPP2e.html
 
A

Alex Buell

The default parameter in the arg list (int array = 43) is just for
distraction, it don't do nuthin' <G>

arrayList.reverse();
for (std::list<int>::iterator i = arrayList.begin(); i !=
arrayList.end(); i++) std::cout << char(*i);

std::cout << "\n";
 
T

TJW

Hello,

BobR said:
To help you 'decode' the message, here is the code I used to get the numbers:

std::string Rev("< the secret string was here >");
std::reverse(Rev.begin(), Rev.end());
for(size_t i(0); i < Rev.size(); ++i){
std::cout<<int( Rev.at(i) )<<" ";
}
std::cout<<std::endl;

You could get back the 'ASCII' with something like:
std::cout<<char(65)<<char(110)<<std::endl; // etc.
Thanks for the expansion ... hopefully I'll have a little time
tonight to kick my brain some more and work out what the string
should be.
The default parameter in the arg list (int array = 43) is just for
distraction, it don't do nuthin' <G>
Yeah ... things started to come back to me after MeDevil's post.
Coming to C++ from C? Do you know about Mr. Eckel's book? (It was pretty much
designed to take you from C to C++)
Get "Thinking in C++", 2nd ed. Volume 1(&2) by Bruce Eckel
(available for free here. You can buy it in hardcopy too.):
http://www.mindview.net/Books/TICPP/ThinkingInCPP2e.html

Thanks for the tip, my classes in college where in C++, but I
stick mainly with C for most of my work and haven't looked at OO
programming much since then. Just trying to get my sea legs back,
so to speak.

Thanks again for the tip,
TJW
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,772
Messages
2,569,593
Members
45,111
Latest member
KetoBurn
Top