Int num1, num2, newNum: double x, y: Which of die following assignments are vali
ID: 3886874 • Letter: I
Question
Int num1, num2, newNum: double x, y: Which of die following assignments are valid? If an assignment is not valid, state the reason. 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 = satatic_caat (x) % 5: j. x = x + y - 5: k. newNum = num1 + static_cast (4.6/2): 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 grado 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.Explanation / Answer
Please find below the required solution:
Problem 03
Given :
int num1,num2,newNum;
double x,y;
a. num1 = 35 VALID
b. newNum = num1 - num2 VALID
c. num1 = 5; num2 = 2 + num1; num1 = num2/3 VALID
d. num1 * num2 = newNum INVALID
Assignment should be always left to right newNum = num1 * num2 is valid
e. x = 12 * num1 -15.3 VALID
f. num1 * 2 = newNum + num2 INVALID
no operations can be performed on left side only assignments can be done
g. x/y = x*y; INVALID
no operations alowed on left side
h. num2 = num1%2.0; INVALID
num1 and num2 is type of int and 2.0 is type of double
invalid operations
i. newNum = static_cast<int> (x) %5; VALID
j. x = x + y - 5 VALID
k. newNum = num1 + static_cast<int> (4.6/2); VALID
Problem 04
a.
int x,y;
x = 25;
y = 18;
b.
int temp = 10;
char ch = 'A';
c.
x = x + 5;
d.
double payRate = 12.50;
e.
int firstNum;
int tempNum = firstNum;
f.
int temp = x;
x=y
y=temp
g.
x+12/y-18 //output will be 2.5
h.
char grade = 'A'
i.
int a,b,c,d;
j.
double z =2.0;
x = int(z)
Please do let me know if u have any concern...
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.