question archive C++ 3 non member function computeUnsignedBinary computeSignAndMagnitudeBinary computeTwosComplementBinary I want to know the algorithms Please comment out the no need function and some in main program Each of these functions takes an integer value and bit pattern size arguments and needs to return a LinkedList object with as many nodes as the bit pattern size and whose data store the binary representation of the integer value argument in the required information representation as indicated by the function name
Subject:Computer SciencePrice: Bought3
C++ 3 non member function
computeUnsignedBinary
computeSignAndMagnitudeBinary
computeTwosComplementBinary
I want to know the algorithms
Please comment out the no need function and some in main program
Each of these functions takes an integer value and bit pattern size arguments and needs to return a LinkedList object with as many nodes as the bit pattern size and whose data store the binary representation of the integer value argument in the required information representation as indicated by the function name. Please note that any overflow bit during your computations must be ignored. For example when you represent a given non-negative integer number in unsigned binary representation say for example in 5 bit but then the integer number requires more than 5 bits to represent it correctly, then only 5 bits should be stored in the linked list and the remaining over flow bits must be ignored. Similarly any overflow bit during arithmetic in two's complement representation must be ignored.
Sample Run Outputs This program demonstrates the Linked List Data Structure in C++ Linked Lists will be used for numeric information representation using *** Unsigned Binary Representation *** Sign and Magnitude Binary Representation '4'" Two's Complement Binary Representation In addition, the program demonstrates *** Two's complement binary addition, and *** Conversion from two's complement to decimal. Select your computation 1. Unsigned Binary Representation Computation 2. Sign and Magnitude Representation Computation 3. Two's Complement Representation Computation 4. Exit Program Enter your selection [1, 2, 3, or 4}: 1 Enter a positive integer for the bit pattern size: 6 Enter a non—negative integer: 45 The unsigned binary representation of 45 in 5 bit is 131181 Press any key to continue . Select your computation 1. Unsigned Binary Representation Computation 2. Sign and Magnitude Representation Computation 3. Two's Complement Representation Computation 4. Exit Program Enter your selection [1, 2, 3, or 4}: 1 Enter a positive integer for the bit pattern size: 4 Enter a non-negative integer: 15 The unsigned binary representation of 15 in 4 bit is 1111 Press any key to continue . Select your computation 1. Unsigned Binary Representation Computation 2. Sign and Magnitude Representation Computation 3. Two's Complement Representation Computation 4. Exit Program Enter your selection {1, 2, 3, or 4}: 1 Enter a positive integer for the bit pattern size: 8 Enter a non-negative integer: 3?3 The unsigned binary representation of S?3 in B bit is 61113161 Press any key to continue .
#include <iostream>
using namespace std;
class Node
{
typedef Node* NodePtr;
private:
int data;
NodePtr link;
public:
Node();
Node(const int &);
Node(const Node &);
int getData() const;
NodePtr getLink() const;
void setData(const int &);
void setLink(const NodePtr &);
friend ostream& operator << (ostream &, const Node &);
};
typedef Node* NodePtr;
Node::Node() : data(0), link(nullptr) {}
Node::Node(const int &d) : data(d), link(nullptr){}
Node::Node(const Node &n) : data(n.data), link(n.link){}
int Node::getData() const { return data; }
NodePtr Node::getLink() const { return link; }
void Node::setData(const int &d) { data = d; }
void Node::setLink(const NodePtr &p) { link = p; }
ostream& operator << (ostream& out, const Node& n)
{
out << n.data;
return out;
}
typedef Node* NodePtr;
class LinkedList
{
private:
NodePtr head;
public:
LinkedList();
LinkedList(const LinkedList &); //copy constructor (deep copy)
~LinkedList(); //destructor (must delete all the nodes from the heap)
LinkedList& operator= (const LinkedList &); //Assignment operator (deep copy)
int getLength() const; //return the number of nodes in the linked list
void head_insert(const int &);
NodePtr search_node(const int &) const;
void insert_after(const NodePtr &, const int &) const;
void remove_node(const NodePtr &);
void remove_node(const int &);
void remove_all(const int &);
void tail_insert(const int &);
void insert_before(const NodePtr &, const int &);
friend ostream& operator << (ostream&, const LinkedList &);
//Assignment specific member functions
void flipBits() const;
void reverseBits() const;
LinkedList operator + (const LinkedList &) const;
void addOne() const;
int twosComplementToDecimal() const;
};
int selectComputation()
{
cout << "Select your computation" << endl;
cout << " 1. Unsigned Binary Representation Computation" << endl;
cout << " 2. Sign and Magnitude Representation Computation" << endl;
cout << " 3. Two's Complement Representation Computation" << endl;
cout << " 4. Exit Program" << endl;
int selection;
cout << "Enter your selection (1, 2, 3, or 4): ";
cin >> selection;
while (selection != 1 && selection != 2 && selection != 3 && selection != 4)
{
cout << "Please enter a correct choice: ";
cin >> selection;
}
return selection;
}
int main()
{
cout << "This program demonstrates the Linked List Data Structure in C++" << endl;
cout << "Linked Lists will be used for numeric information representation using" << endl;
cout << " *** Unsigned Binary Representation" << endl;
cout << " *** Sign and Magnitude Binary Representation" << endl;
cout << " *** Two's Complement Binary Representation" << endl << endl;
cout << "In addition, the program demonstrates" << endl;
cout << " *** Two's complement binary addition, and" << endl;
cout << " *** Conversion from two's complement to decimal." << endl << endl;
do
{
int selection = selectComputation();
if (selection == 1)
{
int bit_pattern_size, num;
cout << endl << "Enter a positive integer for the bit pattern size: ";
cin >> bit_pattern_size;
while (bit_pattern_size <= 0)
{
cout << "You must enter a positive integer. Enter again please: ";
cin >> bit_pattern_size;
}
cout << "Enter a non-negative integer: ";
cin >> num;
while (num < 0)
{
cout << "You must enter a non-negative integer. Enter again please: ";
cin >> num;
}
LinkedList LL = computeUnsignedBinary(num, bit_pattern_size);
cout << "The unsigned binary representation of " << num << " in " << bit_pattern_size << " bit is " << LL << endl;
cout << endl;
}
else if (selection == 2)
{
int bit_pattern_size, num;
cout << endl << "Enter a positive integer for the bit pattern size: ";
cin >> bit_pattern_size;
while (bit_pattern_size <= 0)
{
cout << "You must enter a positive integer. Enter again please: ";
cin >> bit_pattern_size;
}
cout << "Enter an integer: ";
cin >> num;
LinkedList LL = computeSignAndMagnitudeBinary(num, bit_pattern_size);
cout << "The sign and magnitude binary representation of " << num << " in " << bit_pattern_size << " bit is " << LL << endl;
cout << endl;
}
else if (selection == 3)
{
int bit_pattern_size, num1, num2;
cout << endl << "Enter a positive integer for the bit pattern size: ";
cin >> bit_pattern_size;
while (bit_pattern_size <= 0)
{
cout << "You must enter a positive integer. Enter again please: ";
cin >> bit_pattern_size;
}
cout << "Enter an integer: ";
cin >> num1;
LinkedList LL1 = computeTwosComplementBinary(num1, bit_pattern_size);
cout << "The two's complement binary representation of " << num1 << " in " << bit_pattern_size << " bit is " << LL1 << endl;
cout << endl;
cout << "Enter a second integer: ";
cin >> num2;
LinkedList LL2 = computeTwosComplementBinary(num2, bit_pattern_size);
cout << "The two's complement binary representation of " << num2 << " in " << bit_pattern_size << " bit is " << LL2 << endl;
cout << endl;
LinkedList LL3 = LL1 + LL2;
cout << "The binary sum of " << LL1 << " and " << LL2 << " is " << LL3 << endl;
int sum = LL3.twosComplementToDecimal();
cout << "The integer value of the binary sum is " << sum << endl;
if (sum == num1 + num2)
cout << "This is a correct result." << endl;
else
cout << "This is not correct result because our bit pattern is too small to store the result." << endl;
}
else
break;
system("Pause");
cout << endl << endl;
}while (true);
system("Pause");
return 0;
}