Warning: foreach() argument must be of type array|object, bool given in /var/www/html/web/app/themes/studypress-core-theme/template-parts/header/mobile-offcanvas.php on line 20

Problem 1

Mark the following statements as true or false. a. The result of a logical expression cannot be assigned to an int variable. b. In a one-way selection, if a semicolon is placed after the expression in an if statement, the expression in the if statement is always true. c. Every if statement must have a corresponding else. d. The expression in the if statement: if \(\quad(\text { score }=30)\) grade \(=' \mathrm{A}^{\prime}\) always evaluates to true. e. The expression: \((\mathrm{ch}>=\text { 'A ' } \& \& \mathrm{ch}<=\text { ' } \mathrm{Z}\) ') f. Suppose the input is \(5 .\) The output of the code: cin \(>>\) num; if \((\text { num }>5)\) cout \(<<\) num \(;\) num \(=0\); else cout \(<<\) "Num is zero" \(<<\) endl is: Num is zero g. The expression in a switch statement should evaluate to a value of the simple data type. h. The expression ! \((x>0)\) is true only if \(x\) is a negative number. i. \(\quad\) In \(C++,\) both \(!\) and \(!=\) are logical operators. j. The order in which statements execute in a program is called the flow of control.

Problem 3

Suppose that \(x, y,\) and \(z\) are int variables, and \(x=10, y=15,\) and \(z=20\) Determine whether the following expressions evaluate to true or false. a. \(\quad !(x>10)\) b. \(x<=5 | 1 \quad y<15\) \(\begin{array}{llllll}\text { c. } & \langle x & !=5) & \& \& \quad(y \quad !=z)\end{array}\) \(\begin{array}{ll}\text { d. } \quad x>=z & || \quad(x+y>=z)\end{array}\) e. \(\quad(x=z) \quad|| \quad(z-2 \quad !=20)\)

Problem 4

Suppose that str1, str2, and str3 are string variables, and str1 \(=\) "English", str2 = "Computer Science", and str3 = "Programming". Evaluate the following expressions. a. \(\quad \operatorname{str} 1>=\operatorname{str} 2\) b. \(\quad\) str1 \(\quad !=\) "english" c. \(\operatorname{str} 3<\operatorname{str} 2\) d. \(\quad\) str \(2 \quad>=\) "Chemistry"

Problem 8

Write \(\mathrm{C}++\) statements that output Male if the gender is \(' \mathrm{M}\) ', Female if the gender is ' \(\mathrm{F}^{\prime},\) and invalid gender otherwise.

Problem 11

Suppose that sale and bonus are double variables. Write an if....else statement that assigns a value to bonus as follows: If sale is greater than \(\$ 20,000,\) the value assigned to bonus is \(0.10 ;\) If sale is greater than \(\$ 10,000\) and less than or equal to \(\$ 20,000,\) the value assigned to bonus is \(0.05 ;\) otherwise, the value assigned to bonus is 0

Problem 12

Suppose that overspeed and fine are double variables. Assign the value to fine as follows: If \(0<\) overspeed \(<=5,\) the value assigned to fine is \(\$ 20.00 ;\) if \(5<\) overspeed \(<=10,\) the value assigned to fine is \(\$ 75.00\) if \(10<\) overspeed \(<=15,\) the value assigned to fine is \(\$ 150.00 ;\) if overspeed \(>15,\) the value assigned to fine is \(\$ 150.00\) plus \(\$ 20.00\) per mile over 15

Problem 13

Suppose that score is an int variable. Consider the following if statements: if (score > = 90) ; cout \(<<\) "Discount \(=10\) \&" \(<<\) endl a. What is the output if the value of score is 95 ? Justify your answer. b. What is the output if the value of score is \(85 ?\) Justify your answer.

Problem 14

Suppose that score is an int variable. Consider the following if statements: i. if (score = \(=70\) ) cout \(<<\) "Grade is \(\mathrm{C}\). " \(<<\) endl ii. if (score \(=70\) ) cout \(<<\) "Grade is \(\mathrm{C}\). " \(<<\) endl

Problem 16

Rewrite the following expressions using an if...else statement. (Assume that all variables are declared properly.) a. \(\quad(x<5) ? \quad y=10: y=20\) b. \((\text { fuel }>=10)\) ? drive \(=150:\) drive \(=30\) c. (booksBought \(>=3\) ) ? discount \(=0.15\) : discount \(=0.0\)

Problem 17

Suppose that you have the following conditional expression. (Assume that all the variables are properly declared.) \((0<\text { backyard } \& \& \text { backyard }<=5000)\) ? fertilizingCharges \(=40.00\) \(: \text { fertilizingCharges }=40.00+\text { (backyard }-5000) \star 0.01\) a. What is the value of fertilizingCharges if the value of backyard is \(3000 ?\) b. What is the value of fertilizingCharges if the value of backyard is \(5000 ?\) c. What is the value of fertilizingCharges if the value of backyard is \(6500 ?\)

Access millions of textbook solutions in one place

  • Access over 3 million high quality textbook solutions
  • Access our popular flashcard, quiz, mock-exam and notes features
  • Access our smart AI features to upgrade your learning
Get Vaia Premium now
Access millions of textbook solutions in one place

Recommended explanations on Computer Science Textbooks