Ask Question
10 April, 00:58

Have main create two objects: setA and setB. Input the values into setA (end with a 0 or negative) and input the values into setB (end with 0 or negative). Print the ordered pairs using printOrderedPairs. Print if setA is a subset of setB. Then print if setA is a proper subset of setB.

+1
Answers (1)
  1. 10 April, 01:16
    0
    C code is explained below

    Explanation:

    Sets. h:

    #ifndef SETS_H

    #define SETS_H

    class Sets

    {

    private:

    static const int s = 4;

    int na[s];

    public:

    //for constructor

    Sets ();

    //function declaration for add the element

    void addElement (int);

    //function declaration for get the element

    int getElement (int);

    //function declaration for get size

    int getSize ();

    //function declaration for check sub set

    bool isSubset (const Sets &);

    //function declaration for check the proper subset

    bool isProper (const Sets &);

    //function declaration for display the set

    void printSet ();

    //function declaration for display the ordered set

    void Sets::printOrderedPairs (const Sets &);

    };

    #endif

    Main. cpp:

    #include "Sets. h"

    #include

    using namespace std;

    //constructor

    Sets::Sets () {

    for (int i = 0; i < s; i++) {

    na[i] = - 1;

    }

    }

    //function definition for get size

    int Sets::getSize () {

    return s;

    }

    //function definition for add the elements

    void Sets::addElement (int l) {

    for (int i = 0; i < s; i++) {

    if (na[i] = = - 1) {

    na[i] = l;

    break;

    }

    }

    }

    //function definition for get element

    int Sets::getElement (int j) {

    if (j < s) {

    return (-1);

    }

    else{

    int t;

    t = na[j];

    return t;

    }

    }

    //function definition for check the subset

    bool Sets::isSubset (const Sets &b) {

    for (int i = 0, j = 0; i < b. s; i++)

    while (j < s && na[j] < b. na[i]) + +j;

    if (j = = s

    return true;

    }

    //function definition for check the proper subset

    bool Sets::isProper (const Sets &b) {

    int ne = 0;

    for (int i = 0, j = 0; i < b. s; i++)

    return ne < s;

    }

    //function definition for display the ordered set

    void Sets::printOrderedPairs (const Sets &b) {

    cout << "A X B = {";

    for (int i = 0; i < s; i++) {

    for (int j = 0; j < b. s; j++) {

    cout << ' (' << na[i] << ", " << b. na[j] << "), ";

    }

    }

    cout << "/b/b} ";

    }

    //function definition for display the set

    void Sets::printSet () {

    cout << "{";

    for (int i = 0; i < s; i++) {

    cout << na[i] << ",";

    }

    cout << "}";

    }

    //main function

    int main ()

    {

    //object for Set A

    Sets a;

    //object for Set B

    Sets b;

    //add the element for Set A

    a. addElement (1);

    a. addElement (2);

    a. addElement (3);

    a. addElement (4);

    //add the element for Set B

    b. addElement (3);

    b. addElement (4);

    b. addElement (5);

    b. addElement (6);

    //display the set A

    cout << "Set A: ";

    a. printSet ();

    cout << endl;

    //display the set B

    cout << "Set B: ";

    b. printSet ();

    cout << "/n" << endl;

    //display the A X B

    a. printOrderedPairs (b);

    cout << "/n" << endl;

    //chrck the subset

    if (a. isSubset (b) = = true) {

    cout << "Set B is subset of set A" << endl;

    }

    else{

    cout << "Set B is not a subset of set A" << endl;

    }

    //check the proper subset

    if (a. isProper (b) = = true) {

    cout << "Set B is proper subset of set A" << endl;

    }

    else{

    cout << "Set B is not a proper subset of set A" << endl;

    }

    system ("PAUSE");

    return 0;

    }
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Have main create two objects: setA and setB. Input the values into setA (end with a 0 or negative) and input the values into setB (end with ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers