Question

Assignment: Create a program which is capable of assembling and displaying various sets I will provide you with. The program

I can't get my code to work on xcode and give me an output.

#include <conio.h>

#include <cstdlib>

#include <fstream>

#include <iomanip>

#include <iostream>

#include <string>

#include <vector>

using namespace std; // So "std::cout" may be abbreviated to "cout"

//Declare global arrays

int dummy1[10];

int dummy2[10];

int dummy3[10];

int universalSet[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };

//Function to return statement "Empty thread" when the resultant set is

empty

string isEmpty(int arr[])

{

string e = "Empty thread\n\n";

string no = "";

int i;

while (arr[i] == 0 && i < 10)

{

i++;

}

//Test if set is empty

if (i == 10)

return e;

else

return no;

}

//Function to return the union of 2 sets -that is a set containing exactly

//one copy of each element that occurs in one or both sets

void UnionOfSets(int set1[], int set2[], int set3[])

{

for (int i = 0; i < 10; i++)

{

if (set1[i] || set2[i])

set3[i] = 1;

else

set3[i] = 0;

}

for (int i = 0; i < 10; i++)

{

if (set3[i] == 1)

cout << universalSet[i] << " ";

}

cout << endl << endl;

}

//Function to return the intersection of 2 sets -that is a set containing

//one copy of each element that appears in both sets

void IntersectionOfSets(int set1[], int set2[], int set3[])

{

for (int i = 0; i < 10; i++)

{

if (set1[i] && set2[i])

set3[i] = 1;

else

set3[i] = 0;

}

for (int i = 0; i < 10; i++)

{

if (set3[i] == 1)

cout << universalSet[i] << " ";

}

cout << endl << endl;

}

//Function to return the inverse of a set -that is the universal set

//minus the set

void inverseSet(int set1[], int set2[], int set3[])

{

for (int i = 0; i < 10; i++)

{

if (set1[i] && set2[i])

set3[i] = 0;

else

set3[i] = 1;

}

for (int i = 0; i < 10; i++)

{

if (set3[i] == 1)

cout << universalSet[i] << " ";

}

cout << endl << endl;

}

//Function that returns the result of one set being subtracted from

another

void subtractSet(int set1[], int set2[], int set3[])

{

//Copy array

for (int i = 0; i < 10; i++)

{

set3[i] = set1[i];

}

for (int i = 0; i < 10; i++)

{

if (set1[i] && set2[i])

set3[i] = 0;

else

set3[i] = 1;

}

for (int i = 0; i < 10; i++)

{

if (set3[i] == 1)

cout << universalSet[i] << " ";

}

cout << endl << endl;

}

//Function that returns the number of elements in a set

int count(int arr[])

{

int i = 0;

//Count number of objects in set

for (int j = 0; j < 10; j++)

{

if (arr[j] == 1)

i++;

}

return i;

}

//Function that prints the elements in each set

void printSet(int arr[])

{

for (int i = 0; i < 10; i++)

{

if (arr[i] !=0)

cout << universalSet[i] << " ";

}

cout << endl << endl;

}

int main()

{

//Declare sets

int A[] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};

int B[] = { 0, 1, 0, 1, 0, 1, 0, 1, 0, 1 };

int C[] = { 1, 0, 1, 0, 1, 0, 1, 0, 1, 0 };

int D[] = { 1, 1, 1, 0, 1, 0, 1 , 0, 0, 0 };

//Header

cout << "CSC 1501 Lab: 4" << endl;

cout << "----------------" << endl << endl;

//Print sets

cout << "Set A:\n";

printSet(A);

cout << "Set B:\n";

printSet(B);

cout << "Set C:\n";

printSet(C);

cout << "Set D:\n";

printSet(D); cout << endl << endl;

////////////////////////////////////////////////////////

//PROBLEM 1

cout << "-------------------------" << endl;

cout << "Problem 1.) A n D" << endl << endl;

cout << "\nA n D" << endl;

IntersectionOfSets(A, D, dummy1);

cout << endl << isEmpty(dummy1) << endl;

cout << "-------------------------" << endl << endl;

////////////////////////////////////////////////////////

////////////////////////////////////////////////////////

//PROBLEM 2

cout << "Problem 2.) ( B u C ) n A" << endl << endl;

cout << "\nB u C" << endl;

UnionOfSets(B, C, dummy1);

// (B u C) n A

cout << "(B u C) n A" << endl << endl;

IntersectionOfSets(A, dummy1, dummy2);

cout << endl << isEmpty(dummy2) << endl;

cout << "-------------------------" << endl << endl;

////////////////////////////////////////////////////////

////////////////////////////////////////////////////////

//PROBLEM 3

// !C

cout << "Problem 3.) (!C u C) n A" << endl << endl;

cout << "\n!C" << endl;

inverseSet(C, A, dummy1);

// (!C u C)

cout << "(!C u C)" << endl;

UnionOfSets(dummy1, C, dummy2);

// (!C u C) n A

cout << "(!C u C) n A" << endl;

IntersectionOfSets(A, dummy2, dummy3);

cout << endl << isEmpty(dummy3) << endl;

cout << "-------------------------" << endl << endl;

////////////////////////////////////////////////////////

////////////////////////////////////////////////////////

//PROBLEM 4

cout << "Problem 4.) A - D" << endl << endl;

cout << "\n(A - D)" << endl;

subtractSet(A, D, dummy1);

cout << endl << isEmpty(dummy1) << endl;

cout << "-------------------------" << endl << endl;

////////////////////////////////////////////////////////

////////////////////////////////////////////////////////

//PROBLEM 5

cout << "Problem 5.) N(!A u ( C u D))" << endl << endl;

// !A

cout << "\n!A" << endl;

inverseSet(A, universalSet, dummy1);

// (C u D)

cout << "(C u D)" << endl;

UnionOfSets(C, D, dummy2);

// (!A u (C u D))

cout << "(!A u (C u D))" << endl;

UnionOfSets(dummy1, dummy2, dummy3);

// N(!A u (C u D))

cout << endl << "There are " << count(dummy3) << " objects in the set: !A u (C u D)" << endl << endl;

cout << endl << isEmpty(dummy3) << endl;

cout << "-------------------------" << endl << endl;

////////////////////////////////////////////////////////

////////////////////////////////////////////////////////

//PROBLEM 6

cout << "Problem 6.) D n C" << endl << endl;

cout << "\n(D n C)" << endl;

IntersectionOfSets(D, C, dummy1);

cout << endl << isEmpty(dummy1) << endl;

cout << "-------------------------" << endl << endl;

////////////////////////////////////////////////////////

////////////////////////////////////////////////////////

//PROBLEM 7

cout << "Problem 7.) N(B n C)" << endl << endl;

cout << "\n(B n C)" << endl;

IntersectionOfSets(B, C, dummy1);

cout << "N(B n C)" << endl << endl;

cout << endl << "There are " << count(dummy1) << " objects in the set: B n D" << endl << endl;

cout << isEmpty(dummy1) << endl << endl;

cout << "-------------------------" << endl << endl;

////////////////////////////////////////////////////////

////////////////////////////////////////////////////////

//PROBLEM 8

cout << "Problem 8.) A u B u C u D" << endl << endl;

cout << "\n(A u B)" << endl;

UnionOfSets(A, B, dummy1);

// (C u D)

cout << "(C u D)" << endl << endl;

UnionOfSets(C, D, dummy2);

// (A u D) u (C u D)

cout << "(A u B) u (C u D)" << endl << endl;

UnionOfSets(dummy1, dummy2, dummy3);

cout << endl << isEmpty(dummy3) << endl;

cout << "-------------------------" << endl << endl;

////////////////////////////////////////////////////////

_getch();

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

/***********************************set.cpp**************************/

#include <conio.h>

#include <cstdlib>

#include <fstream>

#include <iomanip>

#include <iostream>

#include <string>

#include <vector>

using namespace std; // So "std::cout" may be abbreviated to "cout"

//Declare global arrays

int dummy1[10];

int dummy2[10];

int dummy3[10];

int universalSet[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };

//Function to return statement "Empty thread" when the resultant set is empty

string isEmpty(int arr[])

{

string e = "Empty thread\n\n";

string no = "";

int i;

while (arr[i] == 0 && i < 10)

{

i++;

}

//Test if set is empty

if (i == 10)

return e;

else

return no;

}

//Function to return the union of 2 sets -that is a set containing exactly

//one copy of each element that occurs in one or both sets

void UnionOfSets(int set1[], int set2[], int set3[])

{

for (int i = 0; i < 10; i++)

{

if (set1[i] || set2[i])

set3[i] = 1;

else

set3[i] = 0;

}

for (int i = 0; i < 10; i++)

{

if (set3[i] == 1)

cout << universalSet[i] << " ";

}

cout << endl << endl;

}

//Function to return the intersection of 2 sets -that is a set containing

//one copy of each element that appears in both sets

void IntersectionOfSets(int set1[], int set2[], int set3[])

{

for (int i = 0; i < 10; i++)

{

if (set1[i] && set2[i])

set3[i] = 1;

else

set3[i] = 0;

}

for (int i = 0; i < 10; i++)

{

if (set3[i] == 1)

cout << universalSet[i] << " ";

}

cout << endl << endl;

}

//Function to return the inverse of a set -that is the universal set

//minus the set

void inverseSet(int set1[], int set2[], int set3[])

{

for (int i = 0; i < 10; i++)

{

if (set1[i] && set2[i])

set3[i] = 0;

else

set3[i] = 1;

}

for (int i = 0; i < 10; i++)

{

if (set3[i] == 1)

cout << universalSet[i] << " ";

}

cout << endl << endl;

}

//Function that returns the result of one set being subtracted from another

void subtractSet(int set1[], int set2[], int set3[])

{

//Copy array

for (int i = 0; i < 10; i++)

{

set3[i] = set1[i];

}

for (int i = 0; i < 10; i++)

{

if (set1[i] && set2[i])

set3[i] = 0;

else

set3[i] = 1;

}

for (int i = 0; i < 10; i++)

{

if (set3[i] == 1)

cout << universalSet[i] << " ";

}

cout << endl << endl;

}

//Function that returns the number of elements in a set

int count(int arr[])

{

int i = 0;

//Count number of objects in set

for (int j = 0; j < 10; j++)

{

if (arr[j] == 1)

i++;

}

return i;

}

//Function that prints the elements in each set

void printSet(int arr[])

{

for (int i = 0; i < 10; i++)

{

if (arr[i] !=0)

cout << universalSet[i] << " ";

}

cout << endl << endl;

}

int main()

{

//Declare sets

int A[] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};

int B[] = { 0, 1, 0, 1, 0, 1, 0, 1, 0, 1 };

int C[] = { 1, 0, 1, 0, 1, 0, 1, 0, 1, 0 };

int D[] = { 1, 1, 1, 0, 1, 0, 1 , 0, 0, 0 };

//Header

cout << "CSC 1501 Lab: 4" << endl;

cout << "----------------" << endl << endl;

//Print sets

cout << "Set A:\n";

printSet(A);

cout << "Set B:\n";

printSet(B);

cout << "Set C:\n";

printSet(C);

cout << "Set D:\n";

printSet(D); cout << endl << endl;

////////////////////////////////////////////////////////

//PROBLEM 1

cout << "-------------------------" << endl;

cout << "Problem 1.) A n D" << endl << endl;

cout << "\nA n D" << endl;

IntersectionOfSets(A, D, dummy1);

cout << endl << isEmpty(dummy1) << endl;

cout << "-------------------------" << endl << endl;

////////////////////////////////////////////////////////

////////////////////////////////////////////////////////

//PROBLEM 2

cout << "Problem 2.) ( B u C ) n A" << endl << endl;

cout << "\nB u C" << endl;

UnionOfSets(B, C, dummy1);

// (B u C) n A

cout << "(B u C) n A" << endl << endl;

IntersectionOfSets(A, dummy1, dummy2);

cout << endl << isEmpty(dummy2) << endl;

cout << "-------------------------" << endl << endl;

////////////////////////////////////////////////////////

////////////////////////////////////////////////////////

//PROBLEM 3

// !C

cout << "Problem 3.) (!C u C) n A" << endl << endl;

cout << "\n!C" << endl;

inverseSet(C, A, dummy1);

// (!C u C)

cout << "(!C u C)" << endl;

UnionOfSets(dummy1, C, dummy2);

// (!C u C) n A

cout << "(!C u C) n A" << endl;

IntersectionOfSets(A, dummy2, dummy3);

cout << endl << isEmpty(dummy3) << endl;

cout << "-------------------------" << endl << endl;

////////////////////////////////////////////////////////

////////////////////////////////////////////////////////

//PROBLEM 4

cout << "Problem 4.) A - D" << endl << endl;

cout << "\n(A - D)" << endl;

subtractSet(A, D, dummy1);

cout << endl << isEmpty(dummy1) << endl;

cout << "-------------------------" << endl << endl;

////////////////////////////////////////////////////////

////////////////////////////////////////////////////////

//PROBLEM 5

cout << "Problem 5.) N(!A u ( C u D))" << endl << endl;

// !A

cout << "\n!A" << endl;

inverseSet(A, universalSet, dummy1);

// (C u D)

cout << "(C u D)" << endl;

UnionOfSets(C, D, dummy2);

// (!A u (C u D))

cout << "(!A u (C u D))" << endl;

UnionOfSets(dummy1, dummy2, dummy3);

// N(!A u (C u D))

cout << endl << "There are " << count(dummy3) << " objects in the set: !A u (C u D)" << endl << endl;

cout << endl << isEmpty(dummy3) << endl;

cout << "-------------------------" << endl << endl;

////////////////////////////////////////////////////////

////////////////////////////////////////////////////////

//PROBLEM 6

cout << "Problem 6.) D n C" << endl << endl;

cout << "\n(D n C)" << endl;

IntersectionOfSets(D, C, dummy1);

cout << endl << isEmpty(dummy1) << endl;

cout << "-------------------------" << endl << endl;

////////////////////////////////////////////////////////

////////////////////////////////////////////////////////

//PROBLEM 7

cout << "Problem 7.) N(B n C)" << endl << endl;

cout << "\n(B n C)" << endl;

IntersectionOfSets(B, C, dummy1);

cout << "N(B n C)" << endl << endl;

cout << endl << "There are " << count(dummy1) << " objects in the set: B n D" << endl << endl;

cout << isEmpty(dummy1) << endl << endl;

cout << "-------------------------" << endl << endl;

////////////////////////////////////////////////////////

////////////////////////////////////////////////////////

//PROBLEM 8

cout << "Problem 8.) A u B u C u D" << endl << endl;

cout << "\n(A u B)" << endl;

UnionOfSets(A, B, dummy1);

// (C u D)

cout << "(C u D)" << endl << endl;

UnionOfSets(C, D, dummy2);

// (A u D) u (C u D)

cout << "(A u B) u (C u D)" << endl << endl;

UnionOfSets(dummy1, dummy2, dummy3);

cout << endl << isEmpty(dummy3) << endl;

cout << "-------------------------" << endl << endl;

////////////////////////////////////////////////////////

}

/***************************output*****************************/

CSC 1501 Lab: 4
----------------

Set A:
1 2 3 4 5 6 7 8 9 10

Set B:
2 4 6 8 10

Set C:
1 3 5 7 9

Set D:
1 2 3 5 7

-------------------------
Problem 1.) A n D


A n D
1 2 3 5 7

-------------------------

Problem 2.) ( B u C ) n A


B u C
1 2 3 4 5 6 7 8 9 10

(B u C) n A

1 2 3 4 5 6 7 8 9 10

-------------------------

Problem 3.) (!C u C) n A


!C
2 4 6 8 10

(!C u C)
1 2 3 4 5 6 7 8 9 10

(!C u C) n A
1 2 3 4 5 6 7 8 9 10

-------------------------

Problem 4.) A - D


(A - D)
4 6 8 9 10

-------------------------

Problem 5.) N(!A u ( C u D))


!A


(C u D)
1 2 3 5 7 9

(!A u (C u D))
1 2 3 5 7 9


There are 6 objects in the set: !A u (C u D)

-------------------------

Problem 6.) D n C


(D n C)
1 3 5 7

-------------------------

Problem 7.) N(B n C)


(B n C)


N(B n C)


There are 0 objects in the set: B n D

Empty thread

-------------------------

Problem 8.) A u B u C u D


(A u B)
1 2 3 4 5 6 7 8 9 10

(C u D)

1 2 3 5 7 9

(A u B) u (C u D)

1 2 3 4 5 6 7 8 9 10

-------------------------

DAFileset.exe CSC 1501 Lab: 4 Set A: 1 2 3 456 7 8 910 Set B: 2 46 8 10 Set C 1 3 57 9 Set D: 1 2357 Problem 1.) A n D A n DD:Filelset.exe Problem 3.) (!C u C)nA lt 2 468 10 (!C u C) 1 2 3 45678 9 10 (ICuC)nA 1 2 3 45678 9 10 Problem 4.)A-D (A - D)

DFilelset.exe Problem 6.) D n С (D n C) 1 3 57 Problem 7.) N(B n C) (B n C) N(B n C) There are e objects in the set: B n D Em

Please let me know if you have any doubt or modify the answer, Thanks :)

Add a comment
Know the answer?
Add Answer to:
I can't get my code to work on xcode and give me an output. #include <conio.h> #include <cstdlib> #incl...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I am having trouble with my C++ program.... Directions: In this lab assignment, you are to...

    I am having trouble with my C++ program.... Directions: In this lab assignment, you are to write a class IntegerSet that represents a set of integers (by definition, a set contains no duplicates). This ADT must be implemented as a singly linked list of integers (with no tail reference and no dummy head node), but it need not be sorted. The IntegerSet class should have two data fields: the cardinality (size) of the set, and the head reference to the...

  • import java.util.*; /** * A class that implements the ADT set by using a linked bag....

    import java.util.*; /** * A class that implements the ADT set by using a linked bag. * The set is never full. * * */ public class LinkedSetWithLinkedBag> implements SetInterface { private LinkedBag setOfEntries; /** * Creates a set from a new, empty linked bag. */ public LinkedSetWithLinkedBag() { //TODO Project1 } // end default constructor public boolean add(T newEntry) { //TODO Project1 // new node is at beginning of chain if(this.setOfEntries.isEmpty()) { if (!this.setOfEntries.contains(newEntry)) this.setOfEntries.add(newEntry); } return true; //...

  • I need help fixing my code: In C++ *************** 1) I want to sum the digits...

    I need help fixing my code: In C++ *************** 1) I want to sum the digits of an n*n matrix 2) find the average I have completed the rest ****Do not use C++ standard library. You must use pointers and pointer arithmetic to represent the matrix and to navigate through it. MY CODE: (I have indicated at which point I need help) #include <iostream> using namespace std; void swap(int *xp, int *yp) { int temp = *xp; *xp = *yp;...

  • Hello, I need help with my code. The code needs to display random number from 1...

    Hello, I need help with my code. The code needs to display random number from 1 to 50 every time the program runs but the program displays the same random numbers every time. Thanks #include #include using namespace std; void dynAlloc(int size, int *&arr); void displayArray(int *arr, int n); void insertionSort(int *arr, int n, int *temp); void linear_search(int *arr, int n, int key); void binary_search(int *arr, int n, int key); int main() {   const int n = 50; int *arr,...

  • Need help with my ksmall program. I get an error saying segmentation dump. Thanks #include<iostream> using...

    Need help with my ksmall program. I get an error saying segmentation dump. Thanks #include<iostream> using namespace std; int ksmall(int*, int, int , int); void swap(int*, int*); int main() {     int SIZE = 10;     int target;     int begining=0;     int ending=SIZE-1;     int *array1= new int[SIZE];     cout << "Enter 10 integers: " << endl;     for (int i=0; i<SIZE; i++)     {        cin>>array1[i];     }     cout << " What is the Kth smallest number...

  • Hello, I have some errors in my C++ code when I try to debug it. I...

    Hello, I have some errors in my C++ code when I try to debug it. I tried to follow the requirements stated below: Code: // Linked.h #ifndef INTLINKEDQUEUE #define INTLINKEDQUEUE #include <iostream> usingnamespace std; class IntLinkedQueue { private: struct Node { int data; Node *next; }; Node *front; // -> first item Node *rear; // -> last item Node *p; // traversal position Node *pp ; // previous position int size; // number of elements in the queue public: IntLinkedQueue();...

  • C++ how can I fix these errors this is my code main.cpp #include "SpecialArray.h" #include <...

    C++ how can I fix these errors this is my code main.cpp #include "SpecialArray.h" #include <iostream> #include <fstream> #include <string> using namespace std; int measureElementsPerLine(ifstream& inFile) {    // Add your code here.    string line;    getline(inFile, line);    int sp = 0;    for (int i = 0; i < line.size(); i++)    {        if (line[i] == ' ')            sp++;    }    sp++;    return sp; } int measureLines(ifstream& inFile) {    // Add your code here.    string line;    int n = 0;    while (!inFile.eof())    {        getline(inFile,...

  • graph binary search for size and time c++ //System Libraries #include <iostream> #include <string> #include <cstdlib> #include <ctime> #include <iomanip> #include <alg...

    graph binary search for size and time c++ //System Libraries #include <iostream> #include <string> #include <cstdlib> #include <ctime> #include <iomanip> #include <algorithm> using namespace std; //User Libraries //Global Constants, no Global Variables are allowed //Math/Physics/Conversions/Higher Dimensions - i.e. PI, e, etc... //Function Prototypes //Execution Begins Here! int main(int argc, char** argv) { int n, i, arr[50], search, first, last, middle,count=0,count_in,tot; clock_t start, end; float duration; cout<<"Enter total number of elements :"; cin>>n; cout<<"Enter numbers"; for (i=0; i<n;i++) cin>>arr[i]; cout<<"Enter a...

  • I need to modify my C++ code so it can get the min value of the...

    I need to modify my C++ code so it can get the min value of the stack code is as follows: #include <iostream> using namespace std; #define MAX_SIZE 100 class Stack { private: int S[MAX_SIZE]; int top; public: Stack() {   top = -1; } void push(int x) {   if (top == MAX_SIZE - 1) {    cout << "Stack is Full." << endl;    return;   }   S[++top] = x; } void pop() {   if (top == -1) {    cout << "Stack is...

  •      program will enter data into two single dimension arrays (do not st...

         program will enter data into two single dimension arrays (do not store duplicate values in arrays)      program will find the union and intersection of the two arrays using one function      program will find the symmetric difference of two arrays      program will display the union, intersection, and symmetric difference   */     short* input_data(short size);   // function to dynamically allocate and array and enter data into the array void display_data(short *data, short size); // function to display data in an array void get_union_intersection(short...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT