Exam 7: Constructors and Other Tools
Exam 1: C++ Basics37 Questions
Exam 2: Flow of Control33 Questions
Exam 3: Function Basics30 Questions
Exam 4: Parameters and Overloading31 Questions
Exam 5: Arrays32 Questions
Exam 6: Structures and Classes37 Questions
Exam 7: Constructors and Other Tools32 Questions
Exam 8: Operator Overloading,friends,and References31 Questions
Exam 9: Strings37 Questions
Exam 10: Pointers and Dynamic Arrays29 Questions
Exam 11: Separate Compilation and Namespaces35 Questions
Exam 12: Streams and File IO43 Questions
Exam 13: Recursion40 Questions
Exam 14: Inheritance30 Questions
Exam 15: Polymorphism and Virtual Functions34 Questions
Exam 16: Templates27 Questions
Exam 17: Linked Data Structures30 Questions
Exam 18: Exception Handling29 Questions
Exam 19: Standard Template Library46 Questions
Exam 20: Patterns and Uml22 Questions
Select questions type
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:
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:
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:
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)
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)
Showing 1 - 20 of 32
Filters
- Essay(0)
- Multiple Choice(0)
- Short Answer(0)
- True False(0)
- Matching(0)