Chap 7 Constructors and Other Tools

Chap 7 Constructors and Other Tools

<p>Homework #4 Name______Due February 20, 2006 </p><p>TRUE/FALSE. Write 'T' if the statement is true and 'F' if the statement is false. 1) A static variable of a class cannot be changed. </p><p>2) It is legal to call a constructor as a member function of an object of a class, as in the code below. class A { public: A(){} A(int x, int y):xx(x), yy(y) {} // other members private: int xx; int yy; }; int main(){ A w; w.A(2,3); } </p><p>3) A class may not have another class type object as a member. </p><p>4) A constructor is a special kind of member function. It is automatically called when an object of that class is declared. </p><p>MULTIPLE CHOICE. Choose the alternative(s) that best complete the statement or answers the question. 5) Which of the following are legal access to the class or struct members? (Assume each is outside of the class member definitions.) struct S class C class D { { { int x; int x; public: int y; int y; int x; } private: int y; S s; int z; private: }; int z; C c; }; D d; A) d.z B) c.z C) c.x D) s.x E) d.x </p><p>6) Which of the following are accurate comparisons between call-by-value and const call-by- reference? A) Call-by-value copies the argument whereas const call-by-reference does not. B) Both protect against changing the caller's argument. C) Call-by-value uses more memory than const call-by-reference in making the copy. D) Both are very fast for all sizes of objects. </p><p>1 Homework #4 </p><p>7) Which of the following are correct? A) A class can have only one constructor. B) A class can have only one default constructor. C) A constructor must be declared with a return type. D) A default constructor can only be provided by the compiler. E) A constructor must be declared for each class. </p><p>SHORT ANSWER. Write the word or phrase that best completes each statement or answers the question. 8) What is a default constructor? When does a class not have a default constructor?</p><p>9) Describe the differences between a call to an inline function member and a function that is not declared inline. What advantages are there to inline? What disadvantages?</p><p>10) Examine the definitions below. Rewrite the definition of this class so that functions f()const and g(const A& x) are inline. const int x = 17; class A { public: A( ); A(int n); int f( ) const; int g(const A& x); private: int i; };</p><p>2</p>

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    2 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us