I think I got it.... There are a few other things I had to do also... Is there an easy way to condense this down using functions or whatever? I'm sure there is... but it's too late to try now and was just wondering.
Here is what I have:
#include <iostream>
using namespace std;
Code:
int main()
{
unsigned int n1, n2, temp, temp2;
cout << "Please insert your first number used for calculation:" << endl;
cin >> n1;
cout << "Please insert your second number now:" << endl;
cin >> n2;
char ch = 'a';
char ch2 = 'a';
temp = n1;
temp2 = n2;
// Part "A" //
cout << endl << "Set A = { ";
for(int i = 0; i < 26; i++)
{
if(temp%2 == 1)
{
cout << ch << " ";
ch++;
temp = temp >> 1;
}
else
{
temp = temp >> 1;
ch++;
}
}
cout << "}" << endl;
cout << "Set B = { ";
for(int i = 0; i < 26; i++)
{
if(temp2%2 == 1)
{
cout << ch2 << " ";
ch2++;
temp2 = temp2 >> 1;
}
else
{
temp2 = temp2 >> 1;
ch2++;
}
}
cout << "}" << endl;
// Part "B" //
int Union = n1 | n2;
temp = Union;
ch = 'a';
cout << "Union of the 2 sets = { ";
for(int i = 0; i < 26; i++)
{
if(temp%2 == 1)
{
cout << ch << " ";
ch++;
temp = temp >> 1;
}
else
{
temp = temp >> 1;
ch++;
}
}
cout << "}" << endl;
// Part "C" //
int Intersection = n1 & n2;
temp = Intersection;
ch = 'a';
cout << "Intersection of the 2 sets = { ";
for(int i = 0; i < 26; i++)
{
if(temp%2 == 1)
{
cout << ch << " ";
ch++;
temp = temp >> 1;
}
else
{
temp = temp >> 1;
ch++;
}
}
cout << "}" << endl;
// Part "D" //
int Difference = Intersection ^ n1;
temp = Difference;
ch = 'a';
cout << "Difference of the 2 sets = { ";
for(int i = 0; i < 26; i++)
{
if(temp%2 == 1)
{
cout << ch << " ";
ch++;
temp = temp >> 1;
}
else
{
temp = temp >> 1;
ch++;
}
}
cout << "}" << endl << endl;
}