Question: Write a program in C++ that prompts the user to enter a calculation expression involving two integers in the binary format and the operator +,

Write a program in C++ that prompts the user to enter a calculation expression involving two integers in the binary format and the operator +, ?, ?, /, or % and then displays the result of the calculation. See the instructions for details.

Instructions:

Input: The users input is a string containing a calculation in the following format (first number)operator(second number). Here, the first number and the second one are integers in the binary format, not exceeding the range of type int, and the operator is one of the following operators: +,?,?,/,%. For example, a legitimate input could be (101)+(100) or (101)/(10). The operator / is assumed to be an integer division operator.

Declare the data structure: struct calc bin data{ string x1; string x2; char op; };

Implement a function calc bin data calc parsing(const string & s) that parses the users input provided in the string s. The function must return a variable of type calc bin data in which x1 is a string containing the first number in the input, x2 is a string containing the second number, and op contains a character corresponding to the operator.

Implement a function int convert binary to decimal(const string & s) that converts a string containing an integer (in the binary format) into an integer of type int. For instance, the string s="101" should be converted into the integer 5, and s="-100" into the integer -4.

Implement a function string convert decimal to binary(int n) that converts an integer of type int into a string containing an integer in the binary format. For instance, the integer n=5 should be converted into the string "101", and the integer n=-4 into the string "-100".

Use the above functions to write a program that prompts a user to enter a calculation expression involving two integers in the binary format and the operator +, ?, ?, /, or %. The zeros in the representation should be dropped in the process of conversion. The program must display the result of the calculation in both binary format and the decimal one; see the input-output sample.

You can assume that the the users input is always valid.

Implement a loop in which the above actions are repeated until the user requests to quit.

See sample input-output below:

Write a program in C++ that prompts the user to enter a

calculation expression involving two integers in the binary format and the operator

C:Windowslsystem321cmd.exe Enter an expression in binary format>: +11> > in binary represenation: 101 11-1000 -> in decimal represenation: > in binary represenation -11)-10 > in decimal represenation: -(3)-2 Continue? Enter an expression in binary format>1000/11> > in binary represenation: 100/11)-10 > in decinal represenation: y expression binary decimal represenation: > repre s e nation: Continue? Cy> y Enter an expression > in binary represenation: ?101), y Enter an expression Kin binary format>: > in binary represenation: 10*111-1110 > in dec inal represenation: in binary represenation K10)-1111-1101 ? in decinal repre s e nation: ?2)-(15):-13 ntinue? n Press any key to continue

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!