πŸŽ“ First order? Get 25% OFF β€” use code BISHOPS at checkout  |  πŸ’¬ Chat on WhatsApp

C++ Finish the code

πŸ“… August 6, 2020 ✍️ Writers Research ⏱ 2 min read

Question description

There areΒ two “TODO” to do. There will be more info attached in a file. You do need to make a new code from scratch, since most of it is doneI’m not paying more than 7 dollars because it’s not a big job.Β #include
#include

using namespace std;

//==========================================================================
// CONSTANTS
//==========================================================================

// error codes
const int ERROR_CAPACITY_OVERFLOW = 1;

// maximum size allowed for a set
const int MAX_SET_SIZE = 256;

Writing a Similar Assignment?

Get a Scholar-Written Paper Matched to Your Brief

Every order is handled by a degree-holding expert in your subject β€” written to your exact rubric, fully original, and delivered ahead of your deadline.

Start My Order

//==========================================================================
// TYPES
//==========================================================================

// structure to represent sets of integers
struct IntSet {

int elem[MAX_SET_SIZE]; // the elements in the set (occupied 0 to n-1)
int size = 0; // the number of elements currently in the set

};

//==========================================================================
// FUNCTIONS
//==========================================================================

//————————————————————————–
// isEmpty(s): returns true if the set is empty and false otherwise.
//————————————————————————–

Stuck on Your Assignment?

Cola Papers Experts Are Ready Right Now

Join thousands of students who submit confidently. Human-written, plagiarism-checked, and formatted to your institution's exact standards.

Order My Custom Paper Use code BISHOPS for 25% off

bool isEmpty(IntSet s) {

// s is empty if its size is zero
return s.size == 0;

}

//————————————————————————-
// isMember(s, x): Returns true if x is a memeber of set s and false otherwise.
//————————————————————————–

bool isMember(IntSet s, int x) {

// for every occupied cell of our array…
for (int i = 0; i < s.size ; i++) { // compare contents to x if (s.elem[i] == x) return true; } // if we're here, x was not in the set return false; } //-------------------------------------------------------------------------- // add(s, x): adds element x into set s. If x already is a member of s, then // this operation has no effect. //-------------------------------------------------------------------------- void add(IntSet &s, int x) { // if there is room remaining if (s.size < MAX_SET_SIZE) { // if x is not already in the set if (!isMember(s, x)) { // place x in the elem array of s s.elem[s.size] = x; // update the size of s s.size++; } } else { // the set is filled to capacity cout << "Error: attempted to add an element to a maximum capacity set."; exit(ERROR_CAPACITY_OVERFLOW); } } //-------------------------------------------------------------------------- // clear(s): Clear the set s so that it is empty. //-------------------------------------------------------------------------- void clear(IntSet &s) { s.size = 0; } //-------------------------------------------------------------------------- // print(s): Prints set s to the console. //-------------------------------------------------------------------------- void print(IntSet s) { cout << "{"; for (int i = 0; i < s.size - 1; i++) { cout << s.elem[i] << ", "; } if (s.size > 0) {
cout << s.elem[s.size - 1]; } cout << "}" << endl; } //------------------------------------------------------------------------- // setIntersection(s1, s2, result): Compute the intersection of s1 and s2 and // place it into result. //-------------------------------------------------------------------------- void setIntersection(IntSet s1, IntSet s2, IntSet &result) { clear(result); // TODO: Complete the code below... // for every member of s1 // if it is a member of s2 // add it to the result } //------------------------------------------------------------------------- // setUnion(s1, s2, result): Compute the union of s1 and s2 and place it into // result. // ------------------------------------------------------------------------ void setUnion(IntSet s1, IntSet s2, IntSet &result) { clear(result); // TODO: Complete the code below... // for every member of s1 // add it to the result // for every member of s2 // add it to the result } //-------------------------------------------------------------------------- // MAIN PROGRAM //-------------------------------------------------------------------------- int main() { // fill s1 with {1, 2, 3, 4, 5} IntSet s1; for (int x = 1; x <= 5; x++) { add(s1, x); } cout << "s1: "; print(s1); // fill s2 with {4, 5, 6, 7, 8} IntSet s2; for (int x = 4; x <= 8; x++) { add(s2, x); } cout << "s2: "; print(s2); // compute intersection and print it IntSet res1; setIntersection(s1, s2, res1); cout << "intersection of s1 and s2: "; print(res1); // compute union and print it IntSet res2; setUnion(s1, s2, res2); cout << "union of s1 and s2: "; print(res2); }

Our Key Guarantees

  • βœ“ 100% Plagiarism-Free
  • βœ“ On-Time Delivery
  • βœ“ Student-Friendly Pricing
  • βœ“ Human-Written Papers
  • βœ“ Free Revisions (14 days)
  • βœ“ 24/7 Live Support

Frequently Asked Questions About Our Essay Writing Service