|
CSIS 250 M2000 T1 Assume the following definitions for the questions that follow.
const int MIN_DIM = 1; const int MAX_DIM = 19; const int TEST_COUNT = 5;
//////////////////////////////////////////////////////////////// // CRectangle class definition //////////////////////////////////////////////////////////////// class CRectangle { private: int length; int width; public: CRectangle(int len=1, int wid=1); int perimeter(void) const; int area(void) const; void setDimension(int len, int wid); void setLength(int len); void setWidth(int wid); int getLength(void) const; int getWidth(void) const; void getDimension(int &len, int &wid) const; void display(void) const; int & badSet(void); CRectangle(char ch); ~CRectangle(void); friend bool isSquare(const CRectangle &rect); };
1. Identify the purpose of the word const in the following statement.a) Declare a constant function b) Declare a label c) Declare a constant d) Declare an integer variable e) None of the above
const int MIN_DIM = 1; 2. Identify the purpose of “len=1” in the following statement.a) Specify the global value for len b) Specify the minimum value for len c) Specify the maximum value for len d) Specify the default value for len e) None of the above
CRectangle(int len=1, int wid=1); 3. Identify the purpose of the word const in the following statement.a) Function can only modify the non-constant data members b) Function can only modify the local variables c) Function cannot modify the data members d) Function can modify the data members e) None of the above
int perimeter(void) const; 4. Identify the purpose of the word void in the following statement.a) Function does not take any argument when called b) Function returns the area of a triangle c) Function requires an argument when called d) User supplies the argument at execution time e) None of the above
int area(void) const; 5. Identify the purpose of the word void in the following statement.a) Function does not take any argument when called b) Function returns the dimensions of a triangle c) Function does not return a value d) Function requires two arguments when called e) None of the above
void setDimension(int len, int wid); 6. Identify the purpose of “int len” in the following statement.a) Function does not take any argument when called b) Function returns the dimensions of a rectangle c) Function does not return a value d) It is a call by value e) None of the above
void setLength(int len); 7. Identify the purpose of the word “friend” in the following statement.a) Function does not take any argument when called b) Function has access to the private members of the class c) Function does not return a value d) It is a call by value e) None of the above
friend bool isSquare(const CRectangle &rect); 8. Identify the missing statement in the following function.a) return (length / width); b) return (length + width); c) return (length - width); d) return (length * width); e) None of the above
int CRectangle::area(void) const { ...
} 9. Identify the missing statement in the following function.a) if ((length >= MIN_DIM) && (length <= MAX_DIM)) b) if ((len >= MIN_DIM) && (len <= MAX_DIM)) c) if ((len != MIN_DIM) && (len != MAX_DIM)) d) if ((len >= MIN_DIM) || (len <= MAX_DIM)) e) None of the above
void CRectangle::setDimension(int len, int wid) { ...
length = len; else length = 1; if ((wid >= MIN_DIM) && (wid <= MAX_DIM)) width = wid; else width = 1; } 10. Identify the purpose of the following statement.a) Puts a random value from 0 to MAX_DIM in x b) Puts a random value from 0 to MAX_DIM-1 in x c) Puts a random value from 1 to MAX_DIM in x d) Puts a random value from 0 to MAX_DIM+1 in x e) None of the above
x = rand()%MAX_DIM + 1; 11. Identify the missing statement in the following function.a) len = length; b) length = MAX_DIM; c) length = len; d) length = 0; e) None of the above
void CRectangle::setLength(int len) { if ((len >= MIN_DIM) && (len <= MAX_DIM)) ...
else length = 1; } 12. Identify the correct statement to set the length of a rectangle rect1 to 5.a) length.rect1 = 5; b) rect1.setLength(5); c) rect1.length = 5; d) setLength(rect1) = 5; e) None of the above
13. Identify the missing statement in the following function.a) return length; b) return width; c) width = wid;; d) wid = width; e) None of the above
int CRectangle::getWidth(void) const { ...
} 14. Identify the purpose of the following statement.a) Create an object r1 with length 4 and width 5 b) Set the dimensions of r1 to 4 and 5 c) Create an object r1 with width 4 and length 5 d) Release the memory taken by r1 e) None of the above
CRectangle r1(4, 5); 15. Identify the missing statement in the following function.a) return length; b) return width; c) width = wid;; d) wid = width; e) None of the above
void CRectangle::getDimension(int &len, int &wid) const { ...
wid = width; } 16. Identify the missing statement in the following function.a) return (length == width); b) return length == width; c) return (rect.length != rect.width); d) return (rect.length == rect.width); e) None of the above
bool isSquare(const CRectangle &rect) { ...
} 17. Identify the purpose of the following statement.a) Create an object r1 with length 4 and width 5 b) Set the dimensions of an existing r1 to 4 and 5 c) Create an object r1 with width 4 and length 5 d) Release the memory taken by r1 e) None of the above
CRectangle r1; 18. Identify the purpose of the following statement.a) Display the address of object pointed to by p b) Display the object pointed by p c) Delete the object pointed to by p d) Create an object and put its address in p e) None of the above
p->display(); 19. Identify the purpose of the following statement.a) Display the address of object pointed to by p b) Display the object pointed by p c) Delete the object pointed to by p d) Delete an array of objects pointed to by p e) None of the above
delete []p; 20. Identify the purpose of the following statement.a) Display the address of object pointed to by p b) Display the object pointed by p c) Delete the object pointed to by p d) Delete an array of objects pointed to by p e) None of the above
delete p; Assume the following definitions for the questions that follow.
int const MAX_VALUE = 10; int const TEST_COUNT = 20;
//////////////////////////////////////////////////////////////// // CMoney class definition //////////////////////////////////////////////////////////////// class CMoney { private: int dollars; int cents; public: CMoney(int dollars=0, int cents=0); CMoney(char ch); ~CMoney(void); void display(void) const; CMoney operator + (CMoney amount) const; CMoney add (CMoney amount) const; friend CMoney operator * (CMoney amount1, CMoney amount2); friend CMoney multiply (CMoney amount1, CMoney amount2); }; 21. Identify the purpose of the following statement.a) Create one pointer variable and one object variable b) Create two pointer variables c) Create two object variables d) Create no pointer variable e) None of the above
CMoney * m1, m2; 22. Identify the purpose of the word “this” in the following statement.a) Points to the object amount b) Points to the object in operation c) Points to a global object amount d) Points to the object amount1 e) None of the above
this->dollars = dollars; 23. Identify the purpose of the following statement.a) Assigns a random value from 0 to 100 b) Assigns a random value from 1 to 100 c) Assigns a random value from 1 to 99 d) Assigns a random even value from 2 to 100 e) None of the above
cents = rand()%100; 24. Identify the chances of the logical expression being true in the following segment.a) Fifty percent b) Twenty five percent c) Twenty percent d) Forty percent e) None of the above
if (rand()%4 == 1) { dollars = -dollars; cents = -cents; } 25. Identify the missing statement in the following function.
a) y = temp; b) temp = y; c) x = temp; d) temp = x; e) None of the above
void swap (int &x, int &y) { int temp; temp = x; x = y; ...
}
Circle the correct answer.
|