/*
File name: Set.h
Author: Bo Bayles
E-mail address: bmb3h6@umr.edu
Description: This implementation file for the Set class's member functions.
*/

#include "Set.h"
#include <iostream>
using namespace std;
//Include the headers for the Set class and iostream functions.

Set::Set()
{
  for (int i = 0; i < iMAXSIZE; i++)
    pos[i] = false;
}
//Default constructor: Initialize each element in the array to false.

Set::Set(Set &s)
{
  for (int i = 0; i < iMAXSIZE; i++)
    pos[i] = s.pos[i];
}
//Copy constructor: Copy each element in the passed object's array to
//  the member variables.

Set::~Set()
{
  cout << "Set destructed!" << endl;
}
//Destructor: Output destruction message to the screen.

bool Set::isElement(const int iNumber)
{
  bool bResult = false;
  
  if (pos[iNumber] == true)
    bResult = true;
  
  return bResult;
}
//See if the position indicated by the passed integer evaluates to true.
//  If so, set bResult to true. Then return bResult to the calling function.
  
bool Set::isEmpty()
{
  bool bResult = true;
  
  for (int i = 0; i < iMAXSIZE; i++)
  {
    if (pos[i] == true)
    {
      bResult = false;
      break;
    }
  }

  return bResult;
}
//See if any positions in the array evaluate to true. If so, set bResult
//  to false and break out of the loop. Then return bResult.
    
void Set::addElement(const int iNumber)
{
 if (iNumber < 0 || iNumber > iMAXSIZE)
   cout << "Invalid entry" << endl;
 else
   pos[(iNumber - 1)] = true;
}
//Make sure the number being entered is in bounds. If so, set the loop
//  index's position in the array minus one to true.

void Set::deleteElement(const int iNumber)
{
 if (iNumber < 0 || iNumber > iMAXSIZE)
   cout << "Invalid entry" << endl;
 else
   pos[(iNumber - 1)] = false;
}
//Make sure the number being entered is in bounds. If so, set the loop
//  index's position in the array minus one to false.
  
Set Set::operator+(const Set s)
{
  Set resultSet;
  
  for (int i = 0; i < iMAXSIZE; i++)
  {
    if (s.pos[i] == true || pos[i] == true)
      resultSet.pos[i] = true;
  }
  
  return resultSet;
}
//Create a Set object in which to store results. Then loop through each
//  position of the arrays of both the current and passed objects. If
//  either's current position evaluates to true, set that position to true
//  in the result array. Then return the result object.

Set Set::operator*(const Set s)
{
  Set resultSet;
  
  for (int i = 0; i < iMAXSIZE; i++)
  {
    if (s.pos[i] == true && pos[i] == true)
      resultSet.pos[i] = true;
  }
  
  return resultSet;
}
//Create a Set object in which to store results. Then loop through each
//  position of the arrays of both the current and passed objects. If
//  both array's current position evaluates to true, set that position
//  to true in the result array. Then return the result object.

void Set::printOut()
{
  cout << "{";
  for (int i = 0; i < iMAXSIZE; i++)
  {
    if (pos[i] == true)
    {
      cout << (i + 1);
      if (pos[(i + 1)] == true)
        cout << ",";
    }          
  }  
  cout << "}" << endl;
}
//Output the { for the beginning of the set. Then, loop through the
//  object's array and output the loop index plus 1 to the screen
//  if the position evaluates to true. Then, check to see if the next
//  position evaluates to true. If so, there is another integer in the
//  set, so put a comma as a delimiter. Finally, output the } for the end.

