C++ Programming: From Problem Analysis to Program Design
C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN: 9781337102087
Author: D. S. Malik
Publisher: Cengage Learning
Expert Solution & Answer
Book Icon
Chapter 2, Problem 8CP

a. num1 = 35;

Explanation of Solution

num1 = 35; is a valid assignment as integer 35 is be...

b. newNum = num1 – num2;

Explanation of Solution

newNum = num1 – num2; is a valid assignment although the variables num1 and num2 have not been initialized. If a variable is used in an expression, the expression would yield a meaningf...

c. num1 = 5; num2 = 2 + num1; num1 = num2 / 3;

Explanation of Solution

num1 = 5; num2 = 2 + num1; num1 = num2 / 3; are valid assignments. num1 =5; declares and initializes the variable num1. num2 = 2 + num1; assigns the value of the expression 2 + num1 to num2. Since num1 has been declared and assigned a value, the right-hand expression value is 2 + 5 = 7...

d. num1 * num2 = newNum;

Explanation of Solution

num1 * num2 = newNum; is not a valid assignment as the left hand of a valid assignment is a variable and not an expression...

e. x = 12 * num1 - 15.3;

Explanation of Solution

x = 12 * num1 - 15.3; is a valid assignment although the variable num1 in the expression on the right-hand side has been declared but not initialized before being used in the expression. If a variable is used in an expression, the expression would yield a meaningful value only if the variable has first been initialized...

f. num1 * 2 = newNum + num2;

Explanation of Solution

num1 * 2 = newNum + num2; is not a valid assignment as the left hand of a valid assignment is a variable and not an expression...

g. x / y = x * y;

Explanation of Solution

x / y = x * y; is not a valid assignment as the left hand of a valid assignment is a variable and not an expression...

h. num2 = num1 % 2.0;

Explanation of Solution

num2 = num1 % 2.0; is not a valid assignment as the expression on the right-hand side would not evaluate. The expression on the right-hand si...

i. newNum = static_cast<int> (x) % 5;

Explanation of Solution

newNum = static_cast<int> (x) % 5; is a valid assignment. The double variable is explicitly cast to an int type before it participates as an oper...

j. x = x + y - 5;

Explanation of Solution

x = x + y - 5; is a valid assignment although the variables x and y have not been initialized before being used in the expression. The expression on the right side...

k. newNum = num1 + static_cast<int> (4.6 / 2);

Explanation of Solution

newNum = num1 + static_cast<int> (4.6 / 2); is a valid assignment. The expression on the right-hand side evaluates an unpredictable but int type value. The expression inside the parentheses is evaluated first where the denominator is implicitly casted to floating-point type (as the numerator is floating-point type)...

Blurred answer
Students have asked these similar questions
if L1={ab,b} L2={abb,bb} then L1L2= * O {ababb,abbb,abbab,bbab} O {ab,b,abb,bb} O {ababb,abbb,babb,bbb} O {abbab,abbb,bbab,bbb}
Given a structure for student as follows: struct student { int ID; float grade; } s[5]; Use scanf to have user enter ID and grades for each student: 1st student ID =1, Grade = 90 2nd student ID=2, Grade = 81.5 3rd student ID=3, Grade = 85.5 4th student ID=4, Grade = 88 5th student ID=5, Grade = 94 Each student as a structure needs to have the ID and grade properly set. Output: The average grade for 5 students' needs to be reported using printf. Also, each student ID and Grade need to be reported. NOTE: Use structure syntax as needed. Use for loop when you deal with arrays.
Hef sharks_minnows (minnows, sharks): shark_count = 0 minnow_count = len (minnows) for i in range(minnow_count): curr_shark_height = minnows [i] if curr_shark_height is not None: minnows [i] = None for j in range (i + 1, minnow_count): if minnows [j] == curr_shark_height: minnows [j] = None curr_shark_height -- 1 shark_count += 1 return shark_count <= sharks The provided code is imperfect, in that it sometimes returns True when it should return False, and sometimes returns False when it should return True. (a) Provide an example of a function call where the provided code will correctly return True (i.e. a True Positive) (b) Provide an example of a function call where the provided code will correctly return False (i.e. a True Negative) (c) Provide an example of a function call where the provided code will incorrectly return True (i.e. a False Positive) (d) Provide an example of a function call where the provided code will incorrectly return False (i.e. a False Negative)

Chapter 2 Solutions

C++ Programming: From Problem Analysis to Program Design

Ch. 2 - Which of the following are valid C++ assignment...Ch. 2 - Write C++ statements that accomplish the...Ch. 2 - Write each of the following as a C++ expression....Ch. 2 - Prob. 14SACh. 2 - Suppose x, y, and z are int variables and wandt...Ch. 2 - 16. Suppose x, y, and z are int variables and x =...Ch. 2 - Suppose a and b are int variables, c is a double...Ch. 2 - 18. Write C++ statements that accomplish the...Ch. 2 - Which of the following are correct C++ statements?...Ch. 2 - Give meaningful identifiers for the following...Ch. 2 - 21. Write C++ statements to do the following....Ch. 2 - Prob. 22SACh. 2 - The following program has syntax errors. Correct...Ch. 2 - Prob. 24SACh. 2 - Prob. 25SACh. 2 - Preprocessor directives begin with which of the...Ch. 2 - 27. Write equivalent compound statements if...Ch. 2 - 28. Write the following compound statements as...Ch. 2 - 29. Suppose a, b, and c are int variables and a =...Ch. 2 - Suppose a, b, and sum are int variables and c is a...Ch. 2 - Prob. 31SACh. 2 - Prob. 32SACh. 2 - Prob. 33SACh. 2 - Prob. 34SACh. 2 - 1. Write a program that produces the following...Ch. 2 - Prob. 2PECh. 2 - Prob. 3PECh. 2 - 4. Repeat Programming Exercise 3 by declaring...Ch. 2 - Prob. 5PECh. 2 - Prob. 6PECh. 2 - 7. Write a program that prompts the user to input...Ch. 2 - Prob. 8PECh. 2 - 9. Write a program that prompts the user to enter...Ch. 2 - 10. Write a program that prompts the user to input...Ch. 2 - 11. Write a program that prompts the capacity, in...Ch. 2 - 12. Write a C++ program that prompts the user to...Ch. 2 - 13. To make a profit, a local store marks up the...Ch. 2 - 14. (Hard drive storage capacity) If you buy a 40...Ch. 2 - 15. Write a program to implement and test the...Ch. 2 - 16. A milk carton can hold 3.78 liters of milk....Ch. 2 - 17. Redo Programming Exercise 16 so that the user...Ch. 2 - Prob. 18PECh. 2 - 19. Write a program that prompts the user to input...Ch. 2 - 20. For each used car a salesperson sells, the...Ch. 2 - 21. Newton's law states that the force, , between...Ch. 2 - 22. One metric ton is approximately 2,205 pounds....Ch. 2 - 23. Cindy uses the services of a brokerage firm to...Ch. 2 - 24. A piece of wire is to be bent in the form of a...Ch. 2 - 25. Repeat Programming Exercise 24, but the wire...Ch. 2 - 26. A room has one door, two windows, and a...Ch. 2 - Prob. 27PECh. 2 - 28. In an elementary school, a mixture of equal...Ch. 2 - 29. A contractor orders, say, 30 cubic yards of...
Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education