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)...
Trending nowThis is a popular solution!
Chapter 2 Solutions
C++ Programming: From Problem Analysis to Program Design
- EX2: Write a piece of assembly code that can count the number of ones in word stored at 4AE00harrow_forwardWrite a program that simulates a Magic 8 Ball, which is a fortune-telling toy that displays a random response to a yes or no question. In the student sample programs for this book, you will find a text file named 8_ball_responses.txt. The file contains 12 responses, such as “I don’t think so”, “Yes, of course!”, “I’m not sure”, and so forth. The program should read the responses from the file into a list. It should prompt the user to ask a question, then display one of the responses, randomly selected from the list. The program should repeat until the user is ready to quit. Contents of 8_ball_responses.txt: Yes, of course! Without a doubt, yes. You can count on it. For sure! Ask me later. I'm not sure. I can't tell you right now. I'll tell you after my nap. No way! I don't think so. Without a doubt, no. The answer is clearly NO. (You can access the Computer Science Portal at www.pearsonhighered.com/gaddis.)arrow_forwardStart with the initial angles within the integration and just integrate them without mapping them to specific quadrants. Use python and radiansarrow_forward
- Activity No. Activity Time (weeks) Immediate Predecessors 1 Requirements collection 3 2 Requirements structuring 4 1 3 Process analysis 3 2 4 Data analysis 3 2 5 Logical design 50 3,4 6 Physical design 5 5 7 Implementation 6 6 c. Using the information from part b, prepare a network diagram. Identify the critical path.arrow_forwardGiven the following Extended-BNF grammar of the basic mathematical expressions: Show the derivation steps for the expression: ( 2 + 3 ) * 6 – 20 / ( 3 + 1 ) Draw the parsing tree of this expression. SEE IMAGEarrow_forwardWhentheuserenters!!,themostrecentcommandinthehistoryisexecuted.In the example above, if the user entered the command: Osh> !! The ‘ls -l’ command should be executed and echoed on user’s screen. The command should also be placed in the history buffer as the next command. Whentheuserentersasingle!followedbyanintegerN,theNthcommandin the history is executed. In the example above, if the user entered the command: Osh> ! 3 The ‘ps’ command should be executed and echoed on the user’s screen. The command should also be placed in the history buffer as the next command. Error handling: The program should also manage basic error handling. For example, if there are no commands in the history, entering !! should result in a message “No commands in history.” Also, if there is no command corresponding to the number entered with the single !, the program should output "No such command in history."arrow_forward
- Np Ms Office 365/Excel 2016 I NtermedComputer ScienceISBN:9781337508841Author:CareyPublisher:CengageEBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTNew Perspectives on HTML5, CSS3, and JavaScriptComputer ScienceISBN:9781305503922Author:Patrick M. CareyPublisher:Cengage Learning
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrC++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningProgramming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:Cengage