Click here to Skip to main content
15,892,643 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
See more:
I want create class in C++ with these properties:
1- members of class are strings of length n that each character can get 0 or 1
2- describe a constructor without any parameters
3- describe function member of class that receive two members of class and returns OR operation
4- describe function member of class that receive two members of class and returns AND operation
I write this code please say my problem thanks:
C++
class CBoolOperate{
public:
   CBoolOperate ()//default constructor
   {
     a[5]=b[5]={0};
   };

   ~ CBoolOperate (){};//default destructor
void get()
{
cout<<"please enter first 5 binary digit\n";
for(int i=0;i<5;i++)
cin>>a[i];
cout<<"please enter second 5 binary digit\n";
for(int i=0;i<5;i++)
cin>>b[i];
}
void union(bool a[], bool b[])//A member function
   {
       bool c[5];
       for(int i=0;i<5;i++)
    {
    if (a[i]==1 || b[i]==1)c[i]=1;
    else c[i]=0;
    cout << c[i];
    }
    cout<<"\n";
   }
 void and(bool a[], bool b[])//A member function
   {
       bool c[5];
       for(int i=0;i<5;i++)
    {
    if (a[i]==1 && b[i]==1)c[i]=1;
    else c[i]=0;
    cout << c[i];
    }
    cout<<"\n";
   }
   bool a[5], b[5]; //Member variables
};
int main()
{
CBoolOperate  r;
r.get;
r.union;
r.and;
getch();
return 0;
}
Posted
Updated 12-Jun-11 9:03am
v3

1 solution

C++
r.get;
r.union;
r.and;


You're not calling the functions here.

C++
r.get();
r.union(argument1, argument2);
r.and(argument1, argument2);


But your class already contains the vector arguments, a and b, if I understood. So you could skip them from the argument list altogether.
C++
void union()
{
   ...
}

void and()
{
   ...
}


It's a bit of a mess as it is.
 
Share this answer
 
Comments
Member 7904482 12-Jun-11 13:47pm    
this is new code but it has a lot of errors:
#include <iostream>
using namespace std;
class CBoolOperate{
public:
CBoolOperate ()//default constructor
{
bool a[5];
bool b[5];
a[5]=b[5]={0};
};


~ CBoolOperate (){};//default destructor

void get()
{
cout<<"please enter first 5 binary digit\n";
for(int i=0;i<5;i++)
cin>>a[i];
cout<<"please enter second 5 binary digit\n";
for(int i=0;i<5;i++)
cin>>b[i];
}

bool union(a[], b[])//A member function
{
bool c[5];
for(int i=0;i<5;i++)
{
if (a[i]==1 || b[i]==1)c[i]=1;
else c[i]=0;
cout << c[i];
}
cout<<"\n";
}
void and(bool a[], bool b[])//A member function
{
bool c[5];
for(int i=0;i<5;i++)
{
if (a[i]==1 && b[i]==1)c[i]=1;
else c[i]=0;
cout << c[i];
}
cout<<"\n";
}

bool a[5], b[5]; //Member variables
};

int main()
{
CBoolOperate r;
r.get();
r.union(a[], b[]);
r.and(a[], b[]);
getch();
return 0;
}
Emilio Garavaglia 13-Jun-11 5:46am    
Beware to the name "union": in C and C++ union is keyword (like "for", "void" etc.) and you shouldn't use it as a name for variables or functions.

Also, it seems you don't have a clean understanding of the concept of automatic variables and member variables, and even a not clean understanding on how array works across functions.

You have better not to afford this program, until the basic concept I mentioned are absolutely clean to you, or your further experience will end in tears!


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900