Problem: Set Operations +-------------------------------+ Mathematically, a set
ID: 3762463 • Letter: P
Question
Problem: Set Operations
+-------------------------------+
Mathematically, a set is said to be consists of well-defined elements. For instance, the following are well-defined sets.
A = {1, 2, 3, A, 5, 6, 7, G}
B = {2, 3, 4, 8, 9, B}
A set may be described using other types of expression; specially, if the set has elements (members) that are numerous to list.
There are a well-defined operations that can be performed on sets.
The class should be called Operation
1. Determining a given set A is a subset of B, or not and set B is a subset of A, or not. (This should be a function called SubsetOfA and SubsetofB)
A is-a-subset-of B ==> false
B is-a-subset-of A ==> false
2. Union of sets: finds all elements of both A and B and generates a unique set. (This should be a function called UnionofAandB)
A union B = {1, 2, 3, 4, 5, 6, 7, 8, 9}
3. Intersection of sets: determines common elements that belong to both A and B. (This should be a function called IntersectionofAandB)
A intersection-of B = {2, 3, 4}
4. Complement of sets: given the following sets (This should be a function called ComplementAtoB and ComplementBtoA)
A = {1, 2, 3, 4} and B = {5, 2, 3, 8}
A - B = {1, 4} or B - A = {5, 8}
Tasks Requirement
+---------------------------+
1. You are to develop a "Set Operation Calculator" using C++ Object Oriented Programming. The cpp file should be name operationLastNameFirstName.cpp
2. Expressions are read from file call input.dat and their solutions are displayed on the display monitor and out to a file called output_LastNameFirstName.dat. (Hints: It could be letters too) Create a file with 2 line the first line is input for A and the second line should be the input for B
3. These operations must be supported: subset, union (+), intersection (^), and Complement (-). You must create 4 functions for each of the operations.
Example, Given these sets: A = {1, 2, 3, 4, F, Z} and B = {5, 2, 3, 8, Z}
A is-a-subset-of B ==> false
B is-a-subset-of A ==> false
A + B = {1, 2, 3, 4, 5, 8, F, Z}
A ^ B = {2, 3, Z}
A - B = {1, 4, F}
B - A = {5, 8}
Explanation / Answer
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
class Operation
{
private:
bool flag;
public:
string SubsetOfA()
{
cout << "A is-a-subset-of B ==> ";
}
string SubsetOfB()
{
cout << "B is-a-subset-of A ==> ";
}
string UnionofAandB()
{
cout << "A + B = {";
}
string IntersectionofAandB()
{
cout << "A ^ B = {";
}
string ComplementAtoB()
{
cout << "A - B = {";
}
string ComplementBtoA()
{
cout << "B - A = {";
}
};
int main()
{
string data, data1, data2;
ifstream op;
ofstream nop;
op.open("input.dat");
nop.open("output_BashirRamie.dat");
while (!op.eof())
{
getline(op, data);
cout << data << endl;
nop << data << endl;
}
while (!' ')
{
getline(op, data1);
cout << data << endl;
nop << data << endl;
}
while (!op.eof()) // Here I want to get the second line from my DAT file
{
getline(op, data2);
cout << data << endl;
nop << data << endl;
}
system("pause");
return (0);
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.