Code segment:
int num = 0;
int a = 10, b = 20, c = 20, d = 30, x = 40;
switch(num){
case 102: // case 102 to 105 handles the first if statement
case 103:
case 104:
case 105: a += 1;
break;
case 208: b += 1; // handles the second else if statement
x = 8;
break;
case 209: c = c*3; // handles the third else if statement
break;
default: d += 1004; // handles the last else statement
}
Note: Please refer to the screenshot below to understand the indentation of the code segment.
Screenshot:
QUESTION 18 Rewrite this if/else if code segment into a switch statement int num = 0;...
C programming Rewrite the following code replacing the else-if construct with a switch statement. Make sure you test your code. Supplied code #include <stdio.h> int main(void) { char ch; int countA = 0; int countE = 0; int countI = 0; printf("Enter in a letter A, E, or I.\n"); scanf(" %c", &ch); //Replace the following block with your switch if(ch == 'E' || ch == 'e') countE++; else if(ch == 'A' || ch == 'a') countA++; else if(ch == 'I'...
20) What is the output of the following segment of C code: int avg(int n, int* a); int main () { int array[4]={1,0,6,9}; printf("%d", avg(4, array)+ 1); system("pause"); return 0; } int avg(int n, int* a) { int i, sum=0; for (i=0;i<n;i++) { sum+=a[i]; } return sum/n; } a) 16 b) 5 c) 4 d) 8 21) What is the output of the following segment of C code: int x = 2; int y = 3;...
Rewrite the following highlighted if...else section using a switch. Only rewrite the code that you need to change, not the entire code. #include #include #define TRUE 1 #define FALSE 0 int main(void ) { enum Pops{ Coke = 1, Pepsi, Root_Beer, Grape, Seven_Up, Mountain_Dew, Dr_Pepper, Orange }; int PopSelection, DietStyle; float Price; printf( "Please enter your favourite pop: \n"); printf( "1. Coke\ n"); printf( "2. Pepsi \n" ); printf( "3. Root Beer\ n"); printf( "4. Grape \n" ); printf( "5....
39. Rewrite the following C code segment in x86 (assume bs kebx) x86 switch (b) case 1 case 2: case 3: default: return Walpha" return "beta" return gamma" return "delta" 40. Does the following function definition qualfy as a leaf function? Why or why not? int quadratic(int x, int a, int b, int c) return a square (x) b 41. Assuming the GCC calling conventions are being used, what instructions always start the prolog of a function? 42. Assuming the...
18 C++ 1. What is the output of the following program segment? int y-22: while ((y 3) != 0) cout << y<< "": y=y-2; The output is 2. Suppose that the input is 100, 20,-8, 50, 20. What is the output of the following C++ code? int sum0 int num: int j cin >> num: if (num < 0) continue зит зит + num; cout<< sum << endl; The output is
QUESTION 1 What will be displayed as a result of executing the following code? int x = 5, y = 20; x += 32; y /= 4; cout <<"x = " << x <<"y = " << y; A. x = 32, y = 4 B. x = 9, y = 52 C. x = 37, y = 5 D. x = 160, y = 80 8 points QUESTION 2 What will be the displayed when the following code...
I have this code for python: num = int(input()) if num == 0: print('No change') else: dol = num // 100 num %= 100 Quarters = num // 25 num %= 25 Dimes = num // 10 num %= 10 Nickels = num // 5 num %= 5 Pennies = num if dol > 0: if dol == 1: print('1 Dollar') if Dollars > 1: print(dol,'Dollars') if Quarters > 0: if Quarters == 1: print('1 Quarter') if Quarters > 1:...
31. The following code segment is syntactically correct: int number{20}; cout << number << setbase(16) << " " << number << setbase(10) << " " << number << showpos << " " << number << endl; T__ F__ 32. The following statement wants to determine if ‘count’ is outside the range of 0 through 100: if (count < 0 && count > 100) T__ F__ 33. There is...
A) Rewrite the following pseudocode segment in C++ using the loop structures (for and while). Assume that all the variables are declared and initialized. k-G+ 13)/27 loop: if k> 10 then goto out k=k+1 i=3"k-1 goto loop I out: B) Rewrite the following code segment in C++ using the multiple-selection (switch and if-else) statements. Assume that all the variables are declared and initialized. if((k 1) || (k 2))j-2 k-1 if ((k 3) || ( ks))j - 3.k+1 if (k 4)j-4k-1...
What is the output of the following C++ code? int count = 1; int num = 25; while (count < 25) { num--; count++; } cout << count « " " « num << endl i 25 1 0 24 1 0 25 0 0 24 0 In this while loop statement, while (counter < 10), where counter is an int variable. Which statement below is an equivalent way to write this while statement? while (10 < counter) while (9...