Question: The Problem Your assignment is to write a C++ program using Microsoft Visual Studio, Xcode, repl.it, or such other C++ compiler you wish. Start by

The Problem

Your assignment is to write a C++ program using Microsoft Visual Studio, Xcode, repl.it, or such other C++ compiler you wish.

Start by calculating the size in bits of your operands. (See the Notes section later in this document.) Then issue message 1 described later in this assignment. The C++ program should then display a menu and prompt the user for a menu choice. Use messages 2A through 2I below for that prompt. Invalid choice values should be rejected. Issue message 3 in this case, then prompt the user again for correct values. Repeat this until a valid choice is received. The valid operator choices are:

AND & OR | XOR ^ NOT ~ Negate - [Form negative number using twos complement] Left shift < (logical shift only) Right shift > (logical shift only) Stop execution = #

Once a valid choice is made, if the choice is '#', issue message 6 and end execution. Otherwise, ask the user for the operands using message 4A. (For the single-operand choices, NOT and Negate, issue message 4B.) In the case of left and right shift (< and >), verify that the shift amount is not larger than the number of bits in your operands. Issue message 8 if so and set the result to all zero bits.

Perform the requested transformation. Display the output using message 5.

Continue with the message display again.

Notes

Your program should use unsigned integers for the input variables and the result variable. Use of 64-bit variables is encouraged.

To calculate the bit size, use the C++ sizeof command and multiply the result by 8.

Use cin for all input. Should an input error arise, abandon all further calculations and issue an error message (message 7 in the list below).

Use iomanip to produce the hexadecimal output. The width should be two times the results of the sizeof result. Hexadecimal output must have leading zeroes.

Input

Input will be an operator chosen by the user from a menu, and one or two integer values. Your program will calculate the results for those two values.

Output

Output the resulting value from the specified logical operation. Issue error messages where required.

Output Message Text Values

Issue the following messages as shown below. Do not write different text or additional messages - this hinders automated grading and costs you points. If additional messages are needed, I will send an email to the class with those.

Message 1 - "Bitwise Operation Calculator - CS130 - nn bits - ffff llll" Replace ffff llll with your first and last name. Replace nn with the size in bits of your operands. Message 2A - "Enter one of the following choices:"

Message 2B - "& - AND" Message 2C - "| - OR" Message 2D - "^ - XOR" Message 2E - "~ - NOT" Message 2F - "- - Negate Message 2G - "< - Left shift (logical shift only)" Message 2H - "> - Right shift (logical shift only)" Message 2I - "# - stop execution" Message 3 - "Invalid choice x, please try again." Replace x with the user's choice.

Message 4A - "Enter values for first and second operand:"

Message 4B - "Enter value for operand:"

Message 5 - "Result: xxxxxxxx [Hexadecimal:yyyyyyyy] " Replace xxxxxxxx with the result in decimal and replace yyyyyyyy with the result in hexadecimal. Message 6 - "Calculation ended."

Message 7 - "Input error, enter choice and values again."

Message 8 - "Shift value xx exceeds bit size yy" Replace xx with the user's shift value input and replace yy with the word bit size.

HERE IS A SAMPLE

Bitwise Operation Calculator - CS130 - 64 bits - Sample Solution Enter one of the following choices: & - AND | - OR ^ - XOR ~ - NOT - - Negate < - Left shift (logical shift only) > - Right shift (logical shift only) # - stop execution ~ Enter value for operand: 4094 Result:-4095 [Hexadecimal:fffffffffffff001] Enter one of the following choices: & - AND | - OR ^ - XOR ~ - NOT - - Negate < - Left shift (logical shift only) > - Right shift (logical shift only) # - stop execution - Enter value for operand: 4094 Result:-4094 [Hexadecimal:fffffffffffff002] Enter one of the following choices: & - AND | - OR ^ - XOR ~ - NOT - - Negate < - Left shift (logical shift only) > - Right shift (logical shift only) # - stop execution # Calculation ended.

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!