Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

3.15 Program 3: A 1-Bit Boolean Calculator 1. Introduction in this assignment, you will work with C conditional statements to implement a simple Boolean calculator

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

3.15 Program 3: A 1-Bit Boolean Calculator 1. Introduction in this assignment, you will work with C conditional statements to implement a simple Boolean calculator program. This program will also introduce you to Boolean operators, which we will explore in much more detail later this semester Remember, in addition to submitting your code. you MUST complete the Blackboard assignment "Program 3 style assessment" to get all of the points for this program. You can complete this "assignment" by typing a short message indicating you submitted your code through the textbook IDE. Please see the test cases document for this assignment to view sample runs of the program Also, please note that develop mode now provides an interactive environment in which you can run your program. Interactive mode is a new beta feature for the zyBooks IDE, so please contact your instructor with any issues. 2. Specification Input Specification Your program should prompt the user to enter a simple Boolean expression of the form a op b, where a and bare 1-bit operands and op is one of the following operators: & (AND), (OR),^ (XOR). The prompt should read Enter Boolean expression: See the hints on Boolean operations described in this link for more details on these operators and their desired behavior. Example input expressions include the following (remember, your program must print the prompt "Enter Boolean expression:" and then read the user input that follows) Enter Boolean expression: 1.1 Enter Boolean expression: 0 1 0 Enter Boolean expression: 1*.0 All numeric input values should be treated as unsigned integers, which are read or printed using the scanf(/printf() format specifier u. The operator must be read using a different format Output Specification In addition to printing the prompt shown above, given a valid expression, your program should calculate the result and reprint the entire expression as well as its result. For example, the expressions listed above will produce the following output 1611 0 1 0 - 0 NOTE: Your program should not print the result next section for details on possible input errors. ir program should not print the result of an expression if any error occurs. See the See the program test cases for more sample program runs. Error Checking Tour program should print a descriptive error message under any of the conditions below. For examples of valid error messages, see the built-in program test cases 1. Any of the inputs are incorrectly formatted and therefore cannot be read correctly using scant Your error message should include the number of input values that were entered correctly-for example: Error: 2 values entered correctly I've gotten some feedback that says the error message is poorly worded--it should indicate the number of incorrect values, por correct ones, or say "only 2 values entered correctly." While I do understand that point, we're going to have to stick with this message, as some people have already submitted the program. scanf() returns the number of values correctly read, which you can store in a variable to test later. Say you have the following line of code: nVals - scanf("d 8d 8d", avi, &v2, &v3); 2. If the user enters: 0 1 2 3 ->nVals == 3 12 ->nVals ==2('a' is not part of a valid int) 1.2 2 3 -> nVals - I('.' is not part of a valid int, but 1 is read correctly) X1 2 3 -> n Vals == 0 ('X' is not part of a valid int) 3. Either (or both) of the operands cannot be represented as a single bit (0 and I are the only valid 1-bit values) Your error message should print the invalid input(s) --for example: Error: first input (3) requires > 1 bit 4. The operator entered is not a valid operator Your error message should print the invalid operator-for example: Error: invalid operator X NOTE: If the inputs are correctly formatted (ie, scant "puts are correctly formatted Gie. scant can read all input values), then your y generate multiple error messages! For example, if the user enters the expression> X4, then your program should print: Error first input (3) requires > I bit EREOTI Second input 4 equires > bit Error: invalid operator X If scan ) Seant cannot read all innut values wu r m should only print the error message related to a formatting error For example if the user enters the expression x3, then your program should print Error: 0 values entered correctly 3. Hints Using bitwise operators The &, and symbols aren't operators just designed for this program they're valid, built-in operators in C. You can use them in an expression just as you can use arithmetic operators (t. *. You don't need to write conditional statements to basically implement the truth tables shown later in this section For example, assume your input variables are called in and in2, you know the user entered the & operator, and you want to assign the result of that operation to a variable called result. An inefficient way to handle this operation is through if statements the code below is an example of what NOT to do: if (inl == 011in2 = 0) result = 0; else if (int - 1 && in2 == 1) result - 1) The following simple statement produces the exact same result: result = ini 6 in2; Unsigned values Since both input values should only be 0 or 1, you can represent these values using unsigned integers (data type unsigned int or simply unsigned). Unsigned values are strictly non- negative (0 or positive). The format specifier used to read and print unsigned values ist. The example code snippet below demonstrates the use of this format specifier-it declares two unsigned integers, prompts for and reads their values, and then prints those values to the screen unsigned x,y; printf("Enter two values: "); scanf("$u $u", 6X, &y); printf("x = fu, y = Bu ", X, Y); Using iflelse if vs. multiple if statements Remember in an if/else if statement, only one of the cases is executed, even if multiple conditions are true. For example, in the code below, only the first assignment statement ( + 3) will be executed, even though the first two conditions are both true: 2 int x = 1; int y = 2; if (x == 1) z = z + 3; else if (y - 2) 2 - 2 - 10; If you want both assignment statements that change z to be executed, use multiple if statements without the else: int x = 1; int y = 2; if (x == 1) z = 2 + 3; if (y == 2) 2 - 2 - 10; 4. Grading Rubric For this assignment, points are assigned as follows: 10 points: Your code uses appropriate coding style such as including appropriate comments, indenting the main function body, and appropriate variable declarations You must complete the Blackboard assignment Program 3 style assessment" to earn any of these points. 60 points: Your code compiles and output matches the desired test outputs shown below Each test case has a different number of points assigned to it, as shown in submit mode This section will be auto-graded, while I will assign the other 40 points after inspecting your program. LAB ACTIVITY 3.15.1: Program 3: A 1-Bit Boolean Calculator 0/60 prog3_boolean.c Safari File Edit View History Bookmarks Develop Window Help S 50% O Sat 6:12 PM Nyna a E h mjgeiger.github.io Programming assignments - EECE 2160... EECE 2160: ECE Application Programming mjgeiger.github.io/eece 2160/programs... 3.15 Program 3: A 1-Bit Boolean Calcu... Top Sites = zyBooks Test Cases The results of three full program runs are shown below, with user inputs underlined. Remember, when running the program in submit mode in zyBooks, user inputs are not shown. Studi This youri bottoi TEST CASE 1 Enter Boolean expression: 1&O 1 & 0 = 0 TEST CASE 2 Enter Boolean expression: 0 A 1 O * 1 = 1 Studi Secti Prog TEST CASE 3 Enter Boolean expression: 1 10 = 1 0 TEST CASE 4 Enter Boolean expression: 1 x Error: 2 values entered correctly 3.15 Prog TEST CASE 5 Enter Boolean expression: 4 + 1 Error: first input (4) requires > 1 bit Error: invalid operator + 1. Introduction In this assignment, program will also in TEST CASE 6 Enter Boolean expression: 3 x 2 Error: first input (3) requires > 1 bit Error: second input (2) requires > 1 bit Error: invalid operator x Remember, in addit assessment" to ge indicating you subr Please see the test Notes: You MUST CC program. You the textbook IVL

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

Microsoft Visual Basic 2005 For Windows Mobile Web Office And Database Applications Comprehensive

Authors: Gary B. Shelly, Thomas J. Cashman, Corinne Hoisington

1st Edition

0619254823, 978-0619254827

More Books

Students also viewed these Databases questions