Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

using c++ Problem 2. Binary calculator Write a program that prompts the user to enter a calculation expression involving two integers in the binary format

image text in transcribedimage text in transcribed

using c++

Problem 2. Binary calculator Write a program 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 user's 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: +,-M/%. 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 calcbindata string xli string x2; char opi i . Implement a function calc bin data calcparsing (const string& S) that parses the users input provided in the string s. The function must return a variable of type calcbin.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 . 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 tring"-100" . Use the above functions to write a program that prompts a user to enter a "calculation" ex pression involving two integers in the binary format and the operator +,-, *, /, or %. Unlike in the previous homework 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 user's input is always valid. Problem 2. Binary calculator Write a program 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 user's 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: +,-M/%. 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 calcbindata string xli string x2; char opi i . Implement a function calc bin data calcparsing (const string& S) that parses the users input provided in the string s. The function must return a variable of type calcbin.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 . 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 tring"-100" . Use the above functions to write a program that prompts a user to enter a "calculation" ex pression involving two integers in the binary format and the operator +,-, *, /, or %. Unlike in the previous homework 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 user's input is always valid

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

What is the purpose of an employee stock ownership plan (ESOP)?

Answered: 1 week ago