Problem 2
Which of the following are valid C++ identifiers? a. myFirstProgram b. MIX-UP c. C++Program2 d. quiz7 e. ProgrammingLecture2 f. 1footEquals12Inches g. Mike'sFirstAttempt h. Update Grade i. 4th j. New_Student
Problem 3
Which of the following is a reserved word in C++? a. Const b. include c. Char d. void e. int f. Return
Problem 4
What is the difference between a keyword and a user-defined identifier?
Problem 6
Evaluate the following expressions. a. 25 / 3 b. 20 - 12 / 4 * 2 c. 32 % 7 d. 3 - 5 % 7 e. 18.0 / 4 f. 28 - 5 / 2.0 g. 17 + 5 % 2 - 3 h. 15.0 + 3.0 * 2.0 / 5.0
Problem 7
If x = 5, y = 6, z = 4, and w = 3.5, evaluate each of the following statements, if possible. If it is not possible, state the reason. a. (x + z) % y b. (x + y) % w c. (y + w) % x d. (x + y) *w e. (x % y) % z f. (y % z) % x g. (x *z) % y h. ((x *y) *w) *z
Problem 8
Given:
int num1, num2, newNum;
double x, y;
Which of the following assignments are valid? If an assignment is not valid,
state the
reason.
When not given, assume that each variable is declared.
a. num1 = 35;
b. newNum = num1 – num2;
c. num1 = 5; num2 = 2 + num1; num1 = num2 / 3;
d. num1 * num2 = newNum;
e. x = 12 * num1 - 15.3;
f. num1 * 2 = newNum + num2;
g. x / y = x * y;
h. num2 = num1 % 2.0;
i. newNum = static_cast
Problem 9
Do a walk-through to find the value assigned to e. Assume that all variables are properly declared. a = 3; b = 4; c = (a % b) * 6; d = c / b; e = (a + b + c + d) / 4;
Problem 10
Which of the following variable declarations are correct? If a variable declaration is not correct, give the reason(s) and provide the correct variable declaration. n = 12; // char letter = ; // int one = 5, two; // double x, y, z;
Problem 11
Which of the following are valid C++ assignment statements? Assume that i, x, and percent are double variables. a. i = i + 5; b. x + 2 = x; c. x = 2.5 *x; d. percent = 10%;
Problem 12
Write C++ statement(s) that accomplish the following. a. Declare int variables x and y. Initialize x to 25 and y to 18. b. Declare and initialize an int variable temp to 10 and a char variable ch to 'A'. c. Update the value of an int variable x by adding 5 to it. d. Declare and initialize a double variable payRate to 12.50. e. Copy the value of an int variable firstNum into an int variable tempNum. f. Swap the contents of the int variables x and y. (Declare additional variables, if necessary.) g. Suppose x and y are double variables. Output the contents of x, y, and the expression x + 12 / y - 18. h. Declare a char variable grade and set the value of grade to 'A'. i. Declare int variables to store four integers. j. Copy the value of a double variable z to the nearest integer into an int variable x.