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 19:30
When creating a presentation in libre office impress, where does the editing of slides take place? a. the slides panel b. the center panel c. the tasks panel, under the masters pages tab d. the tasks panel, under the layouts tab
Answers: 3
question
Computers and Technology, 24.06.2019 09:50
Suppose you are an ad-serving company and you maintain a log of cookie data for ads you serve to the web pages for a particular vendor (say amazon). a. how can you use this data to determine which are the best ads? b. how can you use this data to determine which are the best ad formats? c. how could you records of past ads and ad clicks to determine which ads to send to a given ip address? d. how could you use this data to determine how well the technique you used in your answer to part c was working? e. how could you use this data to determine that a given ip address is used by more than one person? f. how does having this data give you a competitive advantage vis-à-vis other ad-serving companies?
Answers: 2
question
Computers and Technology, 24.06.2019 21:40
is on drugs i swear i ask a question and its not showing whats going
Answers: 2
question
Computers and Technology, 25.06.2019 03:00
What judgment would you make about open systems interconnect? not useful that it is a technology that it is a model that it does not pertain to technology
Answers: 1
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, 10.03.2021 22:10
question
Mathematics, 10.03.2021 22:10
question
Mathematics, 10.03.2021 22:10
Questions on the website: 13722363