Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Programming Project #2 EGRE246 Fall 2018 Set Container 1 Overview Write the C++ class Set to implement an unordered set of items according to the

Programming Project #2 EGRE246 Fall 2018 Set Container 1 Overview Write the C++ class Set to implement an unordered set of items according to the specification given below. You may not use any other container classes found in any other library that you did not write yourself. File Set.h (downloadable off the class web pages): #include #include #ifndef SET_H #define SET_H namespace egre246 { class Set{ public: typedef int value_type; typedef std::size_t size_type; static const size_type CAPACITY=1000; // arbitrary Set(); // sets curr to just off front of set Set(value_type *s, size_t begin, size_t count); // creates Set with count number of values // from array s starting at index begin // where index 0 is the first item in the // array; sets curr to just off front of set bool insert(const value_type&); // inserts argument in Set if it is not already in the // Set, does nothing it is in Set already; returns true // if item gets inserted, false otherwise; insert invalidates // iterator by setting current to off front of set void remove(const value_type&); // removes argument from Set, does nothing it if isnt a member // of Set; remove invalidates iterator by setting current to off // front of set void clear(); // clears Set so it is empty (has a cardinality of 0); invalidates the iterator size_t card() const; // returns the cardinality of the set bool equals(const Set&) const; // true if 2 sets contain the same items, false otherwise bool contains(const value_type&) const; // returns true if argument is in Set value_type max() const; // returns the largest item in the Set; asserts that Set is // not empty value_type min() const; // returns the smallest item in the Set; asserts that Set is // not empty bool isEmpty() const; // returns true if Set is empty, false otherwise bool isFull() const; // returns true if Set is full, false otherwise // begin iterator routines void begin(); // set current item to first item in Set void next(); // moves current to next item in Set (or possibly "off" of Set); // calling when already off the end of set has no effect; // calling when off front of set sets current to first item void prev(); // moves current to previous item in Set (or possibly "off" of Set); // calling when already off the front of set has no effect; // calling when off back of set sets current to last item value_type current() const; // returns current item in Set; assumes iterator is on Set; // asserts that current item is legal item in Set (on the Set) bool isItem() const; // returns true if current item of iterator is valid (on the Set) void removeCurrent(); // removes current item; assumes current item of iterator is valid (on the // set); asserts that current item is legal item in Set (on the Set) // end iterator routines value_type *toArray() const; // returns an array representation of the Set std::string toString() const; // returns a string representation of Set; an empty set // returns an empty string (with length of 0), and a // nonempty Set returns items sorted in ascending order // separated by commas (e.g. set {30,20,10,-8} would // return the string "-8,10,20,30" (with no spaces); // note that toString does not change the stored order of // the set friend std::ostream& operator <<(std::ostream&, const Set); // outputs to standard output a representation of the Set; set is printed in stored order // delimited by curly braces; for example, an empty set would output as {} and the set // stored with order 83,4,99,-1 would be outputted as {83,4,99,-1} (no spaces) friend Set operator +(const Set&,const Set&); // set union friend Set operator *(const Set&,const Set&); // set intersection private: value_type data[CAPACITY]; size_t size; // number of items in set size_t curr; // current item in set (for iterator) }; // two helper routines for working with value_type data std::string toString(const Set::value_type &); int cmp(const Set::value_type& op1, const Set::value_type& op2); // returns -1 if op1 < op2, // 0 if op1 == op2, // 1 if op1 > op2 } #endif You may not modify file Set.h in any way. All string representations of any value_type data must be acquired through a call to your toString(const value_type&) routine. In addition all comparisons between values of type value_type in your code must use your cmp(const Set::value_type& op1, const Set::value_type& op2) routine. Use the assert command from assert.h wherever the specifications call for an assertion to be made. You may work in pairs to complete this project, though it is not required (i.e. you may also work alone). If two of you work together you should only turn in a single copy of your code using either of your id numbers, making sure to put both of your names in the opening comments in your file. If you begin work on the project pairing up with someone, you may decide later to end your partnership and turn in individual programs.

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

Beyond Big Data Using Social MDM To Drive Deep Customer Insight

Authors: Martin Oberhofer, Eberhard Hechler

1st Edition

0133509796, 9780133509793

More Books

Students also viewed these Databases questions

Question

Write short notes on departmentation.

Answered: 1 week ago

Question

What are the factors affecting organisation structure?

Answered: 1 week ago

Question

What are the features of Management?

Answered: 1 week ago

Question

Briefly explain the advantages of 'Management by Objectives'

Answered: 1 week ago

Question

KEY QUESTION Refer to the table in question

Answered: 1 week ago