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 01:30
How will you cite information that is common knowledge in your research paper?
Answers: 1
question
Computers and Technology, 22.06.2019 16:50
Consider a slotted aloha system, where the time slot equals the fixed duration of each packet. assume that there are 4 stations a,b,c,d sharing the medium. (a) stations a,b,c,d receive one packet each from higher layers at times 1.3, 1.5, 2.6,5.7 respectively. show which transmissions take place when, according to the slottedaloha protocol; describe all transmissions until all four packets have been successful.when needed, each station has access to the following sequence of random number, provided by a random number generator and drawn uniformly between 0 and 1: (1) station a draws numbers: 0.31, 0.27, 0.78, 0.9, 0.9, 0.11, 0. (2) station b draws numbers: 0.45, 0.28, 0.11, 0.83, 0.37, 0.22, 0. (3)station c draws numbers: 0.1, 0.2, 0.3, 0.4, 0. (4) station d draws numbers: 0.36, 0.77, 0.9, 0.1, 0.1, 0.1, 0.1, 0. (b) in slotted aloha, a station transmits in each time slot with a given probability. what probabilities would you assign to each of the four stations so as to: (i) maximize the efficiency of the protocol? (ii) maximize fairness among the four stations? (c) will the efficiency increase or decrease if we modify slotted aloha as follows: (i) get rid of slots and allow stations to transmit immediately? (ii) implement carrier sensing? (iii) implement collision detection? (iv) implement collision avoidance?
Answers: 3
question
Computers and Technology, 22.06.2019 17:00
Your company has 1,500 desktop computers running windows 7. you want to upgrade them to windows 10. which type of microsoft license would be best suited in this situation?
Answers: 3
question
Computers and Technology, 22.06.2019 22:30
Write a full class definition for a class named player , and containing the following members: a data member name of type string .a data member score of type int .a member function called setname that accepts a parameter and assigns it to name . the function returns no value.a member function called setscore that accepts a parameter and assigns it to score . the function returns no value.a member function called getname that accepts no parameters and returns the value of name .a member function called getscore that accepts no parameters and returns the value of score .this is what i have, aparently this is wrong: class player{private: string name; int score; public: void player: : setname (string n){name =n; }void player: : setscore (int s){score = s; }string player: : getname (){return name; }int player: : getscore (){return score; }};
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
Social Studies, 05.02.2021 22:50
question
Mathematics, 05.02.2021 22:50
question
Mathematics, 05.02.2021 22:50
question
Biology, 05.02.2021 23:00
question
Biology, 05.02.2021 23:00
Questions on the website: 13722361