Implement a Ripple-Carry Adder using a C++ class. The constructor of your adder must take an integer parameter, indicating of the maximum length (i.e. number of bits) that are supported. Keep all class members that are not accessed "from the outside" private. You must have at least 1 private class member. Implement an add-function in the adder class that takes 2 arguments containing the numbers that are to be added. The type of these arguments may vary depending on your implementation. In your main class create a single instance of your adder that you will use to calculate the sum of 2 numbers. Use 5 as the parameter for maximum length.
Once the program is started, it will print out the promt "ripple_carry> " (> is followed by a whitespace):
./a.out
ripple_carry>
You will implement the commands "add" and "quit":
Add takes 2 arguments, which represent the numbers that must be added. The result will be on a new line without any leading zeros. Then repeat the prompt.
ripple_carry> add 101 11
1000
ripple_carry> add 001 100
101
ripple_carry> add 01 00111
1000
ripple_carry>
Exit the program
ripple_carry> quit
Example of program execution:
ripple_carry> add 11 1110
10001
ripple_carry> add 001 1010
1011
ripple_carry> add 1 1
10
ripple_carry> subtract
Error! Not a valid command.
ripple_carry> hi
Error! Not a valid command.
ripple_carry> add -101 1110
Error! Number is negative.
ripple_carry> add 1011 -1
Error! Number is negative.
ripple_carry> add -01 1
Error! Number is negative.
ripple_carry> add 1010101 01
Error! Number exceeds 5 bits.
ripple_carry> add 1 11111111
Error! Number exceeds 5 bits.
ripple_carry> add 11111 1
Error! Overflow!
ripple_carry> add 10101 10101
Error! Overflow!
ripple_carry> add 101 12
Error! Number is not binary.
ripple_carry> add 200 101
Error! Number is not binary.
ripple_carry> quit