|
1. Identify the missing statement in the function that follows. a. if (n/i == 0) b. if (n*i == 0) c. if (n%i == 0) d. if (n*i == 0) e. none of the above
bool isPrime1(int n) { if (1 == n) return false; if (2 == n) return true;
for (int i=2; i<=n-1; i++)
... return false;
return true; }
2. Identify the missing statement in the function that follows. a. for (int i=2; i<=n/2; i++) b. for (int i=2; i=n/2; i++) c. for (int i=2; i<n/2; i++) d. for (int i=2; i>=n/2; i++) e. none of the above
bool isPrime2(int n) { if (1 == n) return false; if (2 == n) return true;
... if (n%i == 0) return false;
return true; }
3. Identify the missing statement in the function that follows. a. for (int i=2; i>sqrt(n); i++) b. for (int i=2; i>=sqrt(n); i++) c. for (int i=2; i=sqrt(n); i++) d. for (int i=2; i<=sqrt(n); i++) e. none of the above
bool isPrime3(int n) { if (1 == n) return false; if (2 == n) return true;
... if (n%i == 0) return false;
return true; }
For the questions that follow, assume the following declarations:
const int ARRAY_SIZE = 10; const int UNDEFINED = -9999; const int MAX_VALUE = 99; const int TEST_COUNT = 10;
class CSortedList { private: int m_array[ARRAY_SIZE]; int m_count; int m_min; int m_max; public: CSortedList(void); CSortedList(char ch); CSortedList(int n); void display(void) const; bool insert(int x); bool isSorted(void) const; void sortBubble1(void); void sortBubble2(void); void sortInsertion1(void); void shuffle(void); int searchSeq(int x) const; int searchBinary(int x) const; int searchBinaryLM(int x) const; void displayDistinct(void) const; void displayDistinctWithCounts(void) const; bool remove(int x); int getAt(int p); int getCount(void); bool operator ==(CSortedList list2); };
2. Identify the missing statement in the function that follows. a. int i=0; b. int i=this->m_count; c. i++; d. for (int i=0; i<this->m_count; i--) e. none of the above
bool CSortedList::operator ==(CSortedList list2) { if (this->m_count != list2.m_count) return false;
... if (this->m_array[i] != list2.m_array[i]) return false;
return true; }
3. Identify the missing statement in the function that follows. a. while (true) b. while (!sorted) c. while (false) d. while (sorted=true) e. none of the above
void CSortedList::sortInsertion1(void) { int i, temp; bool sorted = false;
... { sorted = true; for (i=m_count-2; i>=0; i--) { if (m_array[i] > m_array[i+1]) { temp = m_array[i]; m_array[i] = m_array[i+1]; m_array[i+1] = temp; sorted = false; } } //end for }//end while }
4. Identify the missing statement in the function that follows. a. if (p < m_count) b. if (p >= 0) c. if ((p < m_count) || (p >= 0)) d. if ((p < m_count) && (p >= 0)) e. none of the above
int CSortedList::getAt(int p) {
... return this->m_array[p]; else return UNDEFINED; };
5. Identify the missing statement in the function that follows. a. return 1; b. return 0; c. return this->m_count; d. return this->m_count-1; e. none of the above
int CSortedList::getCount(void) {
... };
6. Identify the missing statement in the function that follows. a. this->m_count = 0; b. count = 0; c. m_count = 1; d. this->m_count = 2; e. none of the above
CSortedList::CSortedList(int n) {
... int x;
for (int i=0; i<n; i++) { x = rand()%(MAX_VALUE+1); this->insert(x); } }
7. Identify the missing statement in the function that follows. a. m_array[i] = m_array[i-1]; b. m_array[i] = m_array[i+1]; c. m_array[i+1] = m_array[i]; d. m_array[i-1] = m_array[i]; e. none of the above
bool CSortedList::remove(int x) { int p = searchSeq(x); if (-1 == p) return false;
for (int i=p; i<=m_count-2; i++)
...
this->m_count--; return true; }
8. Identify the missing statement in the function that follows. a. p++; b. p--; c. p=p+1; d. p=p+2; e. none of the above
int CSortedList::searchBinaryLM(int x) const { int p;
p = this->searchBinary(x);
if (-1 == p) return -1;
while((p>0) && (this->m_array[p] == this->m_array[p-1]))
...
return p; }
9. Identify the missing statement in the function that follows. a. mid = m_count/2; b. mid = lower/2; c. mid = upper/2; d. mid = (lower-upper)/2; e. none of the above
int CSortedList::searchBinary(int x) const { int lower, upper, mid;
lower = 0; upper = this->m_count-1;
while (lower <= upper) {
... if (x == this->m_array[mid]) return mid; if (x < this->m_array[mid]) upper = mid-1; if (x > this->m_array[mid]) lower = mid+1; }
return -1; }
10.Identify the missing statement in the function that follows. a. if (x < this->m_array[i]) b. if (x < i) c. if (x <= i) d. if (x > this->m_array[i]) e. none of the above
int CSortedList::searchSeq(int x) const { for (int i=0; i<=this->m_count-1; i++) { if (x == m_array[i]) return i;
... break; }
return -1; }
11.Identify the missing statement in the function that follows. a. this->m_count = 1; b. this->m_count = 0; c. this->m_count = 2; d. this->m_count = 3; e. none of the above
CSortedList::CSortedList(void) {
... this->m_min = UNDEFINED; this->m_max = UNDEFINED; }
12.Identify the missing statement in the function that follows. a. this->m_count = 0; b. this->m_count = 1; c. this->m_count = 2; d. this->m_count = 3; e. none of the above
CSortedList::CSortedList(char ch) {
... int x, n; if ('r' == ch) { n = rand()%ARRAY_SIZE+1; for (int i=0; i<n; i++) { x = rand()%(MAX_VALUE+1); this->insert(x); } } }
13.Identify the missing statement in the function that follows. a. cout << i << ' '; b. cout << this->m_array[i] << ' '; c. cout << this->m_array << ' '; d. cout << this->m_array[i+1] << ' '; e. none of the above
void CSortedList::display(void) const { cout << "SortedList(" << this->m_count << ")= "; for (int i=0; i<this->m_count; i++)
...
cout << endl; }
14.Identify the missing statement in the function that follows. a. x = this->m_array[m_count]; b. this->m_array[m_count] = 0; c. this->m_array[m_count]++; d. this->m_array[m_count] = x; e. none of the above
bool CSortedList::insert(int x) { if (ARRAY_SIZE == this->m_count) return false; else {
... this->m_count++; this->sortInsertion1(); return true; } }
15.Identify the missing statement in the function that follows. a. for (j=0; j<=this->m_count-2; j--) b. for (j=0; j<=this->m_count-2; j++) c. for (j=0; j=this->m_count-2; j++) d. for (j=0; j>=this->m_count-2; j++) e. none of the above
void CSortedList::sortBubble1(void) { int j; for (int i=1; i<=this->m_count-1; i++) {
... { if (this->m_array[j] > this->m_array[j+1]) { int temp = this->m_array[j]; this->m_array[j] = this->m_array[j+1]; this->m_array[j+1] = temp; } } } }
16.Identify the missing statement in the function that follows. a. while (sorted) b. while (sorted=false) c. while (!sorted) d. while (sorted=true) e. none of the above
void CSortedList::sortBubble2(void) { int i, temp; bool sorted = false;
... { sorted = true; for (i= 0; i<=m_count-2; i++) { if (m_array[i] > m_array[i+1]) { temp = m_array[i]; m_array[i] = m_array[i+1]; m_array[i+1] = temp; sorted = false; } } //end for }//end while }
17.Identify the missing statement in the function that follows. a. for (int i=0; i<=this->m_count-2; i--) b. for (int i=0; i<this->m_count-2; i++) c. for (int i=0; i<=this->m_count; i++) d. for (int i=0; i<=this->m_count-2; i++) e. none of the above
bool CSortedList::isSorted(void) const {
... if (this->m_array[i] > this->m_array[i+1]) return false;
return true; }
18.Identify the missing statement in the function that follows. a. for (int i=0; i<=this->m_count-1; i--) b. for (int i=0; i>=this->m_count-1; i++) c. for (int i=0; i<=this->m_count-2; i++) d. for (int i=0; i<=this->m_count+1; i++) e. none of the above
void CSortedList::shuffle(void) { int picked, temp;
... { picked = rand()%this->m_count; temp = this->m_array[0]; this->m_array[0] = this->m_array[picked]; this->m_array[picked] = temp; } }
|