Question
A small simulation for dual numbers of arbitrary length with n bits shall be programmed. To make it easy n is given as a constant
A small simulation for dual numbers of arbitrary length with n bits shall be programmed. To make it easy n is given as a constant at the start of the program code. Complete class DualSim (dual number simulation) with following members: a private Boolean array with n array elements simulating n bits as only attribute of this class. a public standard constructor which initialises all array elements with value false. a friend binary output operator > reading in its body within a for-loop one by one n characters ('0' or '1' ) from the character input stream given as parameter and store due to the read character value false or true in the respective array element (see examples below). a friend unary operator ! with a reference to an object of class DualSim as parameter, which returns an object of class DualSim and simulates bitwise negation. In its body e.g. within a for-loop each array element of the returned object shall get assigned the negated value of the respective array element of the parameter object (see examples below). a friend unary operator ++ with a reference to an object of class DualSim as parameter, which returns a reference to the same object and simulates a pre increment. Hint: program in its body e.g. within a for-loop from n-1 downto 0, i.e. treating the bit positions from right to left, an increment of 1 for the bit notation; define and use for this simulated increment a Boolean variable used as carry bit to the next higher bit position (see examples below). An overflow of the number range can and should be ignored. a friend binary operator + with two references to objects of class DualSim as parameters, which returns an object of class DualSim and simulates bitwise addition (see examples below). Hint: program in its body e.g. within a for-loop from n-1 downto 0, i.e. treating the bit positions from right to left, a bitwise addition; define and use for this simulated addition a Boolean variable used as carry bit to the next higher bit position (see examples below). An overflow of the number range can and should be ignored.
Your code together with following function main shall be compilable without modifications and run without errors:
#include
class DualSim { private: bool bit[n]; public: // ... };
int main(void) { cout > d1; cout > d2; cout
Wiederholung bitweise Addition und Beispiele/Repetition Bitwise Addition and Examples 0 + 0 = 0 0 + 1 = 1 1 + 0 = 1 1 + 1 = 0 und bertrag 1 in die nchsthhere Bitstelle/ and carry 1 in next higher bit position (0110011)2 (0111011 +(00 10 10 12 + (0010101 bertrag/carry '1101110 bertrag/carry 1111110 = (1 0 0 1 0 0 0)2 = (1 010000Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started