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

Please explain how the 5 codes end up becoming these answers. I want to know wha

ID: 3833855 • Letter: P

Question

Please explain how the 5 codes end up becoming these answers.

I want to know what the codes do in order to make those answers. The answers are correct.

public static void decisions00 int crowded 1; int noisy 0; int booze 1; int food crowded && Inoisy II food ll booze Rriott Let's go to this club!Nn"); printf"What do you want to do?In"); crowded && noisy) && (food && booze priott. Let's go to the bar.Mn"); priott. Let's stay home. public static void decisiens00 int crowded 1; int noisy 0; int booze 1: int food iffl crowded II noisy III food ll booze priott."Let's go to the football ga me.In crowded && noisy II food && booze priott."Let's go here.Mn"); priott Let's play pool-Mn"); void whatsThis01 int i 30; float thing10 13.7f, 7.4f, 4.3f, 3.5f, 6.2f, 4.6); double thing2 36; i--) if(thing 2 [i]) thing2 3 thing1[i]; printf thing2 -%1.1fMn", thing2); Answer is: Let's go to this club Let's stay home Answer is: Let's bbg Let's go here Answer is: Thing2 7.4

Explanation / Answer

Solution:

1. In the first code we have variables

int crowded = 1;

int noisy = 0;

int booze = 1;

int food = 0;

now let us check the if conditions,

the first if..else is

if(crowded && !noisy) || (!food || booze)

   printf(“Let’s go to this club ”);

else

   printf(“What do you want to do? ”);

the if statement is equivalent to,

if(crowded == 1 && noisy != 1) || (food != 1 || booze == 1)

Thus we check,

crowded == 1 is true

noisy != 1(i.e. noisy = 0) is true

food != 1(i.e. food = 0) is true

booze == 1 is true,

so we get,

if(true && true) || (true || true)

thus,

if(true) || (true) - if is true, so the statement

   printf(“Let’s go to this club ”);

gets executed.

Then the control goes to the next if statement , i.e.

if(!crowded && !noisy) && (food && booze),

this is equivalent to,

if(crowded != 1 && noisy != 1) && (food == 1 && booze == 1),

so we check,

crowded != 1 is false

noisy != 1 is true

food == 1 is false

booze == 1 is true,

so we get

if(false && true) && (false && true)

thus,

if(false) && (false) - if is false, so the else part printf(“Let’s stay home. ”);

gets executed,


2.

We have the variables

int crowded = 1;

int noisy = 0;

int booze = 1;

int food = 0;

now let us check the if conditions,

the first if..else is

if(!(crowded || noisy) || !(food || booze))

the if statement is equivalent to,

if(!(crowded ==1 || noisy == 1) || !( food ==1 || booze ==1))

Thus we check,

crowded == 1 is true

noisy == 1 is false

food == 1 is false

booze == 1 is true,

so we get,

if(!(true || false) || !(false || true))

thus,

if(!(true) || !(true)) which is

if(false || false) - if is false, so the else statement

   printf(“Let’s bbq. ”);

gets executed.

Then the control goes to the next if statement , i.e.

if((!crowded && !noisy) || !(food && booze))

this is equivalent to,

if((crowded != 1 && noisy != 1) || !(food == 1 && booze == 1)),

so we check,

crowded != 1 is false

noisy != 1 is true

food == 1 is false

booze == 1 is true,

so we get

if((false && true) || !(false && true))

thus,

if((false) || !(false)), which is equivalent to

if ((false) || (true)) - if is true, so the statement printf(“Let’s go here. ”);

gets executed,

3.

Given:

int i =0;

float thing1[] = {3.7f,7.4f,4.3f,3.5f,6.2f,4.6f};

double thing2 = 6;

for(i = 5; i>0; i--)

if(thing2 < thing1[i]

   thing2 = thing1[i];

So let us take a dry run

i    thing1[i]       thing2

0       4.6f           6

then comes the for loop and i becomes 5, i>0 is true, the control goes to for body, and we have

i    thing1[i]       thing2

5       4.6f           6

It now checks the condition thing2 < thing1[i],

i.e. if(6 < 4.6f) - it is false, so nothing happens,

i is decremented by 1, and we get,

i    thing1[i]       thing2

4           6.2f       6

It now checks the condition thing2 < thing1[i],

i.e. if(6 < 6.2) - it is true, so we store the value thing2 = thing1[4], thus thing2 = 6.2,

we get,

i    thing1[i]       thing2

4       6.2           6.2

i is decremented by 1, and we get,

i    thing1[i]       thing2

3       3.5           6.2

It now checks the condition thing2 < thing1[i],

i.e. if(6.2 < 3.5) - it is false, so nothing happens,

i is decremented by 1, and we get,

i    thing1[i]       thing2

2       4.3           6.2

It now checks the condition thing2 < thing1[i],

i.e. if(6.2 < 4.3) - it is false, so nothing happens,

i is decremented by 1, and we get,

i    thing1[i]       thing2

1       7.4           6.2

It now checks the condition thing2 < thing1[i],

i.e. if(6.2 < 7.4) - it is true, so we store the value thing2 = thing1[1], thus thing2 = 7.4,

we get,

i    thing1[i]       thing2

1           7.4       7.4

i is decremented by 1, and we get,

i    thing1[i]       thing2

0       3.7           7.4

It now checks the condition thing2 < thing1[i],

i.e. if(7.4 < 3.7) - it is false, so nothing happens,

i is decremented by 1, and we get,

i    thing1[i]       thing2

-1               7.4

for loop condition is false as i < 0,

the control goes to the print statement ,

and the answer is thing2 = 7.4

4.

char cube[2][3][4] is a multi dimentional array , which will resemble following table , thus there are main two rows, in that each row is agin diveded into 3 rows and 4 cloumns,

  

so we get,

XXXX

XXXX

XXXX

XXXX

XXXX

XXXX