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 explore

image text in transcribed
image text in transcribed
image text in transcribed
image 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 explore in much more detail later this semester ator program. This program will also introduce you to Boolean operators, which we will 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 b are l-bit operands and on is one of the following operators: & (AND), I (OR),A (XOR). The prompt should read Enter Boolean expression: Y- 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 10 : 1 0 Enter Boolean expression All numeric input values should be treated as unsigned integers, which are read or printed using the scant 0/printt) format specifier su. 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: 010-0 NOTE: Your program should not print the result of an expression next section for details on possible input errors See the program test cases for more sample program runs. Error Checking if any error occurs. See the Your 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 Any of the inputs are incorrectly formatted and therefore cannot be read correctly using scanti 1. Your error message should include the number of input values that were entered correctly-for example: Error: 2 values entered correctly o I've gotten some feedhack that says the error message is poorly worded-it should indicate the mumber of incorrect values, not 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 corectly read, which you can store in a variable to test later. Say you have the following line of code: 2 If the user enters o 1 2 3nVals3 1 2 a-> nVals-2 ('a, s not part ofa valid int) 1 .2 2 3 .> nvals--I (' . , is not part of a valid int, but 1 s read correctly) x 1 0 2 3-> nvals == 0(X' s not part ofa valid int) Either (or both) of the operands cannot be represented as a single bit (0 and 1 are the only valid 1-bit values) 3. 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 inputs are correctly formatted Ge, scanf ) can read all input values), then program may generate multiple error messages! For ex ample, if the user enters the expression 3 'X 4, then your program should print: Error: tirst input (3) requires 1 bit Error: second input 14) requires > 1 bit Etror: invalid operator X If scanf() cannot read all input values, to a formatting error. For example, if the user ent should print Erxort 0 values entered correctly your program should only print the error message related ers the expression: x 3 4, then your program 3. Hints Using bitwise operators The &, |, and-4symbols 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 (+, - ,0 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 ini 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 (in1-011 in2+-o) - result0: result 1i resultinl in2 else if (inl 1 & in21 The following simple statement produces the exact same result Unsigned values Since both input values should only be O 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 is tu. The example code snippet example 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 ,yrints those values t declares two unsigned x, y: printf ("Enter two values: ") printf("x %u, y- 8u ", , y); Using iflelse if vs. multiple if statements Remember: in an it/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 (z +3) will be executed, even though the first two conditions are both true: - int x = 1; int y 2: if (x1) else if (y2) zz 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; zz+ 3; if (y-2) 2z10; 4. Grading Rubric For this assignment, points are assigned as follows 40 points: Your code uses appropriate coding style such as including appropriate comments, indenting the main0 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 ACTIMITY 3.15.1: Program 3: A 1-Bit Boolean Calculator 0/60 prog3 boolean.c

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

Advanced MySQL 8 Discover The Full Potential Of MySQL And Ensure High Performance Of Your Database

Authors: Eric Vanier ,Birju Shah ,Tejaswi Malepati

1st Edition

1788834445, 978-1788834445

More Books

Students also viewed these Databases questions

Question

=+ Have I left out anything in turning my outline into a draft?

Answered: 1 week ago

Question

6. Identify characteristics of whiteness.

Answered: 1 week ago

Question

9. Explain the relationship between identity and communication.

Answered: 1 week ago