2mNaira's Posts
Nairaland Forum › 2mNaira's Profile › 2mNaira's Posts
1 2 3 4 5 6 7 8 ... 15 16 17 18 19 20 21 22 (of 22 pages)
I f you have any code kindly post it as a comment at or new gist at gisthub and notify us here. |
On a second thought I decided to move the whole thing to gist hub because the site is code friendly. @ WhiZTiM, I have copied your code so that others can see the most recent stage of the class all in one place The latest classes can be found at: https://gist.github.com/mnairaland/30ca049feb115c89ca05 |
//This is the most recent parser class enum Token {TT_UNION,TT_INTERSECTION,TT_COMPLEMENT,TT_SETNAME,TT_CARDINALITY,TT_FIND,TT_EVALUATE,TT_GIVEN,TT_EXPAND,TT_SIMPLIFY}; //Interprtation of token: //U = UNION //^ = INTERSECTION //! = COMPLEMENT //SETNAME is strictly of the form "letter-numeral", e.g. A1,A2,A3,A4, etc //CARDINALITY of a set is the number of elements in the set and must be represented by letter n. //nA1 = number of elements in A1, nA2 = no of elements in A2 etc //Keyword FIND, is used to instruct the class to find a set solution e.g. FIND A1 U A2 //Keyword EVALUATE is used to instruct the class to find a value e.g EVALUATE n(AuB^c) //Keyword GIVEN is use to specify a comma seperated list of Cardinalitie //e.g. GIVEN: n(A1^B1) = 12, nA1! = 4; EVALUATE nB1 //Keyword EXPAND, is used to instruct the class to expand an expression. e.g. //EXPAND A!^B^C! //Keyword SIMPLIFY is used to instruct the class to simplify an expression. e.g. //(A U B) ^ (C U D)! //so the parser will pass for the characters:U ^ n ! ( ) , ; : //It will also parse for the keywords: FIND,EVALUATE,GIVEN,EXPAND,SIMLIFY //Note that keyword and characters are not case sensitive. //For instance, FIND and find are the same, n and N are thesame //This class is used for parsing a question for tokens class Parser { SArray<Token> m_TokenList; char *pBuffer; public: Parser(const char *pQuestion);//is created with the set question SArray<Token> GetTokenList() {return m_TokenList;}//return a token list private: Token NextToken();//get next token bool Scan();//Scan for a token in question }; enum SolutionType { SOL_SET, SOL_INTEGER, SOL_STRING}; template <typename T> class SetProblem { MathSet<T> m_UniversalSet;//holds the universal set SArray<MathSet<T>> m_Array;//holds the sets needed for the question string m_Question;//holds the question SArray<Token> m_TokenList;// holds token list int m_iSolution;// holds integer solution MathSet<T> m_Solution;// Holds set solution string m_stSolution//Holds string solution public: SetProblem(const <MathSet<T> &UniversalSet);//this object must be created with the universal set void Ask( char * pQuestion);// A mathematical set question posed to the class to solve void GetSolution(SolutionType &eType);//There three possible solutions, integer,set or string. //The return value should be cast to the //type of solution specified by eTypes void AddSet(vector<Mathset> VSet);//add a set needed for question void ChangeUniversalSet(const <MathSet<T> &UniversalSet); int Remove(MathSet<T> MSet);//remove a set int Remove(int iPosition, int Count = 0);//Remove the first Count det starting from iPosition void RemoveAll(); void RemoveUniversalSet();//Remove a universal set int Count(); private: void Solve(SolutionType &eType);//There three possible solutions, integer,set or string //The return value should be cast to the //type of solution specfied by eTypes }; |
//This is the most recent exception class enum SErrorCode {EC_EMPTYSET,EC_INVAID_SET,EC_EMPTY_QUESTION,EC_INVALID_QUESTION};//Of course this is just a few of the error codes, you //are expected to add yours as you write your implementation. //All implementation should throw exceptions for error use and abnormal use and transfer that function to the runtime. //All implementation are expected to contruct an ecxeption object using the error code. class SException : public exception { int m_iErrorCode; string m_Description; string m_Suggestion; public: SException(int iErrorCode); SException(const SException &obj); SException operator = (const SException &obj); }; SException::SException(int iErrorCode) { m_iErrorCode = iErrorCode; switch(iErrorCode) { case EC_EMPTYSET: m_Description = "Attempted to use empty set"; m_Suggestion = "Provide a non-empty set"; break; case EC_INVAID_SET: m_Description = "Attempted to use an invalid set"; m_Suggestion = "Provide a valid set"; case EC_EMPTY_QUESTION: m_Description = "Attempted to use an empty question"; m_Suggestion = "Provide a non-empty question"; case EC_INVALID_QUESTION: m_Description = "Attempted to use empty question"; m_Suggestion = "Provide a non-empty question"; default: m_Description = "Unknown error"; m_Suggestion = "No suggestion"; break; } } Read friendly version is located at https://gist.github.com/mnairaland/30ca049feb115c89ca05 |
Modified exception class class SException : public exception { int m_ErrorCode; char *m_pDescription; public: SException(int iErrorCode); SException(const SException &obj); SException operator = (const SException &obj); }; |
WhiZTiM:Don.t you think using STL will make the class bulky. I won't be surprised if someone decides to use the class to implement set theory in a calculator. Will size of the class not be too big for for such implementation? As to my questions, I will sign up on one or both of the sights you used paste the code and add my questions as comment to the code section concerned. That aside, I think your Mathset class should define an assignment operator, equality operator and non-equality operator, should a need arise for the class to be used in larger expressions. Your class should include a function Cardinality (or ElementsNo) that returns the number of elements in the set. Please, see the modified exception class and above and below and bear the associated comments in mind in your implementation. |
WhiZTiM:I have seen your class. It is a most excellent and efficient class. How ever I have some questions and concerns. |
prodam:Of course u are talkg sense, I will soon write and post an update. |
asalimpo:I agree with u.But I will soon write a parser throw it open for criticism. If majority condemn it.It will be dropped. |
I apologise for my late response.I have been very busy. |
Ok. I am throwing this open. Which would you prefer, for the class to be implemented using template or strictly overloaded functions. Please let me know what you think and why. Its all towards a better class implementation. If there is a superior argument against template, then I will re-write the class definition. If there isn't template will be retained. |
If you are not a programmer but you are well versed in maths , specifically set theory, please will need your suggestion of concept/ features/problem you would like the class to solve. |
. |
. |
asalimpo:Word problems can be fed in, but it must be done according to a specific language grammer determined by the programmer. It will be made as close as possible to spoken language but not to the extent that it makes it too difficult to write a parser for it. I can develop the grammer and write the parser but I can do everything. If nobody comes up with any grammer/parser, I post a sample one here as giude for people to use. |
asalimpo:Perhaps you could, help with that. The member function. Question takes a string that will be passed. This means someone may need to come up with a grammer / parser for parsing the the question. Thanks for your comment on the title, I will correct it now. |
..... |
... |
.. |
//class definition of a mathematics set classes developed on nairaland //This class defintion may be used or modified freely in as much as the above comment line is included //This following is meant to handle different operation sytem. //At the meoment it is aplace holder. Suggestions on how best to //write is is welcome #define WINDOWS // this line of code will eventually go for cross-platform capability #ifdef WINDOWS #define DEVICE HDC #endif #ifdef LINUX #endif #ifdef UNIX #endif //A generic set class for holding a set neede for asking set questions enum SetType { T_UNSPECIFIED,T_INTEGER, T_DOUBLE, T_CHAR,T_STRING}; template <typename T> class MathSet { T *m_MSet;//Holds set of Elements int m_iElementCount;//Holds the number of elements in set SetType m_eSetType;//Holds information about the type of sets static char chSetName;//Holds the character part of a set's name static char iSetName;//Holds the integer part of a set's name char szSetName[3];//Holds a set's name e.g A1, A2, A3 etc public: MathSet(); MathSet(SetType eSetType); MathSet( T *MSet, int iElementCount); MathSet(const MathSet &ExistingObject); MathSet operator = (const MathSet &Obj); bool operator == (const MathSet &Obj); bool operator != (const MathSet &Obj); bool operator > (const MathSet &Obj); bool operator < (const MathSet &Obj); bool IsEmptySet(); bool IsSuperSet(const MathSet &SecondSet); bool IsSubSet(const MathSet &SecondSet); bool IsProperSubSet(const MathSet &SecondSet); MathSet Intersection(const MathSet &SecondSet); MathSet Union(const MathSet &SecondSet); void Add(T NewELement); int Remove(T Element); void Remove(int Position, int NElements); void RemoveAll(); int Remove(vector<MathSet> vSet); //Additional memebers int Cardinality(); // returns the number of elements in the set }; //this is a generic array class used for holding a set of element template <typename T> class SArray { T * m_Array;// Array of elements int m_iCount;//Count of element in array public: SArray(); SArray( const SArray &Obj); SArray operator = (const SArray &Obj); T ElemetAt(int iIndex);//return element at index iIndex T operator [] (int iIndex);//return element at index iIndex bool operator == (const SArray &Obj); bool operator != (const SArray &Obj); bool operator >(const SArray &Obj); bool operator <(const SArray &Obj); void Add( T Element);//Add new elemnt int Remove(T Element);//Remove specified element int Remove (int iPostion, int iCount = 0);//Remove the first iCount elements //starting from position, iPosition void RemoveAll();//Remove All elements int GetSize();//Get number of lements in array int Count(T Element);//Count the number of times element Element occur in the array }; enum Token {TT_UNION,TT_INTERSECTION,TT_COMPLEMENT,TT_SETNAME,TT_CARDINALITY,TT_FIND,TT_EVALUATE,TT_GIVEN,TT_EXPAND,TT_SIMPLIFY}; //Interprtation of token: //U = UNION //^ = INTERSECTION //! = COMPLEMENT //SETNAME is strictly of the form "letter-numeral", e.g. A1,A2,A3,A4, etc //CARDINALITY of a set is the number of elements in the set and must be represented by letter n. //nA1 = number of elements in A1, nA2 = no of elements in A2 etc //Keyword FIND, is used to instruct the class to find a set solution e.g. FIND A1 U A2 //Keyword EVALUATE is used to instruct the class to find a value e.g EVALUATE n(AuB^c) //Keyword GIVEN is use to specify a comma seperated list of Cardinalitie //e.g. GIVEN: n(A1^B1) = 12, nA1! = 4; EVALUATE nB1 //Keyword EXPAND, is used to instruct the class to expand an expression. e.g. //EXPAND A!^B^C! //Keyword SIMPLIFY is used to instruct the class to simplify an expression. e.g. //(A U B) ^ (C U D)! //so the parser will pass for the characters:U ^ n ! ( ) , ; : //It will also parse for the keywords: FIND,EVALUATE,GIVEN,EXPAND,SIMLIFY //Note that keyword and characters are not case sensitive. //For instance, FIND and find are the same, n and N are thesame //This class is used for parsing a question for tokens class Parser { SArray<Token> m_TokenList; char *pBuffer; public: Parser(const char *pQuestion);//is created with the set question SArray<Token> GetTokenList() {return m_TokenList;}//return a token list private: Token NextToken();//get next token bool Scan();//Scan for a token in question }; enum SolutionType { SOL_SET, SOL_INTEGER, SOL_STRING}; template <typename T> class SetProblem { MathSet<T> m_UniversalSet;//holds the universal set SArray<MathSet<T>> m_Array;//holds the sets needed for the question string m_Question;//holds the question SArray<Token> m_TokenList;// holds token list int m_iSolution;// holds integer solution MathSet<T> m_Solution;// Holds set solution string m_stSolution//Holds string solution public: SetProblem(const <MathSet<T> &UniversalSet);//this object must be created with the universal set void Ask( char * pQuestion);// A mathematical set question posed to the class to solve void GetSolution(SolutionType &eType);//There three possible solutions, integer,set or string. //The return value should be cast to the //type of solution specified by eTypes void AddSet(vector<Mathset> VSet);//add a set needed for question void ChangeUniversalSet(const <MathSet<T> &UniversalSet); int Remove(MathSet<T> MSet);//remove a set int Remove(int iPosition, int Count = 0);//Remove the first Count det starting from iPosition void RemoveAll(); void RemoveUniversalSet();//Remove a universal set int Count(); private: void Solve(SolutionType &eType);//There three possible solutions, integer,set or string //The return value should be cast to the //type of solution specfied by eTypes }; enum SolutionType { SOL_SET, SOL_INTEGER}; template <typename T> class SetProblem { MathSet<T> m_UniversalSet;//holds the universal set SArray<MathSet<T>> m_Array;//holds the sets needed for the question char m_Question[5000];//holds the question SArray<Token> m_TokenList;// holds token list int m_iSolution;// holds integer solution MathSet<T> m_Solution;// Holds set solution public: SetProblem(const <MathSet<T> &UniversalSet);//this object must be created with the universal set void Ask( char * pQuestion);// A mathematical set question posed to the class to solve void GetSolution(SolutionType &eType);//There two possible solutions, integer or set. //The return value should be cast to the //type of solution spefified by eTypes void AddSet(vector<Mathset> VSet);//add a set needed for question void ChangeUniversalSet(const <MathSet<T> &UniversalSet); int Remove(MathSet<T> MSet);//remove a set int Remove(int iPosition, int Count = 0);//Remove the first Count det starting from iPosition void RemoveAll(); void RemoveUniversalSet();//Remove a universal set int Count(); void DrawVennDiagram();//Draws venn diagram to console void DrawVennDiagram( DEVICE pDevice, int iXPoint,int YPoint));// Draw venn diagram to window private: void Solve(SolutionType &eType);//There two possible solutions, integer or set. //The return value should be cast to the //type of solution spefified by eTypes }; class SException : public exception { int m_iErrorCode; string m_Description; string m_Suggestion; public: SException(int iErrorCode); SException(const SException &obj); SException operator = (const SException &obj); }; //This is the first version of the class definitions, please kindly bring in your improvement or additional feature or additional functions suggestion and your own version of the implementation of the functions of the class. Please feel free to use and modify or improve the class implementation that I used in a previous thread |
I recently stumbled into the thread, https://www.nairaland.com/1962286/c-programmer-house and made an effort to assist the poster in writing the class, but I some how have the feeling that I might need a class like that in the nearest future. The unfortunate thing is that I am an extremely busy person and cannot, at this time, afford the time to write a comprehensive MATHEMATICS SET class. So I thought to involve others and and just lead the way. What I wish to write on this thread is a Mathematics Set class that can solve any conceivable mathematics set problem, including drawing of venn diagrams. This means that you ask the class to solve practically any set problem. The class is expected to be cross-platform, meaning it would work on practically any operating symtem including windows, linux, mackintosh, android, blackberry, iOs, etc. This is important because the class will be expected to carry out some graphical drawings. Those who develop school management apps may find the class useful. So, if you are such a person I wil advise you to contribute to the writing of this class. Althought the class will be developed in C/C++, people who can write code to interface it will all other relevant programming language ( once the first version of the class ie completed), will be needed. Along side, it will be neccessary to write an exception class for the thread too. The class will adequately inform users of the kind of misuse that occur and possibly offer, a correct use suggestion. Please, start bringing in your suggestions, and contributions, but kindly wait for me to create the first next neccessary four posts. |
ok.I need an icon to be designed. |
Twisterz:1. In c++ it is data dt determines the methods or funcion that will be required. first decide d data ur class or implentation wil require. From simple observation u will realize that ur class need : (a) an array that will hold the set of integers (b) an integer that will be used to count the number of integers in the array i.e d set. so all d other methods or functions u write will all durectly or indirectly manipulate these two basic variables. Since they are d basic variables on which ur class is based u must make these variables private. If u want ur class to be able to handle arbitrary number of set elements then your data array must be dynamically created.In that case ur basic variables will consist of an integer pointer( for dynamically creating an array) and an integer (for counting the number of elements in d set). Next you decide the various ways you want users to create objects of your class or determine the various ways users would need( or desire to use ) objects of your class. For each use-way you conceive, you must write a constructor. Constructor are functions that are used to create objects of a class based on perceived possible-use senarios. They take the same name as the class and do not return return values and do not have return values written for them. If you want users to be able to create an empty object of your class then you must write a default constructor. Default constructors are constructors that have no parameters. The have the prototype or form: ClassName(); if (a) you want objects of your class to be created from another exsiting object of your class or (b) you want objects of your class to be passes to functions as arguments or (c) you want objects of your class to be returned from functions as return values, the you need a copy constructor. Copy constructors are constructors that take a constant reference of the object of the class thet is being defines as parameter. The have the prototype of form: ClassName( const ClassName &ExistingObject); If you want it to be possible for people to assign an existing object of your class to another existing object of your class, then you neen an assignment operator. If you want people to be able to compare an object of you class with another object of your class, then you need comparison operators. Operators have the form: ReturnValue operator OperatorSymbol ( ParmeterList); An assignment operator take the same parameterList as the copy constructor but returns a copy of the object that invoked it. So an assinment operator has the prototype: ClassName operator = (const ClassName &ExistingObject); Comparison operators can either be member functions or friend function. By definition , member functions are functions that are members of a class and they all have direct access to the private members of the class. Non-member functions are functions that are not members of the class and as such do not have access to private members of the class, however , they have access to public member of the class.( Class members can either be variable or functions). Friend functions are functions that are not members of a class but yet have access to private members of a class. To make a non-member function a friend of a class, include the prototype of the function in the class definition but prepend it with the keyword friend. All comparison operators that are member functions has only one object in its parameter list which is the object that the operator invoked by the invoking object will act upon.( An invoking object is the object that calls the operator function and it is usually the object on the left hand side of the operator. All comparison operators that are friend functions have two objects in their parameter list. The first object is the invoking object while the second object is the object the operator will act upon. Member comparison function takes the form: bool operator OperatorSymbol( const ClassName &ExistingObject); while friend comparison functions take the form: bool operator OperatorSymbol (const ClassName &InvokingObject, const ClassName &ExistingObject); The following are prototypes of common comparison member functions: (i) bool operator > ( const ClassName &ExistingObject); //decides whether the invoking object is less that the object operated upon or not (ii) bool operator >= (const ClassName &ExsitingObject) (iii) bool operator < ( const ClassName &ExistingObject); (iV) bool operator <= ( constant ClassName &ExistingObject); (V) bool operator != (const ClassName &ExistingObject); Similarly, friend finction have the following prototypes: (i) bool operator > (const ClassName &InvokingObject, const ClassName &ExistingObject); //decides whether the invoking object is less that the object operated upon or not (ii) friend bool operator >= (const ClassName &InvokingObject,const ClassName &ExsitingObject) (iii)friend bool operator < (const ClassName &InvokingObject, const ClassName &ExistingObject); (iV) friend bool operator <= (const ClassName &InvokingObject, constant ClassName &ExistingObject); (V) friend bool operator != (const ClassName &InvokingObject,const ClassName &ExistingObject); Asou have probably noticed all comparison functions return bolean values i. e. the return true or false. If you want your class class to be used in arithmentic statement lke addition , subtraction , multiplication, division etc , you must write arithmetic operators for them. Arithmentic operators can either be member functions or friend functions. All arithmetic operators, like the assignment operators return a copy of the of the invoking object. The prototypes for common arithmetic operator are: ClassName operator + (const ClassName &ExistingObject); ClassName operator - (const ClassName &ExistingObject); ClassName operator * (const ClassName &ExistingObject); ClassName operator / (const ClassName &ExistingObject); etc. The prototype of the friend functions are: ClassName operator + (ClassName &InvokingObject,const ClassName &ExistingObject); ClassName operator - (ClassName &InvokingObject,const ClassName &ExistingObject); ClassName operator *(ClassName &InvokingObject,const ClassName &ExistingObject); ClassName operator /(ClassName &InvokingObject,const ClassName &ExistingObject); etc. To implement an operator function, just carry ount the operation on corresponding members of the invoking object and the object operated opon. Note that all invoking object have a 'this' pointer. A 'this' pointer is a pointer to the invoking object. and it is only accessible from within a member function. It cannot be accessed form within a friend function. All member operator function must return the object pointed to by the "this" pointer. This means that the last statement ( or line of code ) in amember operator funtion should be :return *this; ( where this is a pointer to the invoking function and which is dereference by the operator *. All friend functions must return a copy of the invoking object thus: return InvokingObject; You must likely will want users be able to add integer set members to your object at anytime they wish during its lifetime, so you need a function (probably) called Add , that takes a copy or reference to the new member to be added. its proto type will be of the form: void Add(int NewELement); users might wish to remove one or more elements from the set, so you need a Remove member function. Your remove member function should be overloaded and such have one or more of the following prototypes: (i) bool Remove(int ElemetToRemove); // returns true if the element was successfully removed or false other wise (ii) int Remove(int ElementToRemove);//Return the number of copies of the element removed (iii) void Remove(int ElementToRemove);//throws an exception if the specified element is not found (IV) void RemoveAll( )//Remove all elements (v) int Remove(int Position);//Removes the element at the specified position; (vi) int Remove(int N)// Removes the firs N elements in the set. (vii) void Remove(int Position, int N); /Removes first N elements from the set starting from position Position. The wisest combination of overloads that creates no ambiguity for d compiler is: int Remove(int ElementToRemove); void Remove(int Position, int NElements); void RemoveAll();// not an overload You will also need thee a function Intersection to find the elements common to both sets. Its prototype is: ClassName Intersection( constant ClassName &SecondObject);// the first object is the invoking object. This function must return a copy of a third object created within it that holds the set of elements common to d object sets. You may also want to include the function Union to find the union of two set, like the intersection function , it will have the prototype: ClassName Union( constant ClassName &SecondObject);// the first object is the invoking object. This function must return a copy of a third object created within it that holds the set of elements are members of the first set or the second set or common to d two object sets. Also, you may want to add the functions: bool IsSuperSet( constant ClassName &SecondObject);// this function checks to see if all elements of the set of the first object are also elements of the set of the second object. It also checks to see if the number of elements of the sets of the second element are more than those of the first set. This function returns true or false You may also wan to add the function: bool IsSubset( constant ClassName &SecondObject);// this function checks to see if all elements of the set of the second object are also elements of the setof the first object. It also checks to see if the number of elements of the sets of the first element are more than those of the second set. This function returns true or false Finally, you probablyy will need , the function: bool Empty();// This function simply returns a copy of the integer elements that counts the number of elements in the set.C++ automatically , converts zero to false, and non-zero to throught when they are used as boolean return value. As an after thought, you may want users to be able to , creat objects of your class from an existing array of integer set of elements. The prototype will look like this: ClassName( int *intSetArray); Least I forget, since you will be using dynamic memory allocation, your class will need a destructor to free all dynamically allocated memory before the object is destroyed at the end of its useful life time. Destructors are like default constructor save for the fact that you must prepend them with the sign ~. The prototype of the destructor will be: ~ClassName(); So finally foue class should look something like this: class IntergerArray { int *IntArray; int ElementCount; public: IntegerArray(); IntegerArray( int *IntSetArray, int SetElementCount); IntegerArray(const IntegerArray &ExistingObject); IntegerArray operator = (const IntegerArray &ExistingObject); bool operator == (const IntegerArray &ExistingObject); boo operator != (const IntegerArray &ExistingObject); bool operator > (const IntegerArray &ExistingObject); bool operator < (const IntegerArray &ExistingObject); bool Empty(); bool IsSuperSet(const IntegerArray &SecondObject); bool IsSubSet(const IntegerArray &SecondObject); IntegerArray Intersection(const IntegerArray &SecondObject); IntegerArray Union(const IntegerArray &SecondObject); void Add(int NewELement); int Remove(int ElementToRemove); void Remove(int Position, int NElements); void RemoveAll(); //Additional memebers int SetElementCount(); // returns the number of elements in the set void SetPrintf();// Prints the set of elements }; So I will leave it to you as an assignment to write the implementation of the class, but will write the first few construction here and the operator assignment operator. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /// Implementation of IntegerArray class //// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// IntergerArray::IntegerArray(); { IntArray = NULL; ElementCount = 0; } IntegerArray::IntegerArray( int *IntSetArray, int SetElementCount) { if(IntArray != NULL)//delete existing array if, any { delete [] IntArray; } ElementCount = SetElementCount; for(int i = 0; i < ElementCount; i++) { IntArray[i] = IntSetArray[i]; } } IntegerArray::IntegerArray( const IntegerArray &ExistingObject) { if(IntArray != NULL)//delete existing array if, any { delete [] IntArray; } ElemetCount = ExistingObject.ElementCount; IntArray = new int [ElementCount]; for(int i = 0; i < ElementCount; i++) { IntArray[i] = ExistingElemet.IntArray[i]; } } IntegerArray IntegerArray::operator = ( const IntegerArray &ExistingObject) { if(IntArray != NULL)//delete existing array if, any { delete [] IntArray; } ElemetCount = ExistingObject.ElementCount; IntArray = new int [ElementCount]; for(int i = 0; i < ElementCount; i++) { IntArray[i] = ExistingElemet.IntArray[i]; } return *this; } bool IntegerArray::operator == (const IntegerArray & ExistingObject) { if(ElementCount != ExistingObject.ElementCount) { return false; } for(int i = 0; i < ElementCount; i++) { if(IntArray[i] != ExistingObject.IntArray[i]) { return false; } } return true; } bool IntegerArray::operator != (const IntegerArray & ExistingObject) { return !( this == ExistingObject);// This operator simply return the negetion of an equality check } bool IntegerArray::operator > (const IntegerArray & ExistingObject) { return (ElementCount > ExistingObject.ElementCount); } bool IntegerArray::operator < (const IntegerArray & ExistingObject) { return !(ElementCount > ExistingObject.ElementCount);// return the negetion of a greater than check } bool IntegerArray::Empty() { return ElementCount; } bool IntegerArray::IsSuperSet(const IntegerArray &SecondObject) { if(ElementCount >= SecondObject.ElementCount) { return false; } int Count = 0; for(int i = 0; i < ElementCount; i++) { for(int j = 0; j < SecondObject.ElementCount) { if(IntArray[i] == SecondObject.IntArray[j]) { Count++; break; } } } if(Count != ElementCount) { return fasle; } return true; } bool IntegerArray::IsSubSet(const IntegerArray &SecondObject) { if(SecondObject.ElementCount >= ElementCount) { return false; } int Count = 0; for(int i = 0; i < SecondObject.ElementCount; i++) { for(int j = 0; j < ElementCount) { if( SecondObject.IntArray[i] == IntArray[i]) { Count++; break; } } } if(Count != SecondObject.ElementCount) { return fasle; } return true; } void IntegerArray::Add(int NewELement) { ElementCount ++; // Creates a temporary buffer int *pIntArray = new int [ElementCount]; pIntArray[ElementCount - 1] = NewElement; //delete previous array delete [] IntArray; //Update array record IntArray = pIntArray; } IntegerArray IntegerArray::Intersection(const IntegerArray &SecondObject) { //Creates a temporary buffer IntegerArray TempObject; if(SecondObject.ElementCount < ElementCount) { for(int i = 0; i < SecondObject.ElementCount) { for(int j = 0; j < ElementCount) { if( SecondObject.IntArray[i] == IntArray[i]) { TempObject.Add(IntArray[i]); break; } } } } else { for(int i = 0; i < ElementCount) { for(int j = 0; j < SecondObject.ElementCount) { if(IntArray[i] == SecondObject.IntArray[j]) { TempObject.Add(IntArray[i]); break; } } } } return TempObject; } IntegerArray IntegerArray::Union(const IntegerArray &SecondObject) { //Creates a temporary buffer IntegerArray TempObject; //Fill in the gap return TempObject; } int IntArray::Remove(int ElementToRemove) { int NoOfElementsRemoved = 0; //Fill in the gap return NoOfElementsRemoved; } void IntegerArray::Remove(int Position, int NElements) { } void IntegerArray::RemoveAll() { } //Additional memebers int IntArray::SetElementCount() { return ElementCount; } void IntegerArray::SetPrintf()// Prints the set of elements { } IntegerArray::~IntegerArray() { if(IntArray != NULL) { delete [] IntArray; } } //I have almost written the entire class, now fill in the gap, correct comliation errors and debug the class. That all from me. Please note |
Twisterz: |
Twisterz:okay. I get it. a class to implement a mathematical SET of integers. |
ijeezlux:there is a quick sort function in std c library.Why dont u use it. |
Twisterz: |
Twisterz:what is the purpose of ur class? What is it expected to do? What priblen is it expected to solve. if u can answer one or more of d question i 'll able to guide u. |
pls how.did she.make her fortune.is ir from d talk show? |
spenca:The use of fell there is absilutely correct. Fell means to deliberately.make a tall object to fall. Check ur dictionary for more info. |
maclatunji:agbero is the appropriate translation of conductor. using it to describe the bus stop tout is actually bad yoruba. Agbero is a contraction for 'agba ero si oko' |
maclatunji:agbero is the appropriate translation of conductor. using it to describe the bus stop tout is actually bad yoruba. Agbero is a contraction for 'agba ero si oko' |
..I need to even know..
and intersect(set&, set&