Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ Assignment: Create a program which can maintain binary numbers, being able to add them, subtract them, as well as being able to convert them

C++

Assignment: Create a program which can maintain binary numbers, being able to add them, subtract them, as well as being able to convert them from binary to decimal, and decimal to binary. You'll need to use strings to represent binary numbers. So each character in the strings represents one digit. To keep the assignment from getting too complicated, you'll never need a number with more than SIX binary digits, so consider that the upper limit of how many 'char'variables you'll need in each binary class. Your code will need to perform the following tasks:

1. Convert 34 to Binary

2. Convert 22 to Binary

3. Convert 1001 to Decimal

4. Convert 111011 to Decimal

5. Add 11 and 1110 in Binary, Return the Answer in Binary

6. Subtract 111 from 1010 in Binary, then Convert the Answer to Decimal

A general reminder double-check your code's output to make it's correctly converting. And

although many compilers offer built-in Binary-to-Decimal/Decimal-to-Binary converters, PLEASE

DO NOT USE THESE BUILT IN CONVERTERS, as I will intentionally remove points for doing

so. Also, when adding binary numbers, PLEASE ADD THEM WHILE THEYRE STILL IN

BINARY FORM. I'll check to see if your program converts them to decimal, adds them, then

converts then back to binary.

Starting code:

// main.cpp

// Lab 03

#include

#include

using namespace std;

string binary_add(string a, string b)

{

string result;

// TO BE FINISHED

return result;

}

string binary_sub(string a, string b)

{

string result;

// TO BE FINISHED

return result;

}

int binary2int(string a)

{

int result=0;

// TO BE FINISHED

return result;

}

string int2binary(int b)

{

string result;

// TO BE FINISHED

return result;

}

int main(int argc, const char * argv[]) {

// insert code here...

string a = "1011";

string b = "111";

int c;

c = binary2int(a);

return 0;

}

.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Concepts of Database Management

Authors: Philip J. Pratt, Joseph J. Adamski

7th edition

978-1111825911, 1111825912, 978-1133684374, 1133684378, 978-111182591

More Books

Students also viewed these Databases questions