L
Latina
Hi I am doing a program overloaded 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:perator+
(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)const;
void insertElement(int);
void deleteElement(int);
void setString();
void inputSet();
};
IntegerSet set();
IntegerSet::IntegerSet()
{
for(element=0; element>=25; element++)
set[element]= false;
}
IntegerSet::IntegerSet(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::isValid(int i)const
{
return set;
}
//insert element to a set
void IntegerSet::insertElement(int element)
{
set[element]=true;
}
//delete element of a set
void IntegerSet::deleteElement(int element)
{
set[element]=false;
}
//overloaded operator + to compute the union of two sets
IntegerSet IntegerSet:perator+(const IntegerSet &right)const
{
IntegerSet j;
for(int element=0; element<=25; element++)
{
if(isValid(element) || right.isValid(element))
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.insertElement(); <--Error 1
for(int k=6; k<=21; k+3)
S2set.insertElement(); <--Error 1
for(int j=3; j<=18; j+6)
S3set.insertElement(); <--Error 1
for(int z=0; z<=25; z++)
Sset.insertElement(); <--Error 1
run.inputSet();
int choice;
cout<<"\n WELCOME to the INTEGER SET PROGRAM\n";
cout<<"\n\nSelect 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=temp;
}
}
else if(choice==1)
{
char a, b, c, d;
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+(Sset); <--Error 2
}
else if(option=='b'||option=='B')
{
run.operator+(S1set); <--Error 2
}
else if(option=='c'||option=='C')
{
run.operator+(S2set); <--Error 2
}
else if(option=='d'||option=='D')
{
run.operator+(S3set); <--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:perator+
(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)const;
void insertElement(int);
void deleteElement(int);
void setString();
void inputSet();
};
IntegerSet set();
IntegerSet::IntegerSet()
{
for(element=0; element>=25; element++)
set[element]= false;
}
IntegerSet::IntegerSet(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::isValid(int i)const
{
return set;
}
//insert element to a set
void IntegerSet::insertElement(int element)
{
set[element]=true;
}
//delete element of a set
void IntegerSet::deleteElement(int element)
{
set[element]=false;
}
//overloaded operator + to compute the union of two sets
IntegerSet IntegerSet:perator+(const IntegerSet &right)const
{
IntegerSet j;
for(int element=0; element<=25; element++)
{
if(isValid(element) || right.isValid(element))
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.insertElement(); <--Error 1
for(int k=6; k<=21; k+3)
S2set.insertElement(); <--Error 1
for(int j=3; j<=18; j+6)
S3set.insertElement(); <--Error 1
for(int z=0; z<=25; z++)
Sset.insertElement(); <--Error 1
run.inputSet();
int choice;
cout<<"\n WELCOME to the INTEGER SET PROGRAM\n";
cout<<"\n\nSelect 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=temp;
}
}
else if(choice==1)
{
char a, b, c, d;
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+(Sset); <--Error 2
}
else if(option=='b'||option=='B')
{
run.operator+(S1set); <--Error 2
}
else if(option=='c'||option=='C')
{
run.operator+(S2set); <--Error 2
}
else if(option=='d'||option=='D')
{
run.operator+(S3set); <--Error 2
}
}
return 0;
}
I hope some one can help me.