1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
gizmo_the_mogwai [7]
3 years ago
12

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.
Computers and Technology
1 answer:
kvasek [131]3 years ago
6 0

Answer:

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 <iostream>

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 || na[j] > b.na[i] )

           return false;

   }

   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++ ) {

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

       if ( j == s || na[j] > b.na[i] )

           return false;

       ++ne;

   }

   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;

}

You might be interested in
Jonathan wants to create an online journal. He will use it to share with his friends all the cool places he visits while in Euro
nirvana33 [79]

Answer:

a blog

Explanation:

a forum is for questions, a wiki doesn't make sense in this situation and email wouldn't be used for this either so it should be a blog

7 0
3 years ago
Read 2 more answers
Write a recursive function next_pow2(n) that returns the smallest integer value p such that for a non-negative value n. For exam
Finger [1]

Answer:

Explanation:

The following code is written in Python and is a recursive function as requested that uses the current value of p (which is count in this instance) and raises 2 to the power of p. If the result is greater than or equal to the value of n then it returns the value of p (count) otherwise it raises it by 1 and calls the function again.

def next_pow2(n, count = 0):

   if (2**count) < n:

       count += 1

       return next_pow2(n, count)

   else:

       return count

8 0
3 years ago
there are four stage of the product life cycle. during which of these stages do you think is the best time for a company to purc
Alisiya [41]

Maturity Stage – During the maturity stage, the product is established and the aim for the manufacturer is now to maintain the market share they have built up. This is probably the most competitive time for most products and businesses need to invest wisely in any marketing they undertake. They also need to consider any product modifications or improvements to the production process which might give them a competitive advantage. i think this would be the best time for the company to purchase an emerging technology.

7 0
3 years ago
Read 2 more answers
Each time we add another bit, what happens to the amount of numbers we can make?
notsponge [240]

Answer:

The amount doubles

Explanation:

6 0
3 years ago
Knowledge of HTML and CSS is considered essential for the job of a(n)
Ira Lisetskai [31]
I'm not sure but I think d. Webmaster
8 0
3 years ago
Other questions:
  • The primary input device for interacting with the operating system is the ____.
    15·2 answers
  • Emotional intelligence is a new term to describe personal traits ?
    12·1 answer
  • Explain with the help of an example that family background affects the entrepreneurial behaviour of people
    12·1 answer
  • If Word finds a potential error in a document, a red, green, or blue wavy underline flags the problem.
    14·1 answer
  • What are the two ways to print a document?
    11·1 answer
  • Gina wants to consistently format the headings in all of her worksheets.. . Which is a quick way to do so?. A)Format the heading
    10·1 answer
  • What is the main advantage of using a WYSIWYG("what you see is what you get")editor when constructing a website
    5·1 answer
  • What are input masks most useful for in data validation? moving data from one field to another hiding parts of a value that are
    9·2 answers
  • Which tab on the ribbon in the folder window allows users to change how the contents of the folder are being shown?
    11·1 answer
  • 19. List three things you can do to protect your online reputation:
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!