Professional Documents
Culture Documents
مؤشرات PDF
مؤشرات PDF
مؤشرات PDF
Sample Test
1. Using the following declarations for each part, identify the output.
(b) py = px;
*py += *px * y;
cout << x: // output = _______________
(e) pa++;
cout << *++pa; // output = _______________
(f) pa += 2;
*pa += 3;
cout << *pa; // output = _______________
(c) Which assignment statement gives r the same dimensions as the dynamically allocated rectangle
(i) r = rectPtr; (ii) r = new rectangle(*rectPtr);
(iii) r = *rectPtr; (iv) *r = *rectPtr;
*px = 58;
*py += 6; Resulting value of x _________ of y:________
6. Assume we have dynamically allocated an array arr of 50 doubles. Which statement will deallocate these
memory locations?
(a) delete double arr(50); (b) delete [] arr; (c) delete arr[]; (d) delete double[] arr;
7. In class testClass the member function f() doubles the current value of intData and returns a reference to
itself.
class testClass
{
public:
...
testClass& f();
private:
int intData;
};
8. Use the following declaration for each part (a)-(d). Fill in the value for *p and *q.
(a) *p = *q * 2 *p = _____
(b) *q += 8 *q = _____
(c) (*q)++ *q = _____
(d) q=p *p = _____ *q = _____
10. Apply the function f() for parts (a) and (b).
Contents
Contents
(a) Which statement dynamically allocates a vector object that initially contains 8 elements?
(i) p = new vector<int>[8]; (ii) *p = vector<int>(8);
(iii) p = new vector<int>(8); (iv) *p = new vector<int>(8);
(b) Which statement inserts the value 5 at the rear of the vector?
(i) (p->push_back)(5) (ii) *p->push_back(5);
(iii) (*p.push_back)(5) (iv) p->push_back(5);
(a) The constructor allocates dynamic memory for the data member and assigns it the value v. Which
statement is part of the implementation for the constructor?
(i) *ptr = new dynStoreMax <T>(v); (ii) ptr = new dynStoreMax <T>(v);
(iii) *ptr = new T (v); (iv) ptr = new T(v);
(b) What is the value of ptr in part (a) if the heap does not have sufficient memory? __________________
(d) Complete the implementation of the function ~dynStoreMax () assuming inline code.
~ dynStoreMax ()
{ ______________________________________________; }
(e) What is the name for the function dynStoreMax (const dynStoreMax <T>& obj)?
______________________________
(f) Which pair of statements provides the implementation for the overloaded assignment operator?
(i) *ptr = rhs.ptr; (ii) ptr = rhs.ptr;;
return *this; return *this;
(iii) *ptr = *rhs.ptr; (iv) *ptr = rhs.*ptr;;
return *this; return *this;
d.update(t);
13. Which statement(s) dynamically allocates an object of type demo whose members have the initial values 1 and
"cat"?
المؤشرات/ ++ مراجعة لمادة سي
محمد محمود أبوشقير.د
class demo
{
public:
int data;
string name;
14. A sequence of statements use miniVector objects vA and vB. Assume the statements execute sequentially
so that you must use the results from all previous statements to determine the size and the capacity of the
miniVector object after executing the current statement.
15. Correct any syntax error in the declaration of the vector or miniVector object.
(a) vector<vector<int>> table
16. The following is a 4 by 4 table of integer values with the row and column labels in bold.
0 1 2 3
0 5 8 7 -1
1 3 0 2 9
2 -4 7 6 2
3 1 0 7 4
(b) Assuming mat has the integer values above, what is the output from writeVector(mat[1])?
________________________________________
المؤشرات/ ++ مراجعة لمادة سي
محمد محمود أبوشقير.د
17. The word deque is a abbreviation for ___________________________________________________-
int arr[25];
19. Assume a programmer does not explicitly provide a copy constructor in the declaration of the dynamic
class dynClass. The runtime system then calls the class constructor in the following declaration of objects
dA and dB.
For Questions 21 and 22, add the member functions insert() and erase() to the miniVector class. For their
implementation, use the following declaration for key members in the private section of the class.
class miniVector
{
private:
int vSize; // number of elements in the list
T *vArr; // the dynamic array
}
20. The function insert() adds the new element item at index pos in the vector.
}
vArr[pos] = item;
المؤشرات/ ++ مراجعة لمادة سي
محمد محمود أبوشقير.د
}
21. The function erase() removes from the vector the element at index pos.
}
_________________________________________
}
المؤشرات/ ++ مراجعة لمادة سي
محمد محمود أبوشقير.د
Test Solutions
1. (a) output = 23
(b) output = 120
(c) output = 2
(d) output = 1
(e) output = 8
(f) output = 11
2. (a) (i)
(b) (ii)
(c) (iii)
4. (b)
5. (a
6. (b)
7. (b)
8. (a) *p = *q * 2 *p = 16
(b) *q += 8 *q = 16
(c) (*q)++ *q = 9
(d) q=p *p = 30 *q = 30
10. Apply the function f() for parts (a) and (b).
(a)
Contents 7 -9 3 5 6
المؤشرات/ ++ مراجعة لمادة سي
محمد محمود أبوشقير.د
(b)
13. (a)
(b) 3 0 2 9
18. (a)
19. (b)
المؤشرات/ ++ مراجعة لمادة سي
محمد محمود أبوشقير.د