Hi I am doing a program oveloraded operator.
I am having a few errors on it.
Error1: request for member `insertElement' in `S1set', which is of
non-
class type `IntegerSet[26]'
Error2: no matching function for call to `IntegerSet::op erator+
(IntegerSet[26])'
Here is my program:
class IntegerSet
{
private:
bool set[26];
int element;
public:
//Operator methods.
IntegerSet operator + (const IntegerSet &)const;//method union
//Methods
IntegerSet(); //default constructor
IntegerSet(int x[], int k); //overload constructor
bool isValid(int)con st;
void insertElement(i nt);
void deleteElement(i nt);
void setString();
void inputSet();
};
IntegerSet set();
IntegerSet::Int egerSet()
{
for(element=0; element>=25; element++)
set[element]= false;
}
IntegerSet::Int egerSet(int x[], int k)
{
for(element=0; element>=25; element++)
set[element]= false;
for(int j=0; j<k; j++)
{
element=x[j];
set[element]= true;
}
}
bool IntegerSet::isV alid(int i)const
{
return set[i];
}
//insert element to a set
void IntegerSet::ins ertElement(int element)
{
set[element]=true;
}
//delete element of a set
void IntegerSet::del eteElement(int element)
{
set[element]=false;
}
//overloaded operator + to compute the union of two sets
IntegerSet IntegerSet::ope rator+(const IntegerSet &right)const
{
IntegerSet j;
for(int element=0; element<=25; element++)
{
if(isValid(elem ent) || right.isValid(e lement))
j.insertElement (element);
}
return j;
}
int main()
{
IntegerSet run;
IntegerSet S1set[26];
IntegerSet S2set[26];
IntegerSet S3set[26];
IntegerSet Sset[26];
for(int i=2; i<=20; i+2)
S1set.insertEle ment(); <--Error 1
for(int k=6; k<=21; k+3)
S2set.insertEle ment(); <--Error 1
for(int j=3; j<=18; j+6)
S3set.insertEle ment(); <--Error 1
for(int z=0; z<=25; z++)
Sset.insertElem ent(); <--Error 1
run.inputSet();
int choice;
cout<<"\n WELCOME to the INTEGER SET PROGRAM\n";
cout<<"\n\nSele ct one of these choices\n";
cout<<" 0. Create set \n";
cout<<" 1. Find Union \n";
cin>>choice;
if(choice==0)
{
int temp, ele;
int newSet[26];
cout<<"Enter how many elements you want in the set: "<<endl;
cin>>ele;
for(int i=0; i<ele; i++)
{
cout<<i+1;
cin>>temp;
newSet[i]=temp;
}
}
else if(choice==1)
{
char a, b, c, d, e,;
int option;
cout<<"Select one of this choices";
cout<<"a. To find the union of the set you enter and the set
'S'";
cout<<"b. To find the union of the set you enter and the set
'S1'";
cout<<"c. To find the union of the set you enter and the set
'S2'";
cout<<"d. To find the union of the set you enter and the set
'S3'";
cin>>option;
if(option=='a'| |option=='A')
{
run.operator+(S set); <--Error 2
}
else if(option=='b'| |option=='B')
{
run.operator+(S 1set); <--Error 2
}
else if(option=='c'| |option=='C')
{
run.operator+(S 2set); <--Error 2
}
else if(option=='d'| |option=='D')
{
run.operator+(S 3set); <--Error 2
}
}
return 0;
}
I hope some one can help me.
I am having a few errors on it.
Error1: request for member `insertElement' in `S1set', which is of
non-
class type `IntegerSet[26]'
Error2: no matching function for call to `IntegerSet::op erator+
(IntegerSet[26])'
Here is my program:
class IntegerSet
{
private:
bool set[26];
int element;
public:
//Operator methods.
IntegerSet operator + (const IntegerSet &)const;//method union
//Methods
IntegerSet(); //default constructor
IntegerSet(int x[], int k); //overload constructor
bool isValid(int)con st;
void insertElement(i nt);
void deleteElement(i nt);
void setString();
void inputSet();
};
IntegerSet set();
IntegerSet::Int egerSet()
{
for(element=0; element>=25; element++)
set[element]= false;
}
IntegerSet::Int egerSet(int x[], int k)
{
for(element=0; element>=25; element++)
set[element]= false;
for(int j=0; j<k; j++)
{
element=x[j];
set[element]= true;
}
}
bool IntegerSet::isV alid(int i)const
{
return set[i];
}
//insert element to a set
void IntegerSet::ins ertElement(int element)
{
set[element]=true;
}
//delete element of a set
void IntegerSet::del eteElement(int element)
{
set[element]=false;
}
//overloaded operator + to compute the union of two sets
IntegerSet IntegerSet::ope rator+(const IntegerSet &right)const
{
IntegerSet j;
for(int element=0; element<=25; element++)
{
if(isValid(elem ent) || right.isValid(e lement))
j.insertElement (element);
}
return j;
}
int main()
{
IntegerSet run;
IntegerSet S1set[26];
IntegerSet S2set[26];
IntegerSet S3set[26];
IntegerSet Sset[26];
for(int i=2; i<=20; i+2)
S1set.insertEle ment(); <--Error 1
for(int k=6; k<=21; k+3)
S2set.insertEle ment(); <--Error 1
for(int j=3; j<=18; j+6)
S3set.insertEle ment(); <--Error 1
for(int z=0; z<=25; z++)
Sset.insertElem ent(); <--Error 1
run.inputSet();
int choice;
cout<<"\n WELCOME to the INTEGER SET PROGRAM\n";
cout<<"\n\nSele ct one of these choices\n";
cout<<" 0. Create set \n";
cout<<" 1. Find Union \n";
cin>>choice;
if(choice==0)
{
int temp, ele;
int newSet[26];
cout<<"Enter how many elements you want in the set: "<<endl;
cin>>ele;
for(int i=0; i<ele; i++)
{
cout<<i+1;
cin>>temp;
newSet[i]=temp;
}
}
else if(choice==1)
{
char a, b, c, d, e,;
int option;
cout<<"Select one of this choices";
cout<<"a. To find the union of the set you enter and the set
'S'";
cout<<"b. To find the union of the set you enter and the set
'S1'";
cout<<"c. To find the union of the set you enter and the set
'S2'";
cout<<"d. To find the union of the set you enter and the set
'S3'";
cin>>option;
if(option=='a'| |option=='A')
{
run.operator+(S set); <--Error 2
}
else if(option=='b'| |option=='B')
{
run.operator+(S 1set); <--Error 2
}
else if(option=='c'| |option=='C')
{
run.operator+(S 2set); <--Error 2
}
else if(option=='d'| |option=='D')
{
run.operator+(S 3set); <--Error 2
}
}
return 0;
}
I hope some one can help me.
Comment