Question: // NOTE: The ONLY files that should be #included for this assignment are iostream, vector, and string // No other files should be #included #include

// NOTE: The ONLY files that should be #included for this assignment are iostream, vector, and string

// No other files should be #included

#include

#include

#include

// NOTE: The ONLY files that should be #included for this assignment are iostream, vector, and string

// No other files should be #included

using namespace std;

string addbin(string, string);

string addhex(string, string);

string multbin(string, string);

string multhex(string, string);

int main()

{

cout

cout

cout

cout

cout

cout

cout

cout

cout

cout

cout

cout

system("PAUSE");

return 0;

}

string addbin(string bin1, string bin2)

{

//This function is from a previous assignment

string bin_result = ""; int s = 0; int i = bin1.size() - 1, j = bin2.size() - 1; while (i >= 0 || j >= 0 || s == 1) { s += ((i >= 0)? bin1[i] - '0': 0); s += ((j >= 0)? bin2[j] - '0': 0); bin_result = char(s % 2 + '0') + bin_result; s /= 2; i--; j--; } return bin_result;

}

string addhex(string hex1, string hex2)

{

//This function is from a previous assignment

if (hex1.length()

int length1, length2; length1 = hex1.length(); length2 = hex2.length(); int flag = 0; // carry int get_hex1, get_hex2; int sum;

while (length1 > 0) {

if (hex1 [length1 - 1] >= 'A') get_hex1 = hex1[length1 - 1] - 55; else get_hex1 = hex1[length1 - 1] - '0';

if (length2 > 0) { if (hex2[length2 - 1] >= 'A') get_hex2 = hex2[length2 - 1] - 55; else get_hex2 = hex2[length2 - 1] - '0'; }

else get_hex2 = 0;

//get the sum sum = get_hex1 + get_hex2 + flag;

if (sum >= 16) { int left = sum % 16; if (left >= 10) hex1[length1 - 1] = 'A' + left % 10; else hex1[length1 - 1] = '0' + left; flag = 1; } else { if (sum >= 10) hex1[length1 - 1] = 'A' + sum % 10; else hex1[length1 - 1] = '0' + sum; flag = 0; }

length1--; length2--; }

if (flag == 1) return "1" + hex1; else

return hex1;

}

string multbin(string bin1, string bin2)

{

// IMPLEMENT THIS FUNCTION

// IMPLEMENT THIS FUNCTION

// IMPLEMENT THIS FUNCTION

}

string multhex(string hex1, string hex2)

{

// IMPLEMENT THIS FUNCTION

// IMPLEMENT THIS FUNCTION

// IMPLEMENT THIS FUNCTION

}

// NOTE: The ONLY files that should be #included for this assignment

are iostream, vector, and string // No other files should be #included

#include #include #include // NOTE: The ONLY files that should be #included

strin rmulihinksaring, saring) // multiplies two binary numbers together and returns the product string multhex(string, string); // multiplies two hexadecimal numbers together and returns the product NOTE: Like the previous two assignments, everything should be considered arn UNsigned number, so you don't have to handle negative numbers Base Cases: In both of your two multiplication functions you have two base cases. A base case is a special case where you can immediately return the product without having to go through the multiplication algorithm (described below). The two base cases are: 1) One or both of the binary/hexadecimal numbers are 0. In this case, you can immediately return O as the product. 2) One or both of the binary/hexadecimal numbers are 1. When you detedt that one of the numbers is 1, you can immediately return the other number as the product. For example, if hex1 00AF, and hex2 0001, then immediately returned as the product. the value of hex1 (00AF) would te

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!