Find Jobs
Hire Freelancers

Sets By Varick Erickson Introduction For this project you will implement a Set using a hash based chain implementation (each bucket can contain multiple elements).

$10-30 USD

Imekamilika
Imechapishwa about 4 years ago

$10-30 USD

Kulipwa wakati wa kufikishwa
Sets By Varick Erickson Introduction For this project you will implement a Set using a hash based chain implementation (each bucket can contain multiple elements). template<class T> class SetT { public: SetT(); SetT(int numBucks); ~SetT(); void Add(T elem); void Remove(T elem); bool Contains(T elem); SetT Union(SetT otherSet); SetT Difference(SetT otherSet); SetT Intersection(SetT otherSet); int Size() { return numElems }; void operator+(T elem); // Add void operator-(T elem); // Remove SetT operator+(SetT& other); // Union SetT operator*(SetT& other); // Intersection SetT operator-(SetT& other); // Difference void reset(); // Reset iterator bool HasNext(); T GetNextItem(); private: forward_list<T>** buckets; // An array of forward_list's (ie, each index is a forward_list pointer) int numBuckets; int getHashIndex(const T& elem); int numElems; // Iterator variables int currBucket; // what bucket is the iterator on? mutable typename forward_list<T>::iterator bucketIter; // the iterator of the current bucket // Any other private functions and variables you want/need }; Your job is to implement each of the methods in the header class. You are also responsible for creating a test driver (similar to Chunklist) that takes input files and generates output files. You only need to test using SetT<int> sets. forward_list Each bucket contains should contain a linked list of elements of type T. For this assignment, you will be using a Standard Template Library (STL) implementation of a singly linked list. Here a code snippet that should be useful: #include <iostream> #include <forward_list> int main () { std::forward_list<int> mylist; mylist.push_front(42); mylist.push_front(55); mylist.push_front(32); mylist.push_front(5); std::cout << "mylist contains:"; forward_list<T>::iterator it; // Iterator for forward_list for (it = [login to view URL](); it != [login to view URL](); ++it ) std::cout << ' ' << *it; std::cout << '\n'; [login to view URL](42); // Removes 42 from the list std::cout << "mylist contains:"; for (it = [login to view URL](); it != [login to view URL](); ++it ) std::cout << ' ' << *it; std::cout << '\n'; return 0; } Operator Overloading Operator overloading allows the programmer to override the behavior of operators such as +, -, >, and <. While this may sound complicated, it actually straight forward. The following shows how we overload the + operator to add and element to the set: template<class T> void SetT<T>::operator+(T elem) { this->Add(elem); } Note that the operator behavior is based on the type of the argument on the right side. In this case, the argument is of type T. If the argument was of type SetT, then the + would indicate Union. Test Driver You should have a test driver similar to the list driver from the previous program. In particular, it should support the following commands: • Add (this should test add and the + operator) • Remove (this should test remove and the - operator) • Intersection (this should test intersection and the * operator) • Union (this should test union and the + operator) • Difference (this should test difference and the - operator) • Size • Print
Kitambulisho cha mradi: 25336282

Kuhusu mradi

pendekezo 1
Mradi wa mbali
Inatumika 4 yrs ago

Unatafuta kupata pesa?

Faida za kutoa zabuni kwenye Freelancer

Weka bajeti yako na muda uliopangwa
Pata malipo kwa kazi yako
Eleza pendekezo lako
Ni bure kujiandikisha na kutoa zabuni kwa kazi
Imetolewa kwa:
Picha ya Mtumiaji
I am a C/C++, Python, Java expert with 2 years of competitive programming experience with knowledge of Data structures and algorithms and I can do your work as soon as possible. Can we discussed more on this project on chat?
$40 USD ndani ya siku 1
5.0 (4 hakiki)
2.5
2.5

Kuhusu mteja

Bedera ya UNITED STATES
san jose, United States
5.0
1
Njia ya malipo imethibitishwa
Mwanachama tangu Apr 22, 2020

Uthibitishaji wa Mteja

Asante! Tumekutumia kiungo cha kudai mkopo wako bila malipo kwa barua pepe.
Hitilafu fulani imetokea wakati wa kutuma barua pepe yako. Tafadhali jaribu tena.
Watumiaji Waliosajiliwa Jumla ya Kazi Zilizochapishwa
Freelancer ® is a registered Trademark of Freelancer Technology Pty Limited (ACN 142 189 759)
Copyright © 2024 Freelancer Technology Pty Limited (ACN 142 189 759)
Onyesho la kukagua linapakia
Ruhusa imetolewa kwa Uwekaji wa Kijiografia.
Muda wako wa kuingia umeisha na umetoka nje. Tafadhali ingia tena.