Question: 2. (Creating Object Adapters for Bitset, Compile-Time (Composition)) In this exercise we create a compile-time bit matrix (call it BitMatrix ) consisting of N rows

2. (Creating Object Adapters for Bitset, Compile-Time (Composition))

In this exercise we create a compile-time bit matrix (call it BitMatrix) consisting of N rows and M columns all of whose elements are bits. Some requirements are:

 The chosen data structure must be efficient (for example, accessing the elements).

 Its interface must have the same look and feel as that of std::bitset<>.

 We wish to reuse as much code as possible.

 It must be generic enough to support a range of applications in different domains (for example, computer graphics and its many applications).

Answer the following questions:

a) Determine which data structure to use in order to implement BitMatrix, for example as a nested array std::array, N> or a one-dimensional array std::bitset. Which choice is ‘optimal’ is for you to decide. You need to determine which criteria to use (for example, performance and maintainability).

b) Constructors need to be created. Use the same defaults as with std::bitset.

c) Implement the following operators for all rows in the matrix and for a given row in the matrix:

 Set/reset all bits.

 Flip the bits.

 Test if none, all or any bits are set.

 Access the elements.

 Count the number of set bits.

d) Create member functions for OR, XOR and AND Boolean operations on bit matrices.

e) Consider creating the matrix as a derived class of bitset.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Accounting For Financial Instruments Questions!