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

Write your name at the top of this sheet and your program in a block or inline c

ID: 3601943 • Letter: W

Question

Write your name at the top of this sheet and your program in a block or inline comment. Answer the following questions and turn in this sheet before the end of class. You may use the pre-lab, your book or internet resources to assist you 1. (16pts) Assume an array of characters has been created with certain character values. Write the index locations in such an order that the contents of the array spell a word. (Note: some character values may need to be used more than once.) a. SPELL "TEENAGE C. SPELL "NINJA" char ninja [ ]-(1','r,'N','A' ); NINJIA char teenage [ ] { T,'N', 'E', 'A, 'G'); b. SPELL "MUTANT": d. SPELL "TURTLES char turtles [ ] { 'R','S', T,'L','E', 'U'); char mutant -('M,'A,'N' U',T MUTANT TURTLES 2. (4pts) What is the output of the following code snippet? const int SIZE 3; string arr[SIZE] = {"Rick", for (int i = SIZE-1; i > 0; "and", i-) { "Morty"); cout

Explanation / Answer

1.a) char teenage[]={‘T’,’N’,’E’,’A’,’G’};

                As per above array declaration index of T is 0 ,N is 1, E is 2,A is 3 and G is 4

T

E

E

N

A

G

E

0

2

2

1

3

4

2

1 .b) char mutant[]={‘M’,’A’,’N’,’U’,’T’};

As per above array declaration index of M is 0,A is 1,N is 2,U is 3 and T is 4

M

U

T

A

N

T

0

3

4

1

2

4

1.c) char ninja[]={‘I’,’J’,’N’,’A’};

As per above array declaration index of I is 0,J is 1, N is 2 and A is 3

N

I

N

J

A

2

0

2

1

3

1.d) char turtles[]={‘R’,’S’,’T’,’L’,’E’,’U’};

As per above array declaration index of R is 0,S is 1,T is 2,L is 3,E is 4 and U is 5

T

U

R

T

L

E

S

2

5

0

2

3

4

1

2)const int SIZE=3;

String arr[size]={“Rick”, “and”, “Morty”};

Indexes of Rick is 0,and is 1,Morty is 2.

for(int i=SIZE-1;i>0;i--)

{

Cout<<arr[i]<<” “;

}

As per the code in above for loop i starts from SIZE-1 that is i=2

So in the first iteration it print Morty

And i is decremented by 1 and since 1>0 now it will print and in the next iteration which is at index 1

Now again I is incremented by 1 and now I is 0 and since 0>0 is false loop will be stopped. So ouput after executing the loop is

Morty and

T

E

E

N

A

G

E

0

2

2

1

3

4

2