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

Hi, could you please help with these practice questions. I would like to know th

ID: 3626803 • Letter: H

Question

Hi, could you please help with these practice questions. I would like to know the correct answers and know how to do some of the harder questions. Real important. Thanks heaps !

Q8.
How do you use desk-checking to follow through an
algorithm such like the one below?
Procedure
Get Num1, Num2, Num3
Set Num1 = Num2 – Num3
Set Num2 = Num3 – Num1
Set Num3 = Num1 – Num2
Display Num1, Num2, Num3
END
If 3, 9, 5 are the input, use deck-checking to find the
output.

Q9.
Desk-checking algorithms with conditional
statements like the one below.
Procedure
Get Num1, Num2, Num3
IF Num1 > Num2 THEN
IF Num2 > Num3 THEN
Num3 = Num2 + Num1
ELSE
Num2 = Num1 – Num3
ENDIF
Num1 = Num2 – Num3
ENDIF
END
If 7, 5, 5 are the input, what are the values of all the
variables when the program terminates?


Q10.
Consider the following C++ code
int m = 1, n=5;
m = n++;
m += n;
n += ++m ;
Desk-check the above code and find out what are the
values for m and n after the execution.

Q11.
Find the value of
! ( a > b && b <= c ) || a > c && ! b
for a=5, b=4, c=4?

Q12.
If total is initially set to 7, what is the value of rank
after the execution of the following code?
if(total > 10) rank = 1;
else if(total > 8) rank = 2;
else if(total > 6) rank = 3;
else if(total > 4) rank = 4;
else rank =5;


Q16.
Find out the output of the following C++ program?
#include<iostream>
using namespace std;
void f(int & i, int j) {
i++;
j++;
}
int main() {
int i=1, j=2;
f(i, j);
cout << ( i + j );
return 0;
}

Q17. Write out loop statement in pseudocode that
calculates the sum of all the elements in the array
marks of totalElements elements (array index goes
from 1 to totalElements).

Q20.
For the records r and s defined below
struct Rec {
string address;
int age;
};
struct Rec r, s;
How many different ways you can think of that can
let you refer to the age field of the record variable r?
Immediately after the execution of s = r; will
r.address and r.age be exactly the same as r.address
and r.age?

Q21.
If we use the binary search algorithm to search for 31
from the following list,
1, 7, 8, 11, 15, 19, 20, 23, 31, 90,
how would we actually do it? The lecture slides
showed the following pseudocode
binarySearch(key,a,first,last)
set found to false
DOWHILE (first <= last) AND (NOT found
set middle = ? (first + last)/2 ?
IF a(middle) = key THEN
set found to true
ELSE
IF key > a(middle) THEN
first = middle + 1
ELSE
last = middle - 1
ENDIF
ENDIF
ENDDO
for the algorithm, explain the role of each statement
there, and why it is so.

Explanation / Answer

How do you use desk-checking to follow through an
algorithm such like the one below?
Procedure
Get Num1, Num2, Num3
Set Num1 = Num2 – Num3
Set Num2 = Num3 – Num1
Set Num3 = Num1 – Num2
Display Num1, Num2, Num3
END
If 3, 9, 5 are the input, use deck-checking to find the
output.

output   4,1,3


Q9.
Desk-checking algorithms with conditional
statements like the one below.
Procedure
Get Num1, Num2, Num3
IF Num1 > Num2 THEN
IF Num2 > Num3 THEN
Num3 = Num2 + Num1
ELSE
Num2 = Num1 – Num3
ENDIF
Num1 = Num2 – Num3
ENDIF
END
If 7, 5, 5 are the input, what are the values of all the
variables when the program terminates?

-3 , 2 , 5
Q10.
Consider the following C++ code
int m = 1, n=5;
m = n++;
m += n;
n += ++m ;
Desk-check the above code and find out what are the
values for m and n after the execution.

m = 12
n = 17

Q11.
Find the value of
! ( a > b && b <= c ) || a > c && ! b
for a=5, b=4, c=4?

0


Q12.
If total is initially set to 7, what is the value of rank
after the execution of the following code?
if(total > 10) rank = 1;
else if(total > 8) rank = 2;
else if(total > 6) rank = 3;
else if(total > 4) rank = 4;
else rank =5;

rank = 3

Q16.
Find out the output of the following C++ program?
#include<iostream>
using namespace std;
void f(int & i, int j) {
i++;
j++;
}
int main() {
int i=1, j=2;
f(i, j);
cout << ( i + j );
return 0;
}

4

Q17. Write out loop statement in pseudocode that
calculates the sum of all the elements in the array
marks of totalElements elements (array index goes
from 1 to totalElements).

for i=1 to totalElements

sum = sum + a[i];


Q20.
For the records r and s defined below
struct Rec {
string address;
int age;
};
struct Rec r, s;
How many different ways you can think of that can
let you refer to the age field of the record variable r?
Immediately after the execution of s = r; will
r.address and r.age be exactly the same as r.address
and r.age?

there are two ways

r.age = 10 or
struct Rec *op = &r;
op->age = 10;

no addreesses will not be same because both are different. structures.



Q21.
If we use the binary search algorithm to search for 31
from the following list,
1, 7, 8, 11, 15, 19, 20, 23, 31, 90,
how would we actually do it? The lecture slides
showed the following pseudocode
binarySearch(key,a,first,last)
set found to false
DOWHILE (first <= last) AND (NOT found
set middle = ? (first + last)/2 ?
IF a(middle) = key THEN
set found to true
ELSE
IF key > a(middle) THEN
first = middle + 1
ELSE
last = middle - 1
ENDIF
ENDIF
ENDDO
for the algorithm, explain the role of each statement
there, and why it is so.

first = 0
last = 9
0<=9 true
middle = 0+9/2 = 4
a[4] = 15 ! = 31
since 31 > 15 first = 4+1 = 5
now
first < last ? 5 <=9 true
middle = 5+9/2 = 7
a[7] = 23 ! = 31
31 > 23 thus
first = 7+1 = 8

8<=9 true thus

middle = 8+9/2 = 8

a[8]= 31 = 31 key found.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote