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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
int main()
{
unsigned long max;
string natural = ""; // bitstring to hold numbers 0, 1, 2, 3, 4, ...
string evens = ""; // bitstring to hold numbers 2, 4, 6, 8, 10, ...
string odds = ""; // bitstring to hold numbers 1, 3, 5, 7, 9, ...
string fibonacci = ""; // bitstring to hold numbers 0, 1, 1, 2, 3, 5, ...
string *sets[4];
sets[0] = ♮
sets[1] = &evens;
sets[2] = &odds;
sets[3] = &fibonacci;
char option;
// prompt for max / limit
cout << "How big would you like to display each set?\n"
<< "(Please insert a value between 0 and 18,446,744,073,709,551,615)\n"
<< ">";
cin >> max;
//cerr << "you have selected: " << max << endl;
// fill set arrays
cout << "Generating Sets...\n";
for (int i = 0; i < max; i++)
{
natural += "1";
if ((i % 2) && (i > 0))
{
evens += "0";
odds += "1"; // the number is odd
}
else if (i > 0)
{
evens += "1"; // the number is even
odds += "0";
}
else // the first number is a 0, therefore neither even nor odd
{
evens += "0";
odds += "0";
}
}
for (int i = 0; i < 4; i++)
cerr << *sets[i] << endl; // this displays the string sets using the
// pointer
cerr << "first element of even numbers: " << sets[1][0] << endl;
cerr << "Set of Naturals: " << natural << endl;
cerr << "Set of Evens: " << evens << endl;
cerr << "Set of Odds: " << odds << endl;
...
|