C++ PROGRAMMING LMS MINDTAP
C++ PROGRAMMING LMS MINDTAP
8th Edition
ISBN: 9781337696173
Author: 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
Complete the Swap() method in main.c to exchange the values of the num field of two Number struct objects, num1 and num2.
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.
Program

Chapter 2 Solutions

C++ PROGRAMMING LMS MINDTAP

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
Np Ms Office 365/Excel 2016 I Ntermed
Computer Science
ISBN:9781337508841
Author:Carey
Publisher:Cengage
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT