|
CSIS 250 2003 Fall Test02 Incorrect choices could be due to logical, execution, or syntax errors.
Assume the following declarations/definitions for the problems that follow.
const int MAX_SIZE = 25; const int TEST_COUNT = 19; const int MAX_VALUE = 15; const int UNDEFINED = -911;
1. Identify the missing statement/line in the following function. a) deleted=0; b) deleted--; c) deleted++; d) deleted=1; e) None of the above
int deleteDupes(int a[], int &n) { int p, deleted=0;
do { p = -1;
for (int i=0; i<=n-2; i++) if (a[i] == a[i+1]) { p = i+1; deleteAtPos(a, n, p); ...
break; }
} while (p != -1);
return deleted; }
2. Identify the missing statement/line in the following function. a) a[n] = UNDEFINED; b) a[n+1] = UNDEFINED; c) a[n-1] = UNDEFINED; d) a[1] = UNDEFINED; e) None of the above
bool deleteAtPos(int a[], int &n, int p) { if (p<0 || p>=n) return false; else { for (int i=p; i<=n-2; i++) a[i] = a[i+1];
...
n--; return true; } }
3. Identify the missing statement/line in the following function. a) swap(a[i], a[i-1]); b) swap(a[i], a[i+1]); c) swap(a[j], a[i+1]); d) swap(a[i], a[j+1]); e) None of the above
void sortBubble(int a[], int n) { int swaps; do { swaps = 0; for (int i=0; i<=n-2; i++) if (a[i] > a[i+1]) { ...
swaps++; }
} while (swaps!=0);
}
4. Identify the missing statement/line in the following function. a) insert(a, n, x); b) insert(a, n-1, x); c) insert(a, m-1, x); d) insert(a, m, x); e) None of the above
void populate(int a[], int n) { int m=0; for (int i=1; i<=n; i++) { int x = rand()%(MAX_VALUE+1); ...
} }
5. Identify the missing statement/line in the following function. a) swap (a[0], a[pick]); b) return; c) a[0] = a[pick]; d) a[pick] = a[0]; e) None of the above
void shuffle(int a[], int n) { for (int i=1; i<=n*n; i++) { int pick = rand()%n; ...
} }
6. Identify the missing statement/line in the following function. a) for (int i=1; i<=n-2; i++) b) for (int i=0; i<=n; i++) c) for (int i=1; i<=n-1; i++) d) for (int i=0; i<=n-2; i++) e) None of the above
bool isSorted(int a[], int n) { ...
if (a[i] > a[i+1]) return false;
return true; }
7. Identify the missing statement/line in the following function. a) temp = x; b) int x = temp; c) int temp = x; d) int temp; e) None of the above
void swap(int &x, int &y) { if (x != y) { ...
x = y; y = temp; } }
8. Identify the missing statement/line in the following function. a) a[1] = x; b) a[2] = x; c) a[3] = x; d) a[n] = x; e) None of the above
bool insert(int a[], int &n, int x) { if (0 == n) { ...
n++; return true; };
if (MAX_SIZE == n) return false;
if (n > 0) { a[n] = x; n++;
for (int i=n-1; i>=1; i--) { if (a[i] >= a[i-1]) return true; swap(a[i], a[i-1]); }
return true; }
return false; }
9. Identify the missing statement/line in the following function. a) for (int i=1; i<=n-1; i++) b) for (int i=0; i<=n-1; i++) c) for (int i=0; i<=n; i++) d) for (int i=1; i<=n-2; i++) e) None of the above
void initialize(int a[], int n) { ...
a[i] = UNDEFINED; }
10. Identify the missing statement/line in the following function. a) for (int i=1; i<=n-1; i++) b) for (int i=0; i<=n-1; i++) c) for (int i=0; i<=n; i++) d) for (int i=1; i<=n-2; i++) e) None of the above
void display(int a[], int n) { cout << "a[" << n << "]: "; ...
cout << a[i] << ' ';
cout << endl; }
Assume the following declarations/definitions for the problems that follow.
const int MAX_SIZE = 10; const int TEST_COUNT = 25; const int MAX_VALUE = 15; const int UNDEFINED = -911;
class COList { private: int a[MAX_SIZE]; int n; void swap(int &x, int &y); public: COList(void); void display(void) const; void initialize(void); bool insert(int x); bool isSorted(void) const; void shuffle(void); void sortBubble(void); void populate(int n); COList(char ch); friend bool isEqual(const COList &thisList, const COList &thatList); bool isEqual(const COList &thatList) const; bool operator ==(const COList &thatList) const; COList(const COList &givenList); int searchSequential(int x) const; friend COList fUnion(const COList &thisList, const COList &thatList); COList fUnion(const COList &thatList) const; COList operator +(const COList &thatList) const; COList operator *(const COList &thatList) const; COList operator -(const COList &thatList) const; friend ostream & operator << (ostream &bob, const COList &aList); bool hasDistinct(void) const; bool deleteAtPos(int p); int deleteDupes(void); int deleteDupes2(void); int deleteDupes3(void); int deleteDupes3r(void); COList & operator = (const COList &thatList); COList(int n); friend void merge(COList &fList, COList iLists[], int m); bool operator < (const COList &bList); void pointerGame(void); };
11. Identify the missing statement/line in the following function. a) return this; b) return false; c) return true; d) return NULL; e) None of the above
bool COList::operator < (const COList &bList) { for (int i=0; i<=this->n-1; i++) { int x = this->a[i]; if (bList.searchSequential(x) == UNDEFINED) return false; }
...
}
12. Identify the missing statement/line in the following function. a) this->populate(n); b) this->populate(); c) this->populate(123); d) this->populate(0); e) None of the above
COList::COList(int n) { this->initialize(); ...
}
13. Identify the missing statement/line in the following function. a) this->n = n; b) this.n = thatList.n; c) this->n = thatList.n; d) this*n = thatList.n; e) None of the above
COList & COList::operator = (const COList &thatList) { for (int i=0; i<=MAX_SIZE-1; i++) this->a[i] = thatList.a[i];
...
return *this; }
14. Identify the missing statement/line in the following function. a) int tList; b) tList = 0; c) tList = empty; d) n = 0; e) None of the above
COList COList::operator + (const COList &thatList) const { ...
int i;
for (i=0; i<=this->n-1; i++) if (tList.searchSequential(this->a[i]) == UNDEFINED) tList.insert(this->a[i]);
for (i=0; i<=thatList.n-1; i++) if (tList.searchSequential(thatList.a[i]) == UNDEFINED) tList.insert(thatList.a[i]);
return tList; }
15. Identify the missing statement/line in the following function. a) int tList; b) tList = 0; c) tList = empty; d) n = 0; e) None of the above
COList COList::fUnion(const COList &thatList) const { ...
int i;
for (i=0; i<=this->n-1; i++) if (tList.searchSequential(this->a[i]) == UNDEFINED) tList.insert(this->a[i]);
for (i=0; i<=thatList.n-1; i++) if (tList.searchSequential(thatList.a[i]) == UNDEFINED) tList.insert(thatList.a[i]);
return tList; }
16. Identify the missing statement/line in the following function. a) int tList; b) tList = 0; c) tList = empty; d) n = 0; e) None of the above
COList fUnion(const COList &thisList, const COList &thatList) { ...
int i;
for (i=0; i<=thisList.n-1; i++) if (tList.searchSequential(thisList.a[i]) == UNDEFINED) tList.insert(thisList.a[i]);
for (i=0; i<=thatList.n-1; i++) if (tList.searchSequential(thatList.a[i]) == UNDEFINED) tList.insert(thatList.a[i]);
return tList;
}
17. Identify the missing statement/line in the following function. a) for (int i=n; i<=n+deleted-1; i++) b) for (int i=0; i<=n+deleted-1; i++) c) for (int i=1; i<=n+deleted-1; i++) d) for (int i=n; i<=n-deleted-1; i++) e) None of the above
int COList::deleteDupes3r(void) { int p1, p2, deleted;
deleted = 0; p1 = 0; p2=p1+1;
while (p2 <= n-1) if (a[p1] == a[p2]) { p2++; deleted++; } else { p1++; a[p1] = a[p2]; p2++; }
n = n - deleted;
...
a[i] = UNDEFINED;
return deleted; }
18. Identify the missing statement/line in the following function. a) while (p2 <= 1) b) while (p2 <= -1) c) while (p2 <= n-1) d) while (p1 <= n-1) e) None of the above
int COList::deleteDupes3(void) { if (n<=1) return 0;
int deleted, distinctCount=1, p1 = 0, p2=p1+1; ...
if (a[p1] == a[p2]) a[p2++] = UNDEFINED; else { a[++p1] = a[p2++]; distinctCount++; }
deleted = n - distinctCount; n = distinctCount; return deleted; }
19. Identify the missing statement/line in the following function. a) while (p<=2) b) while (p<=n-2) c) while (p<=-2) d) while (p<=n) e) None of the above
int COList::deleteDupes2(void) { int p=0, deleted=0; ...
if (a[p+1] == a[p]) deleteAtPos(p+1), deleted++; else p++;
return deleted; }
20. Identify the missing statement/line in the following function. a) for (int i=0; i<=n-2; i++) b) for (int i=1; i<=n-2; i++) c) for (int i=2; i<=n-2; i++) d) for (int i=3; i<=n-2; i++) e) None of the above
int COList::deleteDupes(void) { int p, deleted=0;
do { p = -1;
...
if (a[i] == a[i+1]) { p = i+1; this->deleteAtPos(p); deleted++; break; }
} while (p != -1);
return deleted; }
21. Identify the missing statement/line in the following function. a) for (int i=p; i<=n-2; i++) b) for (int i=0; i<=n-2; i++) c) for (int i=1; i<=n-2; i++) d) for (int i=2; i<=n-2; i++) e) None of the above
bool COList::deleteAtPos(int p) { if (p<0 || p>=n) return false; else { ...
a[i] = a[i+1];
a[n-1] = UNDEFINED; n--; return true; } }
22. Identify the missing statement/line in the following function. a) if (this->a[i] == this->a[i-1]) b) if (this->a[i] == this->a[i+1]) c) if (this->a[i] == this->a[i+2]) d) if (this->a[i] == this->a[i]) e) None of the above
bool COList::hasDistinct(void) const { for (int i=0; i<=this->n-2; i++) ...
return false;
return true; }
23. Identify the missing statement/line in the following function. a) for (int i=0; i<=MAX_SIZE; i++) b) for (int i=1; i<=MAX_SIZE-1; i++) c) for (int i=2; i<=MAX_SIZE-1; i++) d) for (int i=0; i<=MAX_SIZE-1; i++) e) None of the above
ostream & operator << (ostream &bob, const COList &aList) { bob << "a[" << aList.n << "]: "; ...
bob << aList.a[i] << ' ';
return bob; }
24. Identify the missing statement/line in the following function. a) thisList.insert(x); b) tempList.insert(x); c) thatList.insert(x); d) firstList.insert(x); e) None of the above
COList COList::operator -(const COList &thatList) const { COList tempList; int x;
for (int i=0; i<=this->n-1; i++) { x = this->a[i]; if (thatList.searchSequential(x) == UNDEFINED) if (tempList.searchSequential(x) == UNDEFINED) ...
}
return tempList; }
25. Identify the missing statement/line in the following function. a) if (thisList.searchSequential(x) != UNDEFINED) b) if (tList.searchSequential(x) != UNDEFINED) c) if (tempList.searchSequential(x) != UNDEFINED) d) if (thatList.searchSequential(x) != UNDEFINED) e) None of the above
COList COList::operator *(const COList &thatList) const { COList tempList; int x;
for (int i=0; i<=this->n-1; i++) { x = this->a[i]; ...
if (tempList.searchSequential(x) == UNDEFINED) tempList.insert(x); }
return tempList; }
26. Identify the missing statement/line in the following function. a) for (int i=1; i<=this->n-1; i++) b) for (int i=2; i<=this->n-1; i++) c) for (int i=-1; i<=this->n-1; i++) d) for (int i=0; i<=this->n-1; i++) e) None of the above
int COList::searchSequential(int x) const { ...
if (x == a[i]) return i;
return UNDEFINED; }
27. Identify the missing statement/line in the following function. a) for (int i=0; i<=MAX_SIZE-1; i++) b) for (int i=1; i<=MAX_SIZE-1; i++) c) for (int i=2; i<=MAX_SIZE-1; i++) d) for (int i=3; i<=MAX_SIZE-1; i++) e) None of the above
COList::COList(const COList &oldList) { this->n = oldList.n; ...
this->a[i] = oldList.a[i]; }
28. Identify the missing statement/line in the following function. a) if (this->n = thatList.n) b) if (this->n === thatList.n) c) if (this->n > thatList.n) d) if (this->n != thatList.n) e) None of the above
bool COList::operator ==(const COList &thatList) const { ...
return false;
for (int i=0; i<=this->n-1; i++) if (this->a[i] != thatList.a[i]) return false;
return true; }
29. Identify the missing statement/line in the following function. a) if (this->n = thatList.n) b) if (this->n === thatList.n) c) if (this->n > thatList.n) d) if (this->n != thatList.n) e) None of the above
bool COList::isEqual(const COList &thatList) const { ...
return false;
for (int i=0; i<=this->n-1; i++) if (this->a[i] != thatList.a[i]) return false;
return true; }
30. Identify the missing statement/line in the following function. a) if (thisList.n == thatList.n) b) if (thisList.n != thatList.n) c) if (thisList.n = thatList.n) d) if (thisList.n > thatList.n) e) None of the above
bool isEqual(const COList &thisList, const COList &thatList) { ...
return false;
for (int i=0; i<=thisList.n-1; i++) if (thisList.a[i] != thatList.a[i]) return false;
return true; }
31. Identify the missing statement/line in the following function. a) this->initialize(); b) n = 0; c) n-1 = 0; d) int n; e) None of the above
COList::COList(char ch) { ...
int n = rand()%(MAX_SIZE+1); (*this).populate(n); }
32. Identify the missing statement/line in the following function. a) if (x != y) b) if (x = y) c) if (x == y) d) if (x > y) e) None of the above
void COList::swap(int &x, int &y) { ...
{ int temp = x; x = y; y = temp; } };
33. Identify the missing statement/line in the following function. a) k = 0; b) swaps++; c) return swaps; d) swaps = 0; e) None of the above
void COList::sortBubble(void) { int swaps; do { swaps = 0; for (int i=0; i<=n-2; i++) if (a[i] > a[i+1]) { swap(a[i], a[i+1]); ...
}
} while (swaps!=0);
}
34. Identify the missing statement/line in the following function. a) pick = rand()%n; b) pick = rand()%n + 2; c) int pick = rand()%n; d) int pick = rand() + n; e) None of the above
void COList::shuffle(void) { for (int i=1; i<=n*n; i++) { ...
swap (a[0], a[pick]); }
}
35. Identify the missing statement/line in the following function. a) for (int i=1; i=n; i++) b) for (int i=1; i<=n; i++) c) for (int i=1; i==n; i++) d) for (int i=1; i<=m; i++) e) None of the above
void COList::populate(int n) { ...
{ int x = rand()%(MAX_VALUE+1); (*this).insert(x); } }
36. Identify the missing statement/line in the following function. a) for (int i=1; i<=n-2; i++) b) for (int i=0; i<=n-2; i++) c) for (int i=0; i<=n-1; i++) d) for (int i=0; i<=n; i++) e) None of the above
bool COList::isSorted(void) const { ...
if (a[i] > a[i+1]) return false;
return true; }
37. Identify the missing statement/line in the following function. a) a[i] = UNDEFINED; b) a[i] = a[i+1]; c) a[i] = a[i-1]; d) a[i-1] = a[i+1]; e) None of the above
void COList::initialize(void) { for (int i=0; i<=MAX_SIZE-1; i++) ...
n = 0; }
38. Identify the missing statement/line in the following function. a) a[n] = x; b) a[1] = x; c) a[2] = x; d) a[3] = x; e) None of the above
bool COList::insert(int x) { if (0 == n) { ...
n++; return true; };
if (MAX_SIZE == n) return false;
if (n > 0) { a[n] = x; n++;
for (int i=n-1; i>=1; i--) { if (a[i] >= a[i-1]) return true; swap(a[i], a[i-1]); }
return true; }
return false;
}
39. Identify the missing statement/line in the following function. a) for (int i=1; i<=n-1; i++) b) for (int i=0; i<=n-1; i++) c) for (int i=0; i<=n; i++) d) for (int i=0; i<=n+1; i++) e) None of the above
void COList::display(void) const { cout << "a[" << n << "]: "; ...
cout << a[i] << ' ';
cout << endl; }
40. Identify the missing statement/line in the following function. a) initialize(); b) n=0; c) n=1; d) n=2; e) None of the above
COList::COList(void) { ...
}
Assume the following declarations/definitions for the problems that follow.
const unsigned int BASE = 10; const unsigned int MIN_VALUE = 0; const unsigned int MAX_VALUE = BASE-1; const unsigned int MAX_EXPO = 4; const unsigned int UNDEFINED = 911; const int MAX_SIZE = 10; const int TEST_COUNT = 25;
class CDigit { private: CDigit *_prev; unsigned int _coef; unsigned int _expo; CDigit *_next; public: CDigit(void); CDigit(char ch); CDigit(const CDigit &d2); CDigit(unsigned int coef); CDigit(unsigned int coef, unsigned int expo);
void display(void) const; void displayAll(void) const; void init(void);
bool operator == (const CDigit &d2) const; bool operator != (const CDigit &d2) const; friend class CBigInt; };
class CBigInt { private: CDigit *_first; CDigit *_last; unsigned int _count; public: CBigInt(void); void display(void) const; void displayAll(void) const; void init(void); bool insert(CDigit x); };
41. Identify the missing statement/line in the following function. a) CDigit p; b) CDigit &p; c) CDigit *p; d) CDigit& p; e) None of the above
bool CBigInt::insert(CDigit x) { ...
p = new CDigit; if (NULL == p) return false;
p->_coef = x._coef; p->_expo = x._expo;
if (NULL == this->_first) { this->_first = this->_last = p; this->_count = 1; } else { p->_prev = this->_last; this->_last->_next = p; this->_last = p; this->_count++; }
return true; }
42. Identify the missing statement/line in the following function. a) while (p!=NULL) b) while (p=NULL) c) while (p==NULL) d) while (q=NULL) e) None of the above
void CBigInt::display(void) const { CDigit *p;
p = _first;
...
{ p->display(); p = p->_next; } }
43. Identify the missing statement/line in the following function. a) while (p!=NULL) b) while (p=NULL) c) while (p==NULL) d) while (q=NULL) e) None of the above
void CBigInt::displayAll(void) const { CDigit *p; p = _first; ...
{ p->displayAll(); p = p->_next; } }
44. Identify the missing statement/line in the following function. a) count = 0; b) _count = 0; c) count = 1; d) _count = 1; e) None of the above
CBigInt::CBigInt(void) { _first = NULL; _last = NULL; ...
}
45. Identify the missing statement/line in the following function. a) this=init(); b) this.init(); c) this*init(); d) this->init(); e) None of the above
CDigit::CDigit(unsigned int coef, unsigned int expo) { if (coef<=MAX_VALUE && coef>=MIN_VALUE) _coef = coef; else if (coef>MAX_VALUE) _coef = MAX_VALUE; else if (coef<MIN_VALUE) _coef = MIN_VALUE;
if (expo<=MAX_EXPO && expo>=0) _expo = expo; else if (expo<0) _expo = 0; else if (expo>MAX_EXPO) _expo = MAX_EXPO;
...
}
46. Identify the missing statement/line in the following function. a) this=init(); b) this->init(); c) this.init(); d) this*init(); e) None of the above
CDigit::CDigit(unsigned int coef) { if (coef<=MAX_VALUE && coef>=MIN_VALUE) _coef = coef; else if (coef>MAX_VALUE) _coef = MAX_VALUE; else if (coef<MIN_VALUE) _coef = MIN_VALUE;
_expo = 0; ...
}
47. Identify the missing statement/line in the following function. a) return !(*this == d2); b) return (*this == d2); c) return (*this = d2); d) return !(*this = d2); e) None of the above
bool CDigit::operator != (const CDigit &d2) const { ...
}
48. Identify the missing statement/line in the following function. a) return (_coef==d2._coef && _expo==d2._expo); b) return (_coef==d2._coef || _expo==d2._expo); c) return !(_coef==d2._coef && _expo==d2._expo); d) return !(_coef==d2._coef || _expo==d2._expo); e) None of the above
bool CDigit::operator == (const CDigit &d2) const { ...
}
49. Identify the missing statement/line in the following function. a) this->_prev = p; b) this->_prev = NULL; c) _prev = p; d) _prev != NULL; e) None of the above
void CDigit::init(void) { ...
this->_next = NULL; }
50. Identify the missing statement/line in the following function. a) this->init(NULL); b) this->init(x); c) this->init(); d) this->init(q); e) None of the above
CDigit::CDigit(const CDigit &d2) { this->_coef = d2._coef; this->_expo = d2._expo; ...
}
51. Identify the missing statement/line in the following function. a) this->init(NULL); b) this->init(x); c) this->init(q); d) this->init(); e) None of the above
CDigit::CDigit(char ch) { if ('r'==ch || 'R'==ch) { this->_coef = rand()% (MAX_VALUE-MIN_VALUE+1)+MIN_VALUE; this->_expo = rand()%MAX_EXPO; this->init(); } else { this->_coef = UNDEFINED; this->_expo = UNDEFINED; ...
} }
52. Identify the missing statement/line in the following function. a) cout << this->_coef << ' '; b) cout << *this->_coef << ' '; c) cout << this._coef << ' '; d) cout << this*_coef << ' '; e) None of the above
void CDigit::displayAll(void) const { cout << '@' << this << "="; cout << '[' << this->_prev << ' '; ...
cout << this->_expo << ' '; cout << this->_next << ']'; }
53. Identify the missing statement/line in the following function. a) cout << this*_coef; b) cout << this->_coef; c) cout << this-_coef; d) cout << this._coef; e) None of the above
void CDigit::display(void) const { ...
}
54. Identify the missing statement/line in the following function. a) this->init(); b) init(5); c) this->init(5); d) this->init(NULL); e) None of the above
CDigit::CDigit(void) { this->_coef = UNDEFINED; this->_expo = UNDEFINED; ...
}
|