Question

In: Computer Science

Q1: Given the following code, what is returned by tq(4)? int tq(int num){ if (num ==...

Q1:

Given the following code, what is returned by tq(4)?

int tq(int num){

if (num == 0) return 0;

else

if (num > 100) return -1;

else

    return num + tq( num – 1 );

}

Group of answer choices:

0

4

-1

10


Q2:

Given that values is of type LLNode<Integer> and references a linked list (non-empty) of Integer objects, what does the following code do if invoked as mystery(values)?

int mystery(LLNode<Integer> list)

{

   if (list.getLink() == null)

      return list.getInfo();

   else

      return mystery(list.getLink());

}

Group of answer choices:

returns sum of the numbers on the values list

returns the last number on the values list

returns 0

returns how many numbers are on the values list

Q3:

Given that values is of type LLNode<Integer> and references a linked list (possibly empty) of Integer objects, what does the following code do if invoked as mystery(values)?

int mystery(LLNode<Integer> list)

{

   if (list == null)

      return 0;

   else

      return 1 + mystery(list.getLink());

}

Group of answer choices:

returns 0

returns sum of the numbers on the values list

returns the last number on the values list

returns how many numbers are on the values list

Solutions

Expert Solution


Related Solutions

What will the following code segments print on the screen? int num = 3; switch (num){...
What will the following code segments print on the screen? int num = 3; switch (num){             case 1:                         System.out.println(“Spring”); case 2:                         System.out.println(“Summer”); case 3:                         System.out.println(“Autumn”); case 4:                         System.out.println(“Winter”); }
What is the ouput of the following code? void loop(int num) { for(int i = 1;...
What is the ouput of the following code? void loop(int num) { for(int i = 1; i < num; ++i) { for(int j = 0; j < 5; ++j) { cout << j; } } } int main() { loop(3); return 0; }
(True or False) The following function will compile. void print(int num) { return num+1; } Group...
(True or False) The following function will compile. void print(int num) { return num+1; } Group of answer choices True False Flag this Question Question 2 10 pts (True or False) The following code will output "I was true". bool isGreater(string s1, string s2) { if(s1 > s2) { return true; } return false; } int main() { if(isGreater("before","back")) { cout << "I was true"; } else { cout << "I was false"; } return 0; } Group of answer...
how to write in java; Write a method int[] coPrime[int num, int[]numbers] { // instructions are...
how to write in java; Write a method int[] coPrime[int num, int[]numbers] { // instructions are that it returns an array of all the elements of the int[] array numbers which are coprime with x } Note that the array that is returned may be an empty array--you will have to count how many times gcf(x, numbers[i]) == 1. ASSUME numbers is not null and not empty.
1)What is the output of the following code? struct someType { int a; int b; };...
1)What is the output of the following code? struct someType { int a; int b; }; void f1(someType &s) { s.a = 1; s.b = 2; } someType f2(someType s) { someType t; t = s; s.a = 3; return t; } int main() { someType s1, s2; f1(s1); s2 = f2(s1); cout << s1.a << '-' << s1.b << '-' << s2.a << '-' << s2.b << '-' << endl; return 0; } ------------------------------------------------------------------------------------------------------------------ 2) struct dateType { int...
What is the output of the following C++ code? int* length; int* width; length = new...
What is the output of the following C++ code? int* length; int* width; length = new int; *length = 5; width = length; length = new int; *length = 2 * (*width); cout << *length << " " << *width << " " << (*length) * (*width) << endl;
Question 31 Given the code snippet below, what prints? void fun(int *p) { int q =...
Question 31 Given the code snippet below, what prints? void fun(int *p) { int q = 10; p = &q; } int main() { int r = 20; int *p = &r; fun(p); cout << *p; return 0; } Question 31 options: 10 20 compiler error Runtime error Question 32 A union’s members are exactly like the members of a Structure. Question 32 options: True False Question 33 Given the code below, what are the errors. #include <iostream> using namespace...
#include #include #include int main(void) { int feof(FILE *stdin); int i, num; int binary[10]; char input[10];...
#include #include #include int main(void) { int feof(FILE *stdin); int i, num; int binary[10]; char input[10]; printf("Starting the CPSC 1011 Decimal to Binary Converter!\n"); while(1) {    i=0;    printf("\nPlease enter a positive whole number (or EOF to quit): ");    scanf("%s", input); // user inputs value as a string for separate values    if(strcmp(input,"")==0) {        printf("\n\tThank you for using the CPSC 1011 Decimal to Binary Generator.\nGoodbye!\n\n");    return(0); } num=atoi(input); if (num<=0) {    printf("\n\tSorry, that was...
Translate the following function f to MIPS assembly code. int f(int a, int b, int c,...
Translate the following function f to MIPS assembly code. int f(int a, int b, int c, int d) { return func(func(a,b), func(b+c,d)); } Assume the followings. • The prototype of function func is “int func(int a, int b);”. • You do not need to implement function func. The first instruction in function func is labeled “FUNC”. • In the implementation of function f, if you need to use registers $t0 through $t7, use the lower-numbered registers first. • In the...
Consider the following statements: linkedStackTypemtack; linkedQueueType queue; int num; Suppose the input is 28 30 15...
Consider the following statements: linkedStackTypemtack; linkedQueueType queue; int num; Suppose the input is 28 30 15 11 10 -9 21 8 -3 33 17 14 Write a C++ code that processes these numbers as follows: If the number is an even number, it is pushed onto the stack. If the number is odd and divisible by 3, it is added into the queue; otherwise the top element, if any, of the stack is removed and the square of the number...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT