Switch to full style
C/C++ Technology Tutorials Written By Members.
Post a reply

vectors in c++

Sat Mar 26, 2011 2:20 am

1.A bit vector is a vector with binary elements, that is, each element is either a 0 or a 1. Small bit vectors are conveniently represented by unsigned integers. For example, an unsigned char can represent a bit vector of 8 elements. Larger bit vectors can be defined as arrays of such smaller bit vectors. Complete the implementation of the Bitvec class, as defined below. It should allow bit vectors of any size to be created and manipulated using the associated operators.
Code:
    
enum Bool 
{falsetrue};  
typedef unsigned char uchar;    
class 
BitVec {  
public:     
BitVec       (const short dim);     
BitVec       (const charbits);     
BitVec       (const BitVec&);     
~
BitVec    (void)       
 { 
delete vec
}     
BitVecoperator =    (const BitVec&);     
BitVecoperator &=   (const BitVec&);
BitVecoperator |=   (const BitVec&);    
BitVecoperator ^=   (const BitVec&);    
BitVecoperator <<=  (const short);     
BitVecoperator >>=  (const short);    
 
int    operator []    (const short idx);     
void   Set       (const short idx);     
void   Reset        (const short idx);       
BitVec  operator ~    (void);     
BitVec  operator &    (const BitVec&);     
BitVec  operator |    (const BitVec&);    
 
BitVec  operator ^    (const BitVec&);    
 
BitVec  operator <<   (const short n);    
 
BitVec  operator >>   (const short n);     
Bool   operator ==   (const BitVec&);     
Bool   operator !=    (const BitVec&);     
friend ostreamoperator << (ostream&, BitVec&);    
private:     
uchar  *vec;        // vector of 8*bytes bits     
short   bytes;       // bytes in the vector  
};
 




Re: vectors in c++

Sat Mar 26, 2011 10:14 am

code not clear :S :Blackeye:

Post a reply