Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,160,449 members, 7,843,369 topics. Date: Wednesday, 29 May 2024 at 12:33 AM

Any C++ Programmer In The House - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Any C++ Programmer In The House (1967 Views)

Dear Programmer In Nigeria: How Much Is Your Salary? / What Is The Average Salary Of A Php Programmer In Lagos (2) (3) (4)

(1) (Reply) (Go Down)

Any C++ Programmer In The House by Twisterz: 9:32pm On Oct 22, 2014
I need urgent help on the use of class in c++
Re: Any C++ Programmer In The House by mivicssmith: 10:29pm On Oct 22, 2014
Yeap! On wah aspect?!
Re: Any C++ Programmer In The House by Twisterz: 12:12am On Oct 23, 2014
a class to implement a set of integers with at least seven functions including constructor print() to display a set empty() which should return a true or false value, add element(const int), remove element(const int), intersect(set&, set&) and intersect(set&, set&). the set class should create three sets and exercise some member functions
Re: Any C++ Programmer In The House by mivicssmith: 12:26am On Oct 23, 2014
A class?! Or Program?! Or functions?! Moreova, dre bufin like print() rada printf().
Re: Any C++ Programmer In The House by BlueMagnificent(m): 9:56am On Oct 23, 2014
Twisterz:
a class to implement a set of integers with at least seven functions including constructor print() to display a set empty() which should return a true or false value, add element(const int), remove element(const int), intersect(set&, set&wink and intersect(set&, set&wink. the set class should create three sets and exercise some member functions

I'll suggest you first of all show us the attempts you've made in solving this problem, then you will be assisted smiley
Re: Any C++ Programmer In The House by dgbanj: 4:02pm On Oct 23, 2014
//Simple Class to demonstrate Constructor

#include <iostream>
using namespace std;

class Twisterz
{
private:
int age;
public:
Twisterz(int a)
{
age=a;
cout<<"Age is:"<<age<<endl;
}
};

int main( )
{
Twisterz obj=new Twisterz(30);
return 0;
}
Re: Any C++ Programmer In The House by classiclee(m): 1:12am On Oct 25, 2014
dgbanj:
//Simple Class to demonstrate Constructor

#include <iostream>
using namespace std;

class Twisterz
{
private:
int age;
public:
Twisterz(int a)
{
age=a;
cout<<"Age is:"<<age<<endl;
}
};

int main( )
{
Twisterz obj=new Twisterz(30);
return 0;
}
Bro am a c++ Learner But the query grin here is explainable
#include <iostream>
#include <math.h>
using namespace std;
class Twisterz
{
private:
int age;
public:
Twisterz(int a)
{
age=a;
cout<<"Age is:"<<age<<endl;
}
}

int main( )
{
/*you can't call a string twice it would rewrite*/
void Twiterz = Twisterz(30);
cout<<Twiterz;
}
Re: Any C++ Programmer In The House by dgbanj: 7:04am On Oct 25, 2014
classiclee:

Bro am a c++ Learner But the query grin here is explainable
#include <iostream>
#include <math.h>
using namespace std;
class Twisterz
{
private:
int age;
public:
Twisterz(int a)
{
age=a;
cout<<"Age is:"<<age<<endl;
}
}

int main( )
{
/*you can't call a string twice it would rewrite*/
void Twiterz = Twisterz(30);
cout<<Twiterz;
}


It is constructor initialization and not a string ok. Try to use your own program to help out next time. Thankx
Re: Any C++ Programmer In The House by ijeezlux(m): 1:51pm On Oct 25, 2014
Am a c++ programmer, though i have not really gone far into it. But i have understood every bit of c++ code i have learnt. I have longed wish to hook up with other like-minded programmers so we can share ideas. Well i wil b thankful if u guys drop ur phone numbers, so we can interact beta on other platform like whatsapp and facebook. My numb is 08036407597.
Re: Any C++ Programmer In The House by classiclee(m): 8:09pm On Oct 25, 2014
ijeezlux:
Am a c++ programmer, though i have not really gone far into it. But i have understood every bit of c++ code i have learnt. I have longed wish to hook up with other like-minded programmers so we can share ideas. Well i wil b thankful if u guys drop ur phone numbers, so we can interact beta on other platform like whatsapp and facebook. My numb is 08036407597.
grin well am just learning though
BBM 22C6EA61 , 07067479186 Facebook http://facebook.com/abbeyclassiclee
Re: Any C++ Programmer In The House by mivicssmith: 10:33pm On Oct 26, 2014
08133283494, 3322E146
Re: Any C++ Programmer In The House by Nobody: 1:24am On Oct 27, 2014
Oho, correct C++ programmers don answer. . . . .me i be retired C-- programmer
Re: Any C++ Programmer In The House by ijeezlux(m): 4:15pm On Oct 27, 2014
mivicssmith:
08133283494, 3322E146
tanks 4 dropping ur numb. Lets talk more on whatsapp. I wil stil b grateful if oda programmers apart from c++ e.g java nd c drop their number cos i strongly believe that we can stil be useful to each oda. Tanks
Re: Any C++ Programmer In The House by WhiZTiM(m): 6:02pm On Oct 27, 2014
What in the name of Bjarne Stroustrup is going on here? ...
The code snippets aren't correct.
Re: Any C++ Programmer In The House by Nobody: 12:41am On Oct 28, 2014
^^^Hehehe, i just saw it now sef, interesting. . . .
Re: Any C++ Programmer In The House by ijeezlux(m): 12:43pm On Nov 18, 2014
Hello good day my fellow programmer, i did some coding which i use to sort array of int elements using the quicksort technique. To an extent the program i wrote to implement the sorting using the quicksort worked very well but not that efficient because when i used the program to sort an array that has more than 15 elemnets, the program does give me the desired result that i want.
Here is how quicksort technique works, it has two steps:
1) Partitioning step: take the first element of the unsorted array and determine its final location in the sorted array(i.e,, all values to the left of the element in the array are less than the element, and all values to the right of the element in the array are greater than the element). We now have element in its proper location and two unsorted subarrays.

2) Recursive Step: perform step 1 on each subarray.

Now let me break down the step 1 further so that you will have a broader knowledge of what i am trying to explain. Each time step 1 is perform on a subarray, another element is placed in its final location of the sorted array, and two unsorted arrays are created. When a subarray consists of one element, that array must be sorted; therefore the element is in its final location.
The basic algorithm seem simple enough, but how do we determine the final position of the first element of each subarray? As an example, consider the following set of values (the element in bold is the partitioning element__it will be placed in its final location in the sorted array):
37 2 6 4 89 8 10 12 68 45

a) Starting from the rightmost element of the array, compare each element with 37 until an element less than 37 is founnd. Then swap 37 and that element. The first element less than 37 is 12, so 37 and 12 are swapped. The values now reside in the arrays as follow:
12 2 6 4 89 8 10 37 68 45

b) Starting from the left of the array, but beginning with the element after 12, compare each element with 37 until
an element greater than 37 is found. Then swap 37 and that element. The first element greater than 37 is 89, so 37 and 89 are swapped. The values now reside in the array as follow:
12 2 6 4 37 8 10 89 68 45

c) Starting from the right, but beginning with the element before 89, compare each element with 37 until an element less tha 37 is found. Then swap 37 and that element. the first element less than 37 is 10, so 37 and 10 are swapped. The values now reside in the array as follows:
12 2 6 4 10 8 37 89 68 45

d) Starting from the left, but with the element after 10, compare each element with 37 until an element greater than 37 is found, then swap 37 and that element. There ar no more elements greater than 37, so when we compare 37 with itself, we know that 37 has been placed in its final location of the sorted array.

Once the partition has been applied to the array, there are two unsorted subarrays. The subarray with values less than 37 contains 12, 2, 6, 4, 10, and 8. The subarray with values greater than 37 contains 89, 68 and 45. The sort continues with both subarrays being partitioned in the same manner as the original array.
Based on the preceding discussion write recursive function quicksort to sort a single sub-scripted integer array. the function should receive as arguments an integer array, a starting subscript and an ending subscript. Function partition should be called by quicksort to perform the partitioning steps
Re: Any C++ Programmer In The House by ijeezlux(m): 12:53pm On Nov 18, 2014
Guys this is the code i wrote to implement this quicksort sorting technique, please lets join hands and analyze the program and looks for ways on how to upgrade the code and make it more efficient, efficient enough to sort array of any elements:

#include <iostream>
using namespace std;
void swap(int *, int *);
void quicksort(int *, int, int);
int partition(int *, int, int);

int main ()
{
int first_index, last_index;
const int size = 10;
int data[size]={30, 70, 5, 10, 75, 81, 23, 41, 93, 53};
first_index = 0; last_index = size-1;
cout << "The unsorted elements are: \n";
for(int i = 0; i < size; ++i)
cout << " " << data[i];
cout << "\n\n";
quicksort(data, first_index, last_index);
cout << "The sorted elements are: \n";
for(int i=0; i<size; ++i)
cout << " " << data[i];
return 0;

}
void swap(int *element1, int *element2)
{
int tempstore;
tempstore = *element1;
*element1 = *element2;
*element2 = tempstore;
}

int partition(int *value, int index1, int index2)
{
while(value[index1]<value[index2])
--index2;
swap(&value[index1], &value[index2]);
while(value[index1]<value[index2])
++index1;
swap(&value[index1], &value[index2]);
while(value[index2]>value[index1])
--index2;
swap(&value[index1], &value[index2]);



return index2;
}

void quicksort(int *aray, int first, int last)
{


int pivot;
/* Termination condition! */
if ( last > first )
{
pivot = partition( aray, first, last );
quicksort( aray, first, pivot-1 );
quicksort( aray, pivot+1, last );
}

}
Re: Any C++ Programmer In The House by 2mNaira: 7:41pm On Nov 21, 2014
Twisterz:
a class to implement a set of integers with at least seven functions including constructor print() to display a set empty() which should return a true or false value, add element(const int), remove element(const int), intersect(set&, set&wink and intersect(set&, set&wink. the set class should create three sets and exercise some member functions

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.
Re: Any C++ Programmer In The House by 2mNaira: 7:41pm On Nov 21, 2014
Twisterz:
a class to implement a set of integers with at least seven functions including constructor print() to display a set empty() which should return a true or false value, add element(const int), remove element(const int), intersect(set&, set&wink and intersect(set&, set&wink. the set class should create three sets and exercise some member functions
Re: Any C++ Programmer In The House by 2mNaira: 7:44pm On Nov 21, 2014
ijeezlux:
Guys this is the code i wrote to implement this quicksort sorting technique, please lets join hands and analyze the program and looks for ways on how to upgrade the code and make it more efficient, efficient enough to sort array of any elements:

#include <iostream>
using namespace std;
void swap(int *, int *);
void quicksort(int *, int, int);
int partition(int *, int, int);

int main ()
{
int first_index, last_index;
const int size = 10;
int data[size]={30, 70, 5, 10, 75, 81, 23, 41, 93, 53};
first_index = 0; last_index = size-1;
cout << "The unsorted elements are: \n";
for(int i = 0; i < size; ++i)
cout << " " << data[i];
cout << "\n\n";
quicksort(data, first_index, last_index);
cout << "The sorted elements are: \n";
for(int i=0; i<size; ++i)
cout << " " << data[i];
return 0;

}
void swap(int *element1, int *element2)
{
int tempstore;
tempstore = *element1;
*element1 = *element2;
*element2 = tempstore;
}

int partition(int *value, int index1, int index2)
{
while(value[index1]<value[index2])
--index2;
swap(&value[index1], &value[index2]);
while(value[index1]<value[index2])
++index1;
swap(&value[index1], &value[index2]);
while(value[index2]>value[index1])
--index2;
swap(&value[index1], &value[index2]);



return index2;
}

void quicksort(int *aray, int first, int last)
{


int pivot;
/* Termination condition! */
if ( last > first )
{
pivot = partition( aray, first, last );
quicksort( aray, first, pivot-1 );
quicksort( aray, pivot+1, last );
}

}


there is a quick sort function in std c library.Why dont u use it.
Re: Any C++ Programmer In The House by 2mNaira: 7:49pm On Nov 21, 2014
Twisterz:
a class to implement a set of integers with at least seven functions including constructor print() to display a set empty() which should return a true or false value, add element(const int), remove element(const int), intersect(set&, set&wink and intersect(set&, set&wink. the set class should create three sets and exercise some member functions

okay. I get it. a class to implement a mathematical SET of integers.
Re: Any C++ Programmer In The House by 2mNaira: 7:49pm On Nov 21, 2014
Twisterz:
a class to implement a set of integers with at least seven functions including constructor print() to display a set empty() which should return a true or false value, add element(const int), remove element(const int), intersect(set&, set&wink and intersect(set&, set&wink. the set class should create three sets and exercise some member functions
Re: Any C++ Programmer In The House by 2mNaira: 8:27pm On Nov 21, 2014
Twisterz:
a class to implement a set of integers with at least seven functions including constructor print() to display a set empty() which should return a true or false value, add element(const int), remove element(const int), intersect(set&, set&wink and intersect(set&, set&wink. the set class should create three sets and exercise some member functions

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
Re: Any C++ Programmer In The House by 2mNaira: 3:32pm On Nov 23, 2014
.
Re: Any C++ Programmer In The House by 2mNaira: 3:34pm On Nov 23, 2014
.
Re: Any C++ Programmer In The House by ijeezlux(m): 7:49pm On Nov 25, 2014
mnairaland:



there is a quick sort function in std c library.Why dont u use it.
u might be right but as a programmer who want to reach the peak, you should lok for ways to solve ur problems ursef.
If i may ask, which of the standard lib class wil i get the function to perform the quicksort?
Re: Any C++ Programmer In The House by ijeezlux(m): 9:49pm On Nov 25, 2014
mnairaland:


okay. I get it. a class to implement a mathematical SET of integers.
my friend i wil realy appreciate if talk on other platform, may be facebok and whatsapp. Plz send me a whatsapp message to my numb( 08036407597 ) my facebuk name is cletus ijeoma onyoke. Or better stil give me ur number and facebuk detail let me send u a message right away. Thanks

(1) (Reply)

Heeeeeeeeeeelp Pls / Pls Help. How Do I Convert Excel Sheets To Vcard For Free Pls Pls Pls / Can BASIC Be Introduced To This Forum?

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 91
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.