Exam 7: Constructors and Other Tools

arrow
  • Select Tags
search iconSearch Question
flashcardsStudy Flashcards
  • Select Tags

Describe in terms of who needs access to class members why the public members should come first in a class definition.

Free
(Essay)
4.8/5
(35)
Correct Answer:
Verified

The client is more interested in the public members.The client cannot access the private members,and thus has no real (direct)use for them.Hence the public members should be placed first in a class.

If v is a vector and i is an int variable,then in the following the value of i can be any nonnegative int value: v[i] = i;

Free
(True/False)
4.9/5
(35)
Correct Answer:
Verified

False

A constructor is always named construct with class name attached.If the class is Foo,then the constructor name is constructFoo.

Free
(True/False)
4.9/5
(35)
Correct Answer:
Verified

False

It is valid to initialize member variables in a class on the same line in which the variable is declared.For example,the following sets xx to 1000: class A { public: A(){} private: int xx = 1000; };

(True/False)
4.8/5
(34)

Assignment behaves essentially the same for vectors as for arrays.

(True/False)
4.8/5
(36)

Why is it an error to add a const modifier,as shown to the declaration for the member function input given here? class BankAccount { public: void input( )const; // other members };

(Essay)
4.9/5
(41)

A class member that is to be shared among all objects of a class is called

(Multiple Choice)
4.8/5
(43)

A class may not have another class type object as a member.

(True/False)
4.8/5
(39)

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)s.x b)c.x c)d.x d)c.z e)d.z

(Essay)
4.8/5
(38)

Explain why data members,in particular should be placed in the private section of a class.

(Essay)
4.8/5
(34)

A constructor is like a function.It can return any type value needed.

(True/False)
4.7/5
(36)

You can write a class that is useful with all its constructors in the private section.

(True/False)
4.9/5
(42)

Any use of the keyword const is a promise to the compiler,and a request to the compiler to enforce the promise.What promises?

(True/False)
4.9/5
(44)

It is legal to call a constructor as a member function of an object of a class,as in 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);// Is this legal? }

(True/False)
4.9/5
(35)

A constructor is a special kind of member function.It is automatically called when an object of that class is declared.

(True/False)
4.9/5
(43)

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?

(Essay)
4.8/5
(38)

Which of the following are accurate comparisons between call-by-value and const call-by-reference?

(Multiple Choice)
4.8/5
(32)

If we use an out of range index with a vector,there be an error message from the compiler.

(True/False)
4.9/5
(42)

Inline functions are always more efficent than noninline functions.

(True/False)
4.9/5
(40)

size and capacity of a vector are two names for the same thing.

(True/False)
4.8/5
(33)
Showing 1 - 20 of 32
close modal

Filters

  • Essay(0)
  • Multiple Choice(0)
  • Short Answer(0)
  • True False(0)
  • Matching(0)