1. State whether the following are valid statements. If they are not. Assume variables, a, b & c are declared as integer variables and have been given values (a = 5, b = 10, c = 12) prior to each of...




1. State whether the following are valid statements. If they are not. Assume variables, a, b & c are declared as integer variables and have been given values (a = 5, b = 10, c = 12) prior to each of the following statements. If they are valid explain what the statement will do. (3 points each)



a) if (a = (b == c)) a = 1; else a = -1;


b) a += b ++;


c) (a - b) = c;


d) a = (b - 1) ? b : c;


e) a += b == c;


f) a-=1;


g) a=-1;


h) b ** b;


i) int x [a];


j) a = —a - -;


k) unsigned char m = 5;


l) a * = ++ b;


m) b++ = a;


n) a += b++ + ++c;


o) char N [ ];


p) char L [ ] — *abcd”;


2. What will the following section of code print? (5 pts)


for (int i = 0; i <>


       cout <>


3. What will the following section of code print? (5 pts)


int i;


for (i = 0; i <>


   if (i%3)


       cost <“got>


4. What does the following section of code print? (5 pts)


int a;


int b;


int c;


a = 11


b = 7


c = (a-1.0)/ (b - 4) / 0.7;


cost <>


5. What will the following section of code print? (5 pts)


int j (0);


int k [5];


int m (0);


while (j


   k [j] = j++ * 2;


for (j = 0; j


   m += k [j];


cost <><>


6. Write a loop to print all integers that are multiples of eleven between 1 and 1000. (5 pts)


7. Write a loop which will: (10 pts   Read a character from the keyboard Print a message telling if the character is a digit, uppercase, or lowercase     If the character is a lowercase x the loop will terminate, otherwise it reads another character. 8. Write the declaration for a variable called string holding a string up to 25 alphabetic characters (2 pts) 9. Write a piece of code using only one switch and no other control structures to read one character and do the following: (10 pts)   if a 1 print “Got a ONE   if a 3 print “Got a THREE    if a 5 print “Got a FIVE”   if a 7 print “Got a SEVEN”    if a 9 print “Got a NINE”    if an even number print “Got an even number”    if a non-digit print “Got a non-digit” 10. Write a section of code that will take an integer variable Y and if Y is negative, will set to zero. If Y is greater than zero, the code will add one to Y if and only if Y is also an even number (5 pts)


May 19, 2022
SOLUTION.PDF

Get Answer To This Question

Submit New Assignment

Copy and Paste Your Assignment Here