Invitation to Computer Science 8th Edition

Published by Cengage Learning
ISBN 10: 1337561916
ISBN 13: 978-1-33756-191-4

Chapter 2 - Exercises - Page 88: 21

Answer

The output will be stored as the sequence $R_{1}, R_{2}, \dots R_{m-1}$ $\bullet$ Get the letters of the alphabet $A_{1}, A_{2}, \ldots A_{26}$ $\bullet$ Get the text (including blanks and end symbol) $T_{1}, T_{2}, \ldots T_{m}$ $\bullet$ Get value for $k$ $\bullet$ Set value of $i$ to 1 $\bullet$ While $\left(T_{i}\ \neq \ "S" \right)$ do $\bullet \quad$ If $\left(T_{i} \text { is a blank space }\right)$ then $\bullet \quad\quad R_{i}$ is a blank space $\bullet\quad$ Else $\bullet \quad\quad$ Set value of $j$ to 1 $\bullet \quad\quad$ Set value of Found to NO $\bullet \quad\quad$ While both $(j \leq 26)$ and $(\text {Found}=N O)$ do $\bullet \quad\quad\quad$ If $T_{i}=A_{j}$ then $\bullet \quad\quad\quad\quad$ Set Found to YES $\bullet\quad\quad \quad\quad$ Set value of loc to $j$ $\bullet \quad\quad\quad$ Increment $j$ by 1 $\bullet\quad\quad$ End of loop $\bullet\quad \quad$ If $l o c+k>26$ then $\bullet\quad\quad\quad$ Set $R_{i}$ to $A_{l o c+k-26}$ $\bullet\quad\quad$ Else $\bullet\quad\quad \quad$ Set $R_{i}$ to $A_{l o c+k}$ $\bullet\quad$ Increment $i$ by 1 $\bullet$ End of loop. $\bullet$ Print the result: $R_{1}, R_{2}, \ldots R_{m-1}$

Work Step by Step

The output will be stored as the sequence $R_{1}, R_{2}, \dots R_{m-1}$ $\bullet$ Get the letters of the alphabet $A_{1}, A_{2}, \ldots A_{26}$ $\bullet$ Get the text (including blanks and end symbol) $T_{1}, T_{2}, \ldots T_{m}$ $\bullet$ Get value for $k$ $\bullet$ Set value of $i$ to 1 $\bullet$ While $\left(T_{i}\ \neq \ "S" \right)$ do $\bullet \quad$ If $\left(T_{i} \text { is a blank space }\right)$ then $\bullet \quad\quad R_{i}$ is a blank space $\bullet\quad$ Else $\bullet \quad\quad$ Set value of $j$ to 1 $\bullet \quad\quad$ Set value of Found to NO $\bullet \quad\quad$ While both $(j \leq 26)$ and $(\text {Found}=N O)$ do $\bullet \quad\quad\quad$ If $T_{i}=A_{j}$ then $\bullet \quad\quad\quad\quad$ Set Found to YES $\bullet\quad\quad \quad\quad$ Set value of loc to $j$ $\bullet \quad\quad\quad$ Increment $j$ by 1 $\bullet\quad\quad$ End of loop $\bullet\quad \quad$ If $l o c+k>26$ then $\bullet\quad\quad\quad$ Set $R_{i}$ to $A_{l o c+k-26}$ $\bullet\quad\quad$ Else $\bullet\quad\quad \quad$ Set $R_{i}$ to $A_{l o c+k}$ $\bullet\quad$ Increment $i$ by 1 $\bullet$ End of loop. $\bullet$ Print the result: $R_{1}, R_{2}, \ldots R_{m-1}$
Update this answer!

You can help us out by revising, improving and updating this answer.

Update this answer

After you claim an answer you’ll have 24 hours to send in a draft. An editor will review the submission and either publish your submission or provide feedback.