Question: This is a programming assignment. Write following three C++ functions: A function, named as union , that receives two sets of integers, A and B.

This is a programming assignment. Write following three C++ functions:

A function, named as union, that receives two sets of integers, A and B. The function returns AB, which is a set of integers that are either in set A or in set B.

A function, named as intersection, that receives two set of integers, A and B. The function returns AB, which is a set of integers that are in both A and B.

A function, named as difference, that receives two set of integers, A and B. The function returns A - B, which is a set of integers that are in set A but not in set B.

Include those functions in a source file that contains a main() function for testing the correctness of the functions listed and submit the entire source file to Canvas

//Source code Bag.h

#ifndef _Bag #define _Bag #include using namespace std; template class Bag { private: ItemType items[100]; int itemCount; public: Bag(); bool isEmpty(); bool add(ItemType item); void display(); bool contains(ItemType item); ItemType getItem(int position); }; //====================================== template Bag::Bag() { itemCount = 0; } template bool Bag::isEmpty() { return (itemCount == 0); } template bool Bag::add(ItemType item) { if (itemCount == 100) { cout << "The bag is full!" << endl; return false; } else { items[itemCount] = item; itemCount++; return true; } } template void Bag::display() { for (int i = 0; i < itemCount; i++) cout << items[i] << endl; } template bool Bag::contains(ItemType item) { for (int i = 0; i < itemCount; i++) { if (items[i] == item) return true; } return false; } template

ItemType Bag::getItem(int position) { if (position <= 0 or position > itemCount) { cout << "Invalid position, the program aborted!" << endl; exit(1); } else { return items[position-1]; } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!