c++ - Bit Array Program -


So I am in the summer of OO class and yesterday we have an exam based on this project. In fact, we need to create an array that holds bits in an unspecified quantity and writes four functions which set this array - Set set with set bit 1 , Unset () // set 0 , flip () // change bit (with the given index) and query () // with the given index. If true Bit is set, then set to true 1, wrong otherwise .

If there is any interest then this is a complete statement: and some sample runs:

The problem I have is with high level concept I am quite sure that we Want to store the byte presentations of bits in each index. If this is true, then I am in a disadvantage for the implementation of the tasks completely, if someone can give me some indication on how I can reach it (I think this should be a good understanding tonight because tomorrow I am tomorrow I would write some pseudo code for) I would be quite appreciative.

This is my .h if it helps

  // bitarray.h // // bitrate class declaration #ifndef _BITARRAY_H # Define _BITARRAY_H # include & lt; Iostream & gt; using namespace std; Class bitters {buddy ostream & amp; For operator & lt; & Lt; (Ostream and OS, Const Bitter and A); Friend Bull Operator == (Cost Bitter End, Const Bitter & amp;); Buddy operator! = (Const Bite End, Constant Breath & amp;); Public: bitter (unsigned int n); // Create an array that can handle the N bits bitarre (const bitrate & amp;); // copy constructor ~ bitrate (); // Distict Bitter & amp; Operator = (console bitrate and a); // Assignment operator unsigned int length () const; Return number of bits in // Bitterarre zero set (unsigned index index); // Set zero with 1 zero unset (unsigned index index) with given index; // 0 zero flip (unsigned index index) with zero given index; // change bit (with given index) bool query (unsigned index index) const; // If the correct bit is set to // 1, then false would be otherwise private: unsigned char * barray; // bit array indicator for int array; }; #endif   

and my constructor:

  BitArray :: BitArray (unsigned int n) {int size = sizeof (char); If (n% (8 * size)! = 0) array = ((n / (8 * size)) + 1); Second array = size = n / (8 * size); Barray = New unsigned char [array]; For (Int i = 0; I & lt; arrays; I ++) Barre [I] = 0; }    

set to and query () , find the position of the word in which your interest is slightly shorter. (Your code starts using char as the word.) Then, find the position of the bit within this word. Create a bitmask that addresses specific bits, you will need a transfer operator for it. Remember bit-bit operators who will eventually help you in your job. Sometimes bit-wise assignment operators will be more elegant.

Do you remember the BitWord XOR operator in C ++? Use it with flip () to implement it using set () . Finally unset () . Use the bit wise incorporation operator to implement

. Note that your method of determining array size is very complex. Consider using std that range (a / b) == bottom ((+ a + b-1) / B) Remember in those cases which can be here. :: Vector If you have permission instead of a simple array Speaker below!

This class also has an interesting expertise.

By changing your class to a template where you have the actual storage unit ( char , uint16_t , ...) in the form of parameters You can specify in For starters, say typedef char WORD_TYPE and see that when you change the definition of WORD_TYPE , then your code is compiled later.

Comments

Popular posts from this blog

Python SQLAlchemy:AttributeError: Neither 'Column' object nor 'Comparator' object has an attribute 'schema' -

java - How not to audit a join table and related entities using Hibernate Envers? -

mongodb - CakePHP paginator ignoring order, but only for certain values -