subject

Define a class named Bits that holds a single integer variable. You will use this integer simply as a container of bits. The number of bits you can support depends on the type of integer you use. We will use an unsigned long long, which on most platforms occupies 64 bits. However, DO NOT HARD-CODE the type of integer you use throughout your code. You should be able to change only one line of code for your class to work with a different size integer (see the using statement on the second code line below). The code skeleton below gets you started, and also shows you the interface your class needs to implement. I gave you the code for some of the functions. The body of at should help you with many other functions. class Bits { using IType = unsigned long long; // We only have to change the integer type here, if desired enum {NBITS = sizeof (IType) *8}; IType bits = 0; public: Bits () = default; Bits (IType n) { bits = n; } static int size () { return NBITS; bool at(int pos) const { // Returns (tests) the bit at bit-position pos assert (0 <= pos && pos < NBITS); return bits & (IType (1) << pos); } void set (int pos); // Sets the bit at position pos void set(); // Sets all bits void reset (int pos); // Resets (makes zero) the bit at position pos void reset(); // Resets all bits void assign(int pos, bool val); // Sets or resets the bit at position pos depending on val vois assign (IType n); // Replaces the underlying integer with n void toggle(int pos); // Flips the bit at position pos void toggle(); // Flips all bits void shift (int n) ; // If n > 0, shifts bits right n places; if n <0, shifts left void rotate (int n); // If n > 0, rotates right n places; if n < 0, rotates left int ones () const; // Returns how many bits are set in the underlying integer int zeroes () const { // Returns how many bits are reset in the underlying integer return NBITS ones(); ) IType to_int() const { return bits; 1 friend bool operator==(const Bits & bl, const Bits & b2) { return bl. bits b2.bits; 1 friend bool operator!=(const Bits& bl, const Bits & b2) { return bl. bits != b2.bits; 1 friend std::ostream& operator<<(std::ostream& os, const Bits & b) { return os << std::bitset (b. bits); // Be sure to #include ) ==
I have also defined for you the following non-member, friend functions:
an output stream operator (<<) that prints the bits to an output stream (without a newline; hint: use std::bitset)
the equality operator ==
the inequality operator !=
Remember that bit positions are numbered right-to-left, so bit-position 0 is the low-order (right-most) bit. "Rotate" means that bits that fall off one end replace the vacated bits on the other (in the same order as they appeared originally).
Define all functions inline in a header file named bits. h.
rotate is the most interesting function to implement.
I suggest that you develop your code offline in the development environment of your own choice, implementing and testing one function at a time. When you are satisfied everything is working, submit your code for grading.
Something think about
What will you do if a user of your Bits class tries to use a bit position out of range of what the integer holds? You can just use asserts for now, as shown above.
Remember
Never use using namespace std; in a header file!

ansver
Answers: 1

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 07:30
Jasper and samantha are in a robotics competition. the guidelines state that the robots should be able to move a 10-gram weight at least 2 meters and turn in a circle. jasper and samantha have already built the robot. which step of the design process should they follow next to decide whether their robot meets the minimum criteria for the competition?
Answers: 1
question
Computers and Technology, 23.06.2019 05:00
In cell b18, enter a formula to calculate the amount budgeted for meals. this amount is based on the daily meal allowance and the total travel days (# of nights+1).
Answers: 1
question
Computers and Technology, 23.06.2019 09:00
Which company provides a crowdsourcing platform for corporate research and development? a: mtruk b: wiki answers c: mediawiki d: innocentive
Answers: 2
question
Computers and Technology, 23.06.2019 10:50
Your friend kayla is starting her own business and asks you whether she should set it up as a p2p network or as a client-server network. list three questions you might ask to kayla decide which network to use and how her answers to those questions would affect your recommendation.
Answers: 2
You know the right answer?
Define a class named Bits that holds a single integer variable. You will use this integer simply as...
Questions
question
Mathematics, 18.06.2020 18:57
question
History, 18.06.2020 18:57