//
//
//      AUTHOR: Russell Lowke
//         T.F: Francis Crick
//  CSCIE-s111: Unit Six, Easy Supp - question 1 [worth 3pts],  7/24/2002
//
//  function that converts a character string of uppercase letters
//  into an integer whose bits stand for 'A' (bit 0) through 'Z' (bit 25)
// 
// read two srings as input and produce a list of all letters that occur
// in one string but not the other


#include <iostream>
#include <iomanip>

int const MAXSTR    = 80;
int const CHARRANGE = ('Z' - 'A' + 1);

//
//  Get a string [str] of length maxLength
//
void getString(char * query, char * str, int maxLength)
{
	cout << query;							// ask query
	
	cin >> ws;								// remove all the white spaces
	cin.getline(str, maxLength);			// read characters until \n MAXSTR
}


void setBit(int& bits, int val)
{
	bits |= (1 << val);
}


void clearBit(int& bits, int val)
{
	bits &= ((1 << val) ^ 255);
}


bool getBit(int bits, int val)
{
	return (bits & (1 << val) );
}


void storeUpperCase(int& bits, char* str)
{
	while (*str) {
		if (*str >= 'A' && *str <= 'Z') {
			setBit(bits, (*str - 'A') );
		}
		str++;
	}
}

void printBitset(int bits)
{
	cout << "{ ";
	for (int i = 0; i < CHARRANGE; i++) {
		if (getBit(bits, i)) {
			cout << char (i + 'A') << " ";
		}
	}
	cout << "}" << endl;
}

int main()
{
	char str1[MAXSTR], str2[MAXSTR];
	int bits1st = 0, bits2nd = 0, bitsR = 0;
	
	getString("character string 'A': ", str1, MAXSTR);
	cout << "set A: ";
	storeUpperCase(bits1st, str1);
	printBitset(bits1st);
	
	getString("character string 'B': ", str2, MAXSTR);
	cout << "set B: ";
	storeUpperCase(bits2nd, str2);
	printBitset(bits2nd);
	
	cout << "Symmetric difference of both sets" << endl;
	bitsR = bits1st ^ bits2nd;
	printBitset(bitsR);
	
	exit( 0 );
}
