Consider the following if statement, where doesSignificantWork, makesBreakthrough, and nobelPrizeCandidate are all boolean variables: if doesSignificantWork : if makesBreakthrough : nobelPrizeCandidate = True else nobelPrizeCandidate = False elif not doesSignificantWork: nobelPrizeCandidate = False (assume that doesSignificantWork and makesBreakthrough have been initialized, there is no error) First, write a simpler if statement that is equivalent to this one. Then write a single assignment statement that does the same thing. (Hint: Try to trace this piece of code with all possible initial values for makesBreakthrough and doesSignificantWork. It helps you to understand the code and then you can simplify it and rewrite it).
Firstly, if else equivalent:
if(doesSignificantWork) {
if(makesBreakthrough) {
noblePrizeCandidate=true; }
else {
nobelPrizeCandidate=false; }
}
else if( ! doesSignificantWork) {
noblePrizeCandidate=false; }
Now coming to single statement we can use ternary operators in below format:
For eg : variable = condition ? expression1 : expression2;
Using above format
noblePrizeCandidate= doesSignificantWork ? ( makesBreakThrough ? true : false) : false ;
Consider the following if statement, where doesSignificantWork, makesBreakthrough, and nobelPrizeCandidate are all boolean variables: if doesSignificantWork...
Assume x and y are boolean variables that were declared and initialized correctly. Regardless of the initial values for x and y, which Java statement is logically equivalent to all of the Java source code below? boolean z = false; if (!x) N = true; else if (x && Y) Z = true; = !x || Y; N = x || ! (x && y); N z !X && (x && y); = !x && Y; N none of the...
4. Consider the following statement: “The product of an even integer with any integer is always even.” (a) Rewrite the statement in the form “for all ... , if ... , then ..." using symbols to represent variables. (b) Write the negation of the statement, again using symbols. (c) Prove the statement if you think it is true or disprove it if you think it is false.
Write a c++ expression representing the following algebraic expression. Assume that all variables in your program are of the type double and that your program has already included the <cmath> header file. 3x + 1/y - 10 + Squareroot g Your answer: (b) Rewrite the same expression assuming that variables x and y in your program are of type int your answer: Convert the following switch statement into an equivalent if-else if statement switch (ch) {case 'A'; cout << "...
EXERCISES: if & if...else STATEMENTS: Name Examples of if and if-else statements: Write an if statement that multiplies payRate by 1.5 iſ hours is greater than 40. Write variable declarations for the variables payRate and hours first. Hint: Look for keyword if first, your boolean comes after the keyword [. This translates into Java as: double hours, payRate; if (hours > 40) { //{-} are optional here but I recommend that you them payRate = payRate 1.5; pay Rato pay...
QUESTION 4 Consider the following block of Python code, where variables age_1, age_2 and age_3 each store integer values: if age_1 > age_2: if age_2 > age_3: print(age_3) else: print(age_2) elif age_1 > age_3: print(age_3) else: print(age_1) Which of the following options best describes the purpose of the above code? To print the largest of the values stored in age_1, age_2 and age_3 To print the largest of the values stored in age_1 and age_2 only To print the largest...
Given the following Bayesian network, where all random variables have Boolean values (true or false), compute the probability of D being true, given that A is true. That is, compute P(D-true |A-true) AP(A) 0.7 P(B IA) 0.2 P(B 1-A)-0.5 P(C I A)-0.7 PCI-A)-0.25 P(D IBAC)-0.3 P(D I-BAC)-0.1
Given the following Bayesian network, where all random variables have Boolean values (true or false), compute the probability of D being true, given that A is true. That is, compute P(D-true |A-true) AP(A)...
Module 6 - Cash Register (10 Points) We are going to write a program that simulates a customer's transaction at a cash register. You will organize your code using functions. Each of the functions below counts for 2 points. You must create functions allowing the user to: 1. Add an item to the order. No name or list of items is needed simply prompt the user for a dollar amount to add. 2. Clear all transactions. Set the amount of...
Need some guidance with the following problems as I am new to Java programming. Any assistance is greatly appreciated. Thanks Using printf and specifiers for all print instructions: 1. Code the following: a. 10% is stored in a variable called discount when the customer is a student; otherwise, it stores 0%. Code this if … else control structure using the conditional operator (ternary operator). The variables discount and student have already been declared. Assume student is a boolean variable. b. ...
1. Assume you have a Car class that declares two private instance variables, make and model. Write Java code that implements a two-parameter constructor that instantiates a Car object and initializes both of its instance variables. 2. Logically, the make and model attributes of each Car object should not change in the life of that object. a. Write Java code that declares constant make and model attributes that cannot be changed after they are initialized by a constructor. Configure your...
2) Write an assembly program that is algorithmically equivalent to the following C+t code Consider the variables to be 8-bit unsigned integers; you may initialize them to any values 0-255 if you like for testing purposes 13 int speed, lower, a, b; 14 15 if (speed < 98) { 16 17 if (speed <80) t 18 lower++; 19 20 21 else f 23 24 25 26 else t 27 28
2) Write an assembly program that is algorithmically equivalent to...