Chapter 4: Problem 22
include
Short Answer
Step by step solution
Key Concepts
These are the key concepts you need to understand to accurately answer the question.
Chapter 4: Problem 22
include
These are the key concepts you need to understand to accurately answer the question.
All the tools & learning materials you need for study success - in one app.
Get started for free(Sides of a Triangle) Write a program that reads three nonzero double values and determines and prints whether they could represent the sides of a triangle.
Write C++ statements to accomplish each of the following: a) In one statement, assign the sum of the current value of \(x\) and \(y\) to \(z\) and postincrement the value of \(x\) b) Determine whether the value of the variable count is greater than \(10 .\) If it is, print "Count is greater than \(10 . "\) c) Predecrement the variable \(x\) by \(1,\) then subtract it from the variable total. d) Calculate the remainder after \(q\) is divided by divisor and assign the result to q. Write this statement two different ways.
(Dangling-else Problem) State the output for each of the following when \(x\) is 9 and \(y\) is 11 and when \(x\) is 11 and \(y\) is \(9 .\) The compiler ignores the indentation in a \(C++\) program. The \(C++\) compiler always associates an else with the previous if unless told to do otherwise by the placement of braces \\{\\}\(.\) On first glance, you may not be sure which if and else match, so this is referred to as the "dangling-else" problem. We eliminated the indentation from the following code to make the problem more challenging. [Hint: Apply indentation conventions you've learned.] (Dangling-else Problem) State the output for each of the following when \(x\) is 9 and \(y\) is 11 and when \(x\) is 11 and \(y\) is \(9 .\) The compiler ignores the indentation in a \(C++\) program. The \(C++\) compiler always associates an else with the previous if unless told to do otherwise by the placement of braces \\{\\}\(.\) On first glance, you may not be sure which if and else match, so this is referred to as the "dangling-else" problem. We eliminated the indentation from the following code to make the problem more challenging. [Hint: Apply indentation conventions you've learned.]
(Another Dangling-else Problem) Modify the following code to produce the output shown. Use proper indentation techniques. You must not make any changes other than inserting braces. The compiler ignores indentation in a \(\mathrm{C}++\) program. We eliminated the indentation from the following code to make the problem more challenging. [Note: It's possible that no modification is necessary. if ( y == 8 ) if ( x == 5 ) cout << "@@@@@" << endl; else cout << "#" << endl; cout << "$$$$$" << endl; cout << "&&&&&" << endl; a) Assuming \(x=5\) and \(y=8,\) the following output is produced. @@@@@ $$$$$ &&&&& b) Assuming \(x=5\) and \(y=8,\) the following output is produced. @@@@@ c) Assuming \(x=5\) and \(y=8,\) the following output is produced. @@@@@ &&&&& d) Asuming \(x=5\) and \(y=7,\) the following output is produced. \([\) Note: The last three output statements after the else are all part of a block.] # $$$$$ &&&&&
(Printing the Decimal Equivalent of a Binary Number) Input an integer containing only 0 s and \(1 s\) (i.e., a "binary" integer) and print its decimal equivalent. Use the modulus and division operators to pick off the "binary" number's digits one at a time from right to left. Much as in the decimal number system, where the rightmost digit has a positional value of \(1,\) the next digit left has a positional value of \(10,\) then \(100,\) then \(1000,\) and so on, in the binary number system the rightmost digit has a positional value of \(1,\) the next digit left has a positional value of \(2,\) then \(4,\) then \(8,\) and so on. Thus the decimal number 234 can be interpreted as \(2^{*} 100+3^{*} 10+4^{*} 1 .\) The decimal equivalent of binary 1101 is \(1^{*} 1+0^{*} 2+1^{*} 4+1^{*} 8\) or \(1+0+4+8\), or \(13 .[\) Note: To learn more about binary numbers, refer to Appendix D.]
What do you think about this solution?
We value your feedback to improve our textbook solutions.