Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

objective: This homework is an advanced introduction to C++ classes with operato

ID: 3855446 • Letter: O

Question

objective: This homework is an advanced introduction to C++ classes with operator overloading. The goal is to gain better knowledge of classes and utilize operator overloading where appropriate. Checklist: 1. Review the assignment specification 2. Review Binary Numbers 3. Please review how to separate your class into an implementation, definition, and driver sections. These will all become separate files as outlined below. 4. Create a binary·cpp (should contain the class implementation only) , binary.h (should contain your class definition, no functions), binary-sandbox.cpp (should contain the main() and #include "binary.h") file within your IDE. 5. Develop a Binary class definition. Do not bother at first to create the individual functions. You can do that later. Have it checked by your instructor. 6. Use the binary-sandbox.cpp to test your Class. 7. Create and test each operator one at a time. The easiest operators for this assignment may be to start with the "cin" and "cout" operators. 8. Verify sample output by providing corresponding sample hand calculations. 9. Make sure that your code complies with the C++ coding standards. 10.Submit the binary.cpp, binary-sandbox.cpp, and binary.h Specification

Explanation / Answer

The below program satisfies the given requirement as follows:-

---------------------------------------------------------------------------------

#include<iostream>

using namespace std;

int BinToDec(int num);

int DecToBin(int dec);

int main()

{

long num1, num2, sum;

cout << "Enter the two decimal numbers to add";

cin >> num1;

cin >> num2;

sum=DecToBin(BinToDec(num1)+BinToDec(num2));

cout << "The sum of two Binary numbers is " << sum << endl;

}

int BinToDec(int num) //code to convert Binary to decimal

{

long bin, dec = 0, rem, num, base = 1;

bin = num;

while (num > 0) //using while loop to convert binary number to decimal

{

rem = num % 10;

dec = dec + rem * base;

base = base * 2;

num = num / 10;

}

return dec;

}

int DecToBin(int dec) //code to convert Decimal to Binary

{

long dec,rem,i=1,bin=0;

do //using do-while loop to convert binary number to decimal

{

rem=dec%2;

bin=bin + (i*rem);

dec=dec/2;

i=i*10;

}while(dec>0);

return bin;

}

Output:-

---------

Enter the two decimal numbers to add

10101010

11001100

The sum of two Binary numbers is 0101110110