Introduction需要提交的文件:MyInteger.hpp MyInteger.cppIntegerSet.hpp IntegerSet.cppWrite a class called IntegerSet, which represents a mathematicalset of integer values. The IntegerSet will store the values in anarray, which will need to grow if it gets full. IntegerSet shouldhave the following data members:• an int-pointer that points to a dynamically allocated array (ofint) that holds the values that are part of the set• an int that holds the current size of the array - it will need tobe updated whenever the add() method creates a largerarray• an int that holds the number of values that are currently partof the set - it will need to be updated in the add() andremove() methodsThe IntegerSet class should have the following methods:• a default constructor that initializes the pointer data memberto point to an array of size 10, initializes the variable thatstores the size of the array to 10, and initializes the variablethat stores the number of values in the set to zero• a copy constructor that initializes the pointer data memberto point to an array of the same size as the one beingcopied, copies over the array values, and also copies thevalues for the size of the array and the number of values inthe set• an overloaded assignment operator that initializes thepointer data member to point to an array of the same sizeas the one being copied, copies over the array values,copies the values for the size of the array and the number ofvalues in the set, and returns a reference to the objectpointed to by the this pointer• a destructor that deallocates the dynamically allocated array• the size() method should return the number of valuescurrently in the IntegerSet• the isEmpty() method should return true if the IntegerSetcontains no values, and return false otherwise• the contains() method should take an int parameter andreturn true if that value is in thC++代写 Write a class called IntegerSet代做C/C++实验作业e IntegerSet, but return falseotherwise• the add() method should take an int parameter and add thatvalue to the IntegerSet (if that value is not already in theIntegerSet) - if the array is currently full and you need to addanother value, then you must first increase the size of thearray by allocating a new array that is twice as large,copying the contents of the old array into the new array,redirecting the data member pointer to the new array, anddeallocating the old array (avoid memory leaks - ordermatters)• the remove() method should take an int parameter andremove it from the IntegerSet (if that value is in theIntegerSet) by shifting over all of the subsequent elementsof the array - it’s okay if values that are no longer part of theset are still in the array, so long as you do the rightbookkeeping• the getAsVector method should return a vector (of ints) thatcontains all of the values in the IntegerSet and only thosevalues. Order doesn’t matter.• an overloaded + operator that returns a new IntegerSet thatis the union of its two operands (contains all and only thosevalues that were in either IntegerSet)• an overloaded operator that returns a new IntegerSet thatis the intersection of its two operands (contains all and onlythose values that were in both IntegerSets)• an overloaded / operator that returns a new IntegerSet thatis the symmetric difference of its two operands (contains alland only those values that were in one IntegerSet or theother, but not both)One short example of how the IntegerSet class could be used:IntegerSet mySet1;mySet1.add(-30);mySet1.add(13);mySet1.add(100);mySet1.remove(-30);mySet1.add(44);int size = mySet1.size();IntegerSet mySet2 = mySet;bool check1 = mySet2.contains(13);bool check2 = mySet2.contains(44);IntegerSet mySet3 = mySet1 mySet2;The files must be named: IntegerSet.hpp and IntegerSet.cpp转自:http://ass.3daixie.com/2019030313746021.html
讲解:C++ Write a class called IntegerSetC/C++
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
推荐阅读更多精彩内容
- Introduction需要提交的文件:MyInteger.hpp MyInteger.cppIntegerSet...
- Introduction需要提交的文件:MyInteger.hpp MyInteger.cppIntegerSet...
- Introduction需要提交的文件:MyInteger.hpp MyInteger.cppIntegerSet...