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

Write a C++ program that shows the menu below. User can select an item by insert

ID: 3703898 • Letter: W

Question


Write a C++ program that shows the menu below. User can select an item by inserting an integer. The program should show the menu again after each iteration and it should exit only if user selects item number 6 *The computer system for this assignment is an eight-bit cell. Menu: 1- Convert an unsigned binary number to a decimal 2- Convert a positive decimal number to unsigned binary 3- Convert a signed binary number in sign-bit representation to decimal 4- Convert a decimal number to a binary number in sign-bit representation 5- Convert a decimal number to binary number in two's complement representation 6- Exit If the number is not specified to be positive, you should consider positive, negative and zero values. If it is specified to be positive, zero should be considered as well. Sign-bit representation is the representation of a binary number where the leftmost bit is the sign bit and the rest are magnitude If the number is out of the range of the presentation, program should show "overflow" message and show the menu for more selection.

Explanation / Answer


#include <iostream>
#include<math.h>
#include<string.h>
#include<string>
using namespace std;
int SignedDecimalToBinary()
{
long decimal = 1;
long remainder = 1;
long i = 1;
long sum = 0;
cout << "Enter Decimal Number: " << endl;
cout << "Decimal: "<< endl;
cin >> decimal;
do
{
//Conversion to Signed Binary.
remainder = decimal %2;
sum = sum + (i * remainder);
decimal = decimal / 2;
i = i * 10;
}while (decimal < 0 || decimal > 0); //Less Than 0 to Make Value Signed.
cout << "Binary: " << sum << endl << endl;
return 0;
}
int binary_decimal(int n) //Function For Signed Binary to Decimal.
{
int decimal = 0, i = 0, remainder;
//Two's Compliment.
//n = ~n + 1;
//Conversion to Decimal.
while (n != 0)
{
remainder = n % 10;
n /= 10;
decimal += remainder * pow(2,i);
++i;
}
return decimal;
}
int SignedBinaryToDecimal()
{
int binary_decimal(int n);
int n;
cout << "Enter Binary Number: ";
cin >> n;
cout << "In Decimal: " << n << " = " << binary_decimal(n) << endl;
return 0;
}
int convertBinaryToDecimal()
{
long n;
cin>> n;
int decimalNumber = 0, i = 0, remainder;
while (n!=0)
{
remainder = n%10;
n /= 10;
decimalNumber += remainder*pow(2,i);
++i;
}
cout << "In Decimal: " << n << " = " << decimalNumber << endl;
return 0;
}
long convertDecimalToBinary()
{
int n;
cin >> n;
long long binaryNumber = 0;
int remainder, i = 1, step = 1;
while (n!=0)
{
remainder = n%2;
cout << "Step " << step++ << ": " << n << "/2, Remainder = " << remainder << ", Quotient = " << n/2 << endl;
n /= 2;
binaryNumber += remainder*i;
i *= 10;
}
cout << "In Binary: " << n << " = " << binaryNumber << endl;
return 0;
}
int DecimalToTwocomplement(){
long decimal = 1;
long remainder = 1;
long i = 1;
long sum = 0;
cout << "Enter Decimal Number: " << endl;
cout << "Decimal: "<< endl;
cin >> decimal;
do
{
//Conversion to Signed Binary.
remainder = decimal %2;
sum = sum + (i * remainder);
decimal = decimal / 2;
i = i * 10;
}while (decimal < 0 || decimal > 0); //Less Than 0 to Make Value Signed.
cout << "Binary: " << sum << endl << endl;
return 0;
}
int main()
{
cout << "1: convertBinaryToDecimal"<< endl;
cout << "2: convertDecimalToBinary"<< endl;
cout << "3: SignedDecimalToBinary"<< endl;
cout << "4: SignedBinaryToDecimal"<< endl;
cout << "5: DecimalToTwocomplement" << endl;
cout << "6: Exit"<< endl;
int input;
while(1>0){
cout << "Enter the Options:" << endl;
cin >> input;
if(input==1){
convertBinaryToDecimal();
continue;
}
if(input==2){
convertDecimalToBinary();
continue;
}
if(input==3){
SignedBinaryToDecimal();
continue;
}
if(input==4){
SignedDecimalToBinary();
continue;
}
if(input==5){
DecimalToTwocomplement();
continue;
}
if(input==6){
cout<< "bye" << endl;
break;
}
}
return 0;
}
Please find the code above

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote