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

PHASE #1-Description: Develop a code to and finally implement a set of functions

ID: 3698399 • Letter: P

Question

PHASE #1-Description: Develop a code to and finally implement a set of functions using C++ that would implement the IEHE standard Phase 1 will inchude the literature write up, description of the IEEE 754 single and a complete description of the fiunctions 1. Functions type void, or any data returning function 2. Type of data passed in to the functions (function parameters or aiguments) 3. Type of function parameters (value or reference) 4. Global variables if needed. 5. IEEE 754 single precision layout and its individual parts (sign, exponent, and mantissa) details. 6. The hexadecimal layout of both precision. Explain the code using descriptions and if possible try not to use "Bitset" SUGGESTED FUNCTIONS PLAN: MENU To display the user options... SPLITTER To split the number to whole and fraction WHOLECONVERTER Whole Part binary converter FRACTIONCONVERTER Fraction Part binary converter CONCATENATOR Concatenate STANDARDIZER Normalizes the binary mumber to standard form. DISPLAY Display the result

Explanation / Answer

#include <iostream>

#include <cmath>

using namespace std;

void showChoices();

void splitter();

void convertWholePartTobinary();

void convertFractionalPartTobinary();

double concatenator();

void standardizer();

double binaryToDecimal(string, int);

int main()

{

float x, y;

int choice;

do

{

showChoices();

cin >> choice;

switch (choice)

{

case 1:

splitter();

break;

case 2:

convertWholePartTobinary();

break;

case 3:

convertFractionalPartTobinary();

break;

case 4:

concatenator();

break;

case 5:

standardizer();

case 6:

break;

default:

cout << "Invalid input" << endl;

}

}while (choice != 6);

return 0;

}

void showChoices()

{

cout << "MENU" << endl;

cout << "1: Splitter " << endl;

cout << "2: Whole Converter" << endl;

cout << "3: Fraction Converter" << endl;

cout << "4: Concatenator " << endl;

cout << "5: Standardizer " << endl;

cout << "6: Exit " << endl;

cout << "Enter your choice :";

}

void splitter(){

  

float x;

cout<<" Enter the number:";

cin>>x;

int y=x;

float z=(x-y);

cout<<" Integer part :"<<y;

cout<<" Fractional part :"<<z <<endl<<endl;

}

void convertWholePartTobinary(){

  

float x;

int a[10], binaryInt = 0, i = 1;

cout<<" Enter the number:";

cin>>x;

int y=x;

float z=(x-y);

cout<<" Integer part :"<<y<<endl;

while(y>0)

{

binaryInt = binaryInt + y % 2 * i;

i = i * 10;

y = y / 2;

}

cout<<"Binary of the given number= "<<binaryInt<<endl<<endl;

}

void convertFractionalPartTobinary(){

  

float x;

float binaryFract = 0, k =0.1f, temp1;

int a[10], i;

cout<<" Enter the number:";

cin>>x;

int y=x;

float z=(x-y);

cout<<" Fractional part :"<<z <<endl;

  

while(k>0.00000001)

{

temp1 = z *2;

binaryFract = binaryFract+((int)temp1)*k;

z = temp1 - (int)temp1;

k = k / 10;

}

cout<<"Binary of the Fraction number= "<<binaryFract<<endl<<endl;

}

double concatenator(){

  

float x;

float binaryFract = 0, k =0.1f, temp1,binaryInt = 0;

int a[10], i=1;

double binaryNumber;

cout<<" Enter the number:";

cin>>x;

int y=x;

float z=(x-y);

cout<<" Integer part :"<<y<<endl;

cout<<" Fractional part :"<<z <<endl;

while(y>0)

{

binaryInt = binaryInt + y % 2 * i;

i = i * 10;

y = y / 2;

}

cout<<"Binary of the given number= "<<binaryInt<<endl;

while(k>0.00000001)

{

temp1 = z *2;

binaryFract = binaryFract+((int)temp1)*k;

z = temp1 - (int)temp1;

k = k / 10;

}

cout<<"Binary of the Fraction number= "<<binaryFract<<endl<<endl;

cout<<"Concating Converted binary numbers of "<<x<<" is = "<< binaryInt + binaryFract<<endl;

binaryNumber = binaryInt + binaryFract;

}

void standardizer(){

  

string n;

  

cout<<" Enter the binary number:";

cin.ignore();

getline(cin, n);

  

cout <<"Binary to decimal conversion for "<<n<<" is = " <<binaryToDecimal(n, n.length()) << " ";

}

double binaryToDecimal(string binary, int len)

{

// Fetch the radix point

size_t point = binary.find('.');

// Update point if not found

if (point == string::npos)

point = len;

double intDecimal = 0, fracDecimal = 0, twos = 1;

// Convert integral part of binary to decimal

// equivalent

for (int i = point-1; i>=0; --i)

{

// Subtract '0' to convert character

// into integer

intDecimal += (binary[i] - '0') * twos;

twos *= 2;

}

// Convert fractional part of binary to

// decimal equivalent

twos = 2;

for (int i = point+1; i < len; ++i)

{

fracDecimal += (binary[i] - '0') / twos;

twos *= 2.0;

}

// Add both integral and fractional part

return intDecimal + fracDecimal;

}