Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

For all Programs: To get in the habit of writing UML for the class first, then doing the program Based on Chapter 1. Create a

For all Programs:

To get in the habit of writing UML for the class first, then doing the program

Based on Chapter 1.

Create a class called Sets for positive integers that will have the following functions:

addElement , will take a positive integer and add it to the set

getElement, will take a position number and return the element at the position (return -1 if bad position)

getSize, return the size of the set

isSubset, takes a sets object (call it b) and see if the current set (call it a) is a subset of b. If so, return a Boolean true, else return a Boolean false

isProper, takes a sets object (call it b) and see if the current set (call it a) is a proper subset of b. Note, use the isSubset function first then see if b has at least one more element than a

printOrderedPairs, takes a sets object (call it b) and takes the current set (call it a) and prints the ordered pairs of of A X B

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 setB is a subset of setA.

Then print if setB is a proper subset of setA.

For C++, submit a header file, an implementation file, and a main file.

Java, just the class and the main file

Put in UML as comments in the header file (the class file)

Hints:

Remember, currently sets can have duplicates. In other words, set B could have values of {2, 1, 3, 3} and be a subset AND proper subset of {3, 4, 1, 2}. Size can NOT be a sole determinate of subset and proper subset

Order does not matter. The set of {4, 5, 3} is the same as {3, 4, 5}

To be a subset, you need to see if every value in set A is in set B. If so, it is a subset

To be a proper subset, please call isSubset FIRST!. THEN see if there is a value in set B NOT in set A (i.e. check every value in set B against set A). If so, it is a proper subset.

Sets.cpp

#include "Sets.h" #include

using namespace std;

Sets::Sets() { size = 0; for (int index = 0; index < MAX_SIZE; index++) setAry[index] = 0; } bool Sets::addElement(int e) {

} int Sets::getElement(int p) { if (p >= 0 && p < size) return setAry[p]; else return -1; } int Sets::getSize() { return size; } bool Sets::isSubset(Sets &b) {

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

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

}

Sets.h

/* UML goes here */

const int MAX_SIZE = 10;

class Sets { private: int setAry[MAX_SIZE]; int size; public: Sets(); bool addElement(int); int getElement(int); int getSize(); bool isSubset(Sets &); bool isProper(Sets &); void printOrderedPairs(Sets &); };

Sets.java

/* UML goes here */ public class Sets { private int size; private int setAry[]; public final int MAX_SIZE = 10; public Sets() { size = 0; setAry = new int[MAX_SIZE]; } public boolean addElement(int e) { } public int getElement(int p) { if (p >= 0 && p < size) return setAry[p]; return -1; } public int getSize() { return size; } public boolean isSubset(Sets b) { } public boolean isProper(Sets b) { if (isSubset(b)) { // check further } } void printOrderedPairs(Sets b) { } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Management An Organizational Perspective

Authors: Richard T. Watson

1st Edition

0471305340, 978-0471305347

More Books

Students also viewed these Databases questions

Question

LO1 Explain how the workforce is changing in unpredicted ways.

Answered: 1 week ago

Question

LO6 List the components of job descriptions.

Answered: 1 week ago