Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Question 1 ( 1 2 points ) What is output by the code below? int gRay [ 1 0 ] ; gRay [ 0 ]

Question 1(12 points)
What is output by the code below?
int gRay[10];
gRay[0]=33;
gRay[1]=14;
gRay[2]=37;
gRay[3]=11;
gRay[4]=27;
cout << gRay.length();
Question 1 options:
a)
4
b)
11
c)
error
d)
9
e)
10
Question 2(11 points)
Which of the following lines would correctly fill
/* code */ in function getIt()?
//method getIt should return the sum of all numbers in array
int getIt(int array[], int length)
{
int z=0;
for(int spot=0; spot < length; spot++)
{
/* code */
}
return z;
}
Question 2 options:
a)
z = z + array[spot-1];
b)
z = z + array[spot+1];
c)
z = z + array[spot];
d)
z = z + spot;
Question 3(11 points)
What will be printed?
void changeArray( int a [], int len )
{
for (int i =0; i < len; i++)
a[i]= a[i]/3;
}
//** back in the main method
int arr []={56,20,6,0,-35,-95,70,12};
int len =8;
changeArray(arr,len);
cout << arr[7]<<"";
Your Answer:
Question 3 options:
Answer
Question 4(11 points)
What is the value of alpha[2] after the following code executes?
int alpha[5];
int j;
for (j =0; j <5; j++)
alpha[j]=2* j +1;
Question 4 options:
a)
6
b)
4
c)
5
d)
1
Question 5(11 points)
The word const is used before the array declaration in a function heading to allow the function to modify the array.
Question 5 options:
True
False
Question 6(11 points)
Suppose that list is an array of 10 components of type int. Which of the following codes correctly outputs all the elements of list?
Question 6 options:
a)
for (int j =0; j <=9; j++)
cout << list[j]<<"";
cout << endl;
b)
for (int j =1; j <=10; j++)
cout << list[j]<<"";
cout << endl;
c)
for (int j =1; j <11; j++)
cout << list[j]<<"";
cout << endl;
d)
for (int j =1; j <10; j++)
cout << list[j]<<"";
cout << endl;
Question 7(11 points)
Suppose that gamma is an array of 50 components of type int and j is an int variable. Which of the following for loops sets the index of gamma out of bounds?
Question 7 options:
a)
for (j =0; j <=50; j++)
cout << gamma[j]<<"";
b)
for (j =0; j <=49; j++)
cout << gamma[j]<<"";
c)
for (j =0; j <=48; j++)
cout << gamma[j]<<"";
d)
for (j =1; j <50; j++)
cout << gamma[j]<<"";
Question 8(11 points)
Suppose list is a one dimensional array of size 25, wherein each component is of type int. Further, suppose that sum is an int variable. The following for loop correctly finds the sum of the elements of list.
sum =0;
for (int i =0; i <25; i++)
sum = sum + list;
Question 8 options:
True
False
Question 9(11 points)
Given two arrays of integers (arr1 & arr2) with identical lengths, the following if statement will determine if the arrays have the same values.
if (arr1== arr2)
Question 9 options:
True
False

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions