Question

In: Computer Science

What is the output of the following code snippet? (If there is some kind of syntax...

What is the output of the following code snippet? (If there is some kind of syntax error indicate this by marking "error" in your answer choice)

1.

       int laps = 8;

       if (laps++ > --laps)

              laps += 2;

       else if (--laps > (laps - 1))

              laps += 4;

       else if (++laps)

              laps -= 3;

       cout << laps << endl;

2.

What is the output of the following code snippet?

  1.     int j = 47;
  2.     int i = 8;
  3.     j = (j / 3);
  4.     if (j / 2 > i && --i > (j /= 3))
  5.         j += i;
  6.     else
  7.     cout << j << endl;

3.

integer i = 67;
    double d = i - 1;
    i = d;
    character c = i;

    if i > 65
        cout << "The character is: " << c << " in the alphabet" << endl;
    else i <= 65
        cout << "The character is before the alphabet" << endl;

The character is: B in the alphabet

The character is: C in the alphabet

The character is: c in the alphabet

The character is before the alphabet

Error: the code will not compile

4.

What is the output of the following? (if there is a  syntax or runtime error enter “error” for your answer)
 
               int know = 4;
               short test = 5;
               long large = 28;
               
               if (large / 5 < test && ++test > know && ++test < large)
               {
                              test += know;
               }
               else if (--test == know++)
               {
                              test -= know;
               }
               large -= test;
               cout << large << endl;

5.

What is the output of the following code snippet? (If there is some kind of syntax error indicate this by marking "error" in your answer choice)

       //Note that there are no endl's until the end of the problem

       short k = 5;

       float red = 7.7f;

       if (++k < --red)

              cout << k;

       if (k < --red)

              cout << 4;

       if (++red > k--)

              cout << 2;

       cout << k << endl;

Solutions

Expert Solution



Related Solutions

Identify all private and shared variables in the following code snippet. What is the output of...
Identify all private and shared variables in the following code snippet. What is the output of the program (e.g. the value of res)? // ========= int A[100]; int count; void work(int index[]) { float B[10]; …… } void main(){ int res = 10; #pragma omp parallel   { int index[10], i=0, IS=0;                         work(index);                         #pragma omp for                         for(i=0;i<100;i++)                         { IS = IS + i;                         } #pragma omp critical res += IS; }...
• Based on the following code snippet and plan attributes, provide the output for Plan A,...
• Based on the following code snippet and plan attributes, provide the output for Plan A, Plan B and Plan C. Code Snippet • {{IF:[Copay]=Not Covered && [Coinsurance]=Not Covered, show ‘Not covered’}} • {{IF:[Copay]!=$0.00 && [Copay]!=Blank, show value from {{Copay}} copayment}} • {{IIF:[Copay]!=$0.00 && [CopayFrequency]!=Blank, show {{Copay}} copayment/{{CopayFrequency}}}} • {{IF:[CopayMax]=$0.00 OR [Copay]=$0.00, show No Charge}} • {{IF:[[CopayMax]!=$0.00 && [CopayMax] contains ‘$’ && [Coinsurance] contains ‘%’ && [CopayMaxFrequency]=Blank, show {{CopayMax}} copayment then {{Coinsurance}} coinsurance]}} Plan Copay CopayFrequency CopayMax CopayMaxFrequency Coinsurance Plan...
The following code has some syntax error. Please fixed the error. Besides, I want the output...
The following code has some syntax error. Please fixed the error. Besides, I want the output in ASCII characters. Please give me the corrected code along with the screenshot of the output. def cbc_dec(ys): int xs = [] int iv = ("0XAA", 16) #in decimal int key = ("0X08", 16) int x0 = chr(((163 * (int (ys[0], 16) - key)) % 256) ^ iv) xs.append(x0) for i in range (1, len(ys)): int xi = chr((( 163 * (int (ys[i], 16)...
I'm having trouble understanding the following code (a snippet of a code). What does it do?...
I'm having trouble understanding the following code (a snippet of a code). What does it do? The whole code is about comparing efficiencies of different algorithms. def partition(list,first,last): piv = list[first] lmark = first+1 rmark = last done = False while not done: while lmark <= rmark and list[lmark]<=piv: lmark=lmark+1 while list[rmark]>=piv and rmark>=lmark: rmark=rmark-1 if rmark<lmark: done = True else: temp = list[lmark] list[lmark]=list[rmark] list[rmark]=temp temp = list[first] list[first]=list[rmark] list[rmark]=temp return rmark
[50%] Code Snippet Given snippet code below that you are required to complete. You are not...
[50%] Code Snippet Given snippet code below that you are required to complete. You are not allowed to make a new function or change any given code. Please complete each section that are marked with the notation “INSERT YOUR CODE HERE”. Once you complete the snippet below, your output should have the same result with the given output below. Descriptions: [15%] isValid() This function is for checking that there is no duplicated employee data in the linked list. This function...
The following code snippet is free of errors (issues that will prevent the code from compiling)...
The following code snippet is free of errors (issues that will prevent the code from compiling) but it does contain a major bug that will cause the program to hang (not finish running). Identify the problem and create a line of code to fix it. #include <stdio.h> char get_input(); int main() { printf("The user's inputted letter is %c\n", get_input()); return 0; } char get_input() { printf("Please enter a letter: \n"); char input = getchar(); while (!(input >= 'a' && input...
a. What will be the output of LINE A in code “a” and output of code...
a. What will be the output of LINE A in code “a” and output of code “b”? Also write reasons for the outputs. a. #include <sys/types.h> #include <stdio.h> #include <unistd.h> int value = 3; int main() { pid_t pid; pid = fork(); if (pid = = 0) {/* child process */} value += 233; return 0; } else if (pid > 0) {/* parent process */} wait(NULL); printf(“PARENT: value = %d”, value); /* LINE A */ return 0; } }...
What is the Big-Oh notation of the following code snippet: BinarySearch(numbers, N, key) { mid =...
What is the Big-Oh notation of the following code snippet: BinarySearch(numbers, N, key) { mid = 0; low = 0; high = 0; high = N - 1; while (high >= low) { mid = (high + low) / 2 if (numbers[mid] < key) { low = mid + 1 } else if (numbers[mid] > key) { high = mid - 1 } else { return mid } } return -1 // not found }
identify the syntax errors in the following code:             public class Hello {                    &
identify the syntax errors in the following code:             public class Hello {                         private static int main(String [] args) {                                     string Msg=”Hello, Wrld!;                                     Sytem.out.println(msg+ “Ken")
What is the output from each of the following segments of C++ code? Record the output...
What is the output from each of the following segments of C++ code? Record the output after the “Answer” prompt at the end of each program fragment. Assume all variables have been suitably declared. (Each problem is worth 3 points.) 1. for (int j = 8; j > 3; j -= 2)         cout << setw(5) << j;     Answer:      2. int sum = 5;    for (int k = -4; k <= 1; k++)         sum = sum...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT