commets pls include ArrayBagh include SetFunctionsh include

commets pls,

#include \"ArrayBag.h\"

#include \"SetFunctions.h\"

#include <string>

using namespace std;

int main()

{

  

  

ifstream inFile(\"setInput.txt\");

if (inFile.fail()) //check if file is open or failed

{

cout << \"file could not open\" << endl; //if file not opened print a error message

}

else

{

Set bag1,bag2;

bag1.readfile(inFile);

bag2.readfile(inFile);

  

inFile.close();

  

cout << \"bag1:\" << endl; cout << bag1 << endl << endl;

cout << \"bag2:\" << endl; cout << bag2 << endl << endl;

cout << \"bag1 - bag2:\" << endl; cout << bag1 - bag2 << endl<< endl;

cout << \"bag1 + bag2:\" << endl; cout << bag1 + bag2 << endl << endl;

}

  

}

#include \"ArrayBag.h\"

#include \"SetFunctions.h\"

#include <fstream>

#include <sstream>

#include <string>

using namespace std;

Set::Set()

{

bag = ArrayBag();

}

bool Set::add(int newValue)

{

if(!bag.contains(newValue))

return bag.add(newValue);

if( bag.getCurrentSize() < bag.getMaxSize() )

return true;

  

else

return false;

}

bool Set::remove(int removeValue)

{

return bag.remove(removeValue);

}

bool Set::readfile(ifstream& inFile)

{

stringstream ss;

int tempInt;

string readString;

  

getline(inFile, readString);

ss << readString;

  

while(!ss.eof())

{

ss >> tempInt;

if(ss.fail())

{

cout << \"Input contains non-integer data \ \" << endl;

ss.clear();

return false;

}

add(tempInt);

}

return true;

  

}

Set operator+(const Set lhs, const Set rhs)

{

Set Union;

for(int i = 0; i < lhs.bag.getCurrentSize(); i++)

{

Union.add(lhs.bag[i]);

}

for(int i = 0; i < rhs.bag.getCurrentSize(); i++)

{

Union.add(rhs.bag[i]);

}

return Union;

}

Set operator-(const Set lhs, const Set rhs)

{

Set difference;

  

for(int i = 0; i < lhs.bag.getCurrentSize(); i++)

{

difference.add(lhs.bag[i]);

}

  

for(int i = 0; i < rhs.bag.getCurrentSize(); i++)

{

difference.remove(rhs.bag[i]);

}

return difference;

}

ostream& operator<<(ostream &op, const Set output)

{

for(int i = 0; i < output.bag.getCurrentSize(); i++)

{

op << output.bag[i] <<\'\\t\';

}

  

return op;

}

#include\"ArrayBag.h\"

#include<iostream>

#include<fstream>

using namespace std;

class Set

{

private:

ArrayBag bag;

  

public:

Set();

bool add(const int newValue);

  

bool remove(const int removeValue);

  

bool readfile( ifstream& inFile);

  

friend Set operator+(const Set lhs, const Set rhs);

  

friend Set operator-(const Set lhs, const Set rhs);

friend ostream& operator<<(ostream &os, const Set output);

};

Set operator+(const Set lhs, const Set rhs);

Set operator-(const Set lhs, const Set rhs);

ostream& operator<<(ostream &op, const Set output);

Solution

Here is the code for you:

//commets pls,
#include \"ArrayBag.h\"
#include \"SetFunctions.h\"
#include <string>
using namespace std;
int main()
{
  
  
ifstream inFile(\"setInput.txt\");   //Creates an input file stream with the specified file.
if (inFile.fail()) //check if file opening failed
{
cout << \"file could not open\" << endl; //if file not opened print a error message
}
else       //If not failed.
{
Set bag1,bag2;   //Declares 2 objects of type Set.
bag1.readfile(inFile);   //Reads the object bag1 from the file stream.
bag2.readfile(inFile);   //Reads the object bag2 from the file stream.
  
inFile.close();   //Close the file stream.
  
cout << \"bag1:\" << endl; cout << bag1 << endl << endl;   //Prints the bag1 object.
cout << \"bag2:\" << endl; cout << bag2 << endl << endl;   //Prints the bag2 object.
cout << \"bag1 - bag2:\" << endl; cout << bag1 - bag2 << endl<< endl;   //Prints the result of bag1 - bag2.
cout << \"bag1 + bag2:\" << endl; cout << bag1 + bag2 << endl << endl;   //Prints the result of bag1 + bag2.
}
  
}
#include \"ArrayBag.h\"
#include \"SetFunctions.h\"
#include <fstream>
#include <sstream>
#include <string>
using namespace std;
Set::Set()       //Set class constructor.
{
bag = ArrayBag();   //Creates an ArrayBag.
}
bool Set::add(int newValue)   //Adds an element to set, and returns true if added, and false otherwise.
{
if(!bag.contains(newValue))   //If the bag doesn\'t contains the newValue.
return bag.add(newValue);   //Add it to the set, and return the value.
if( bag.getCurrentSize() < bag.getMaxSize() )   //If the bag current size is less than the allowable maximum bag size.
return true;               //Return true.
  
else                       //If not.
return false;               //Return false.
}
bool Set::remove(int removeValue)   //Removes an element from the set, and return true, if removed successfully.
{
return bag.remove(removeValue);       //Calls the remove() method to remove the removeValue from the bag object.
}
bool Set::readfile(ifstream& inFile)   //Reads the set from the file stream inFile.
{
stringstream ss;       //Declares a stringstream.
int tempInt;           //Declares an integer.
string readString;       //Declares a string.
  
getline(inFile, readString);   //Reads a line of text from filestream into string.
ss << readString;               //Creates a string stream with that read string.
  
while(!ss.eof())               //As long as the string stream is not empty.
{
ss >> tempInt;                   //Read an integer from stream.
if(ss.fail())                   //If the reading fails.
{
cout << \"Input contains non-integer data \ \" << endl;   //Print to screen, that read value is not integer.
ss.clear();                       //And clear the stream.
return false;                   //Return false.
}
add(tempInt);                   //If reading succeeds, add the integer to Set.
}
return true;                   //Return true.
  
}
Set operator+(const Set lhs, const Set rhs)   //Adds 2 sets, i.e., performs union operation for sets lhs, and rhs.
{
Set Union;   //Declares a set union.
for(int i = 0; i < lhs.bag.getCurrentSize(); i++)   //For each element in the set lhs.
{
Union.add(lhs.bag[i]);       //Add it to the newly created set union.
}
for(int i = 0; i < rhs.bag.getCurrentSize(); i++)   //For each element in the set rhs.
{
Union.add(rhs.bag[i]);       //Add it to the newly created set union.
}
return Union;               //Returns the newly created set union.
}
Set operator-(const Set lhs, const Set rhs)   //Finds the difference between the set lhs, and rhs.
{
Set difference;   //Declares a set difference.
  
for(int i = 0; i < lhs.bag.getCurrentSize(); i++)   //For each element in set lhs.
{
difference.add(lhs.bag[i]);   //Add it to newly created set difference.
}
  
for(int i = 0; i < rhs.bag.getCurrentSize(); i++)   //For each element in set rhs.
{
difference.remove(rhs.bag[i]);   //Remove it from the set difference.
}
return difference;               //Return the newly created set difference.
}
ostream& operator<<(ostream &op, const Set output)   //Overloads the outputstream operator.
{
for(int i = 0; i < output.bag.getCurrentSize(); i++)   //For each element in the set output.
{
op << output.bag[i] <<\'\\t\';   //Add it to the output stream op, succeeding with a space.
}
  
return op;   //Returns op.
}
#include\"ArrayBag.h\"
#include<iostream>
#include<fstream>
using namespace std;
class Set   //Defines a Set class.
{
private:       //Declares private variables.
ArrayBag bag;   //An object bag of type ArrayBag
  
public:           //Declares public methods.
Set();           //Declares a constructor.
bool add(const int newValue);   //Declares a method add()
  
bool remove(const int removeValue);   //Declares a method remove()
  
bool readfile( ifstream& inFile);   //Declares a method readFile()
  
friend Set operator+(const Set lhs, const Set rhs);   //Overloads the + operator.
  
friend Set operator-(const Set lhs, const Set rhs);   //Overloads the - operator.
friend ostream& operator<<(ostream &os, const Set output);   //Overloads the outputstream operator.
};
Set operator+(const Set lhs, const Set rhs);   //Overloads the + operator.
Set operator-(const Set lhs, const Set rhs);   //Overloads the - operator.
ostream& operator<<(ostream &op, const Set output);   //Overloads the outputstream operator.

commets pls, #include \
commets pls, #include \
commets pls, #include \
commets pls, #include \
commets pls, #include \
commets pls, #include \
commets pls, #include \

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site