Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Can you please give me the steps and explanations on how to do these. use the co

ID: 3604451 • Letter: C

Question

Can you please give me the steps and explanations on how to do these.

use the code to fill in the values. Use a ? if the value is not determined by the code. If a character is stored use ' 's about the character value. int h = 0, n = 0, s = 0, y = 0; char ch;

switch (ch) { case 'k' : ++h; break;  

                case 'p' : ++n;

                case 's' : ++s;

                default : ++y;         }

/* In each part below, start with the initial values */

a.   if value of ch is 'k'     h ____ n ____ s ____ y ____

b.   if value of ch is 'p'     h ____ n ____ s ____ y ____

c.   if value of ch is 's'     h ____ n ____ s ____ y ____

d.   if value of ch is 'h'     h ____ n ____ s ____ y ____

Explanation / Answer

a.) h =1 n =0 s =0 y =0

It will only print the first line as break keyword is been used it will

move us out of the condition and hence, rest of the cases will not print.

As, the value has been incremented for h it will increase from 0 to 1.

b.)h=0 n=1 s=0 y=0

h=0 n=1 s=1 y=0

h=0 n=1 s=1 y=1

As, there is no break keyword used in the statement all the rest of the case

will be printed and then, the values will be as above. Rest remains the same.

c.)h=0 n=0 s=1 y=0

h=0 n=0 s=1 y=1

As, there is no break keyword used in the statement all the rest of the case

will be printed and then, the values will be as above. Rest remains the same.

d.)h=0 n=o s=0 y=1

As, h is not the case in the switch stated as above. Hence, the default will

run which will result in printing the values in the default case with the

increment in y.

Rate an upvote....Thankyou

Hope this helps....