Question: Write a C++ program that reads two strings of binary digits and adds them using a simulation of a full-adder. The program must contain a
Write a C++ program that reads two strings of binary digits and adds them using a simulation of a full-adder.
The program must contain a routine that simulates a half-adder, which the full adder routine will need to call twice in order to perform the addition.
The program should implement routines to simulate AND, OR, and NOT gates, (and possibly XOR gates). Your program should accept strings of binary digits up to eight in length (can be shorter than 8 bits), and print each step in the binary addition of the two strings, including any carries. Then the program should output the final result of the addition.
The program should respond gracefully (but not end) if the input is not a string of ones and zeros.
Set up the program to repeat four times so that I can test it on four different sets of numbers without having to restart it each time.
See attached file for example output.
Hints:
1. You will need to write a routine called something like HALFADDER. It will have two parameters, p and q. The routine will calculate a sum and a carry using AND, OR and NOT operations and/or possibly XOR. Your main program will not call the HALFADDER routine. This routine will only be called by the FULLADDER routine.
2. Then you will need a routine called something like FULLADDER. It will call the half adder routine twice for each pair of bits that you want to add. The full adder routine will have three parameters, the two bits that you want to add and the carry-in from the previous operation. The full adder routine will calculate a sum and a carry-out for the two bits that you are adding. The carry-out will become the carry-in for the next two bits.
Runs 4 times Shows each step Adds correctly Simulates full and half adders Responds gracefully if input is not correct Bonus: Put a space every 4 bits
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
