C++ Help: Given the following code int num[30] = {2, 4, 6, 9, 5, -1, 7, 10}; Show the value of: a. num[3] + num[4] b. num[6] c. num[9] + 1 d. num[30]
In c++
array index starts from 0
so num[0] will give the first element of array named num so num[0] = 2 that is first element of array .
similarly num[1] will give the second element of the array named num . so num[1] = 4
now
(A) num[3] + num[4] will add index numbered 3 and 4 element of array num .
now num[3] = 9 and num[4] = 5
so num[3] + num[4] will gve 9+5 = 14
now for part B
num[6] will give the element at the 6th index in array num which is equal 7
now for part c
since array size given is 30 and only 8 elements has been initialized . By default the remaining 22 elements ( 30 - 8) will
be implicitly initialized with value 0 .
we have num[9] + 1 . Now num[9] value will be by default 0 so adding( 0 + 1 ) result will be 1 .
now D
array size given is 30 elements int num[30]. so the valid index will be from 0 to 29 . so accessing array index 30 will display any garbage value which might be present in location of num(30).
C++ Help: Given the following code int num[30] = {2, 4, 6, 9, 5, -1, 7,...
Given the following function: int fun1(int count){ int Num ; for (i = 0; i < count; ++i) { cin >> Value; if (i == 0) Num = Value; else if (Value > Num) Num = Value; } return Num ; } What is the output of the following C++ code segment if the following list is entered? (Input list: 5 -15 -90 -2 -60 -30) int Num = 0 , Value, numValues; cin >> numValues; if (numValues > 0) cout...
Consider the following code segment. int[]arr={1, 2, 3, 4, 5, 6, 7, 8}; for(int k=3; k<arr.length-1; R++ arr[k]-arr[k+1]; What are the contents of arr as a result of executing the code segment? a. {1, 2, 3, 5, 6, 7, 8, 8) b. {2, 2, 4, 5, 6, 7, 8, 8} C. {2, 4, 6, 5, 6, 7, 8,8} d. {4, 2, 4, 4, 6, 7, 8, 8) e. {6, 6, 4, 5, 6, 7, 8, 8} int) arr={7, 2.5, 3.0,...
What is the value of result after the following code executes? int a = 60; int b = 15; int result = 20; if (a = b) result *= 3; 30 20 60 10 code will not execute The numeric data types in C++ can be broken into two general categories which are integers and floating-point numbers singles and doubles real and unreal numbers numbers and characters numbers and literals Which line in the following program will cause a compiler error?...
What is the output of the following code? #include« stdio.h» 2 4 int main() 6 int a=15,b=12,c=5, d-e; 7 printf("the value of d is %d",d); return 0; 8 9 10 Ly 0 29 O 30 0 28 O 31
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...
public static boolean primeCheck (int num) int temp; boolean isPrime-true: for(int i-2;i<=num/ 2 ; i++) temp-numsi if (temp=-0) isPrime-false; break; return isPrime Given the above code segment, 1. (30 points) Draw a Control Flow Graph (CFG) for the code. 2. (10 points) Enumerate the Test Requirements for node coverage. Design a set of 3. 4. 5. test cases (input value num) that will satisfy node coverage. (10 points) Enumerate the Test Requirements for edge coverage. Design a set of test...
1. What is the output? System.out.print(3 + 3 * 3); a. 18 b. 12 c. 9 d. 0 e. 10 2. What is output by the code below? System.out.print("\\dog\\cat"); a. dog b. dogcat c. \\dog\\cat d. \dog\cat e. catdog\\\\ 3. What is returned by the call getIt(9) ? public static int getIt(int num){ int ans = 0; if( num >=2 ) { if( num >= 7) ans += 2; else ans += 3; } ans += 4; return ans; }...
What is the output of the following code? int num = 17; //Line 1 double gpa = 3.85; //Line 2 bool done; //Line 3 done = (num == static_cast<int>( (2 * gpa + 9.3))); //Line 4 cout << "The value of done is: "<< done << endl; //Line 5
Given the following code segment, int x = 20; int y = 7; what is the data type of the value of the expression (x % y) ? (3 points) Question 1 options: 1) int 2) double 3) numeric 4) Error: possible loss of precision 5) Unable to be determined Question 2 (3 points) Given the following code segment, double x = 42.3; double y = 11.7; what is the data type of the value of the expression (x %...
1. What is the output of the following code segment? int array[] = { 8, 6, 9, 7, 6, 4, 4, 5, 8, 10 }; System.out.println( "Index Value" ); for ( int i = 0; i < array.length; i++ ) System.out.printf( "%d %d\n", i, array[ i ] ); 2. What is the output of the following code segment? char sentence[] = {'H', 'o', 'w', ' ', 'a', 'r', 'e', ' ', 'y', 'o', 'u' }; String output = "The sentence...