Deck 7: Constructors and Other Tools

ملء الشاشة (f)
exit full mode
سؤال
A constructor is like a function.It can return any type value needed.
استخدم زر المسافة أو
up arrow
down arrow
لقلب البطاقة.
سؤال
A constructor is a special kind of member function.It is automatically called when an object of that class is declared.
سؤال
A constructor usually terminates by falling off the end of its block,but a return statement is permitted if there is no argument add following the word return..
سؤال
Assignment behaves essentially the same for vectors as for arrays.
سؤال
A local class and a nested class are the same thing.
سؤال
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;
سؤال
The set of integers ranging from -MAXINT to MAXINT make up the int data type.
سؤال
A class may not have another class type object as a member.
سؤال
A constructor is always named construct with class name attached.If the class is Foo,then the constructor name is constructFoo.
سؤال
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;
};
سؤال
A static variable of a class cannot be changed.
سؤال
The keyword static is used in a static function declaration in a class but not in the function definition.
سؤال
size and capacity of a vector are two names for the same thing.
سؤال
The functions or data members declared in the private: section of a class can be accessed only in the definition those functions declared in that class.Note that friend functions are also declared (but not defined)in the class to which they are friends,so they also have access to private as well as public members.
سؤال
Any use of the keyword const is a promise to the compiler,and a request to the compiler to enforce the promise.What promises?
سؤال
Vector assignment is well behaved.
سؤال
You can write a class that is useful with all its constructors in the private section.
سؤال
A constructor can be called implicitly or explicitly.(Implicitly means the compiler did it for you. )In the interest of uniformity in answers,please use class A;for your examples.
سؤال
Inline functions are always more efficent than noninline functions.
سؤال
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?
}
سؤال
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
سؤال
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?
سؤال
A constructor

A)can only be used to initialize
B)must initialize all member variables
C)can do anything any other method can do.
D)usually initializes all,or most,member variables
سؤال
Describe in terms of who needs access to class members why the public members should come first in a class definition.
سؤال
Given 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;
};
سؤال
Suppose you have a class whose objects are very,very large.Briefly,describe the advantages and drawbacks of call-by-value and call-by-reference for large objects.Describe a parameter passing mechanism that will allow the safety of call-by-value and the efficiency of call-by-reference.
سؤال
Explain why data members,in particular should be placed in the private section of a class.
سؤال
Which of the following are accurate comparisons between call-by-value and const call-by-reference?

A)Both protect against changing the caller's argument.
B)Both are very fast for all sizes of objects.
C)Call-by-value copies the argument whereas const call-by-reference does not
D)Call by value uses more memory than const call-by-reference in making the copy.
سؤال
A class member that is to be shared among all objects of a class is called

A)A const member
B)A reference member
C)A static member.
D)A value member
E)A function member
سؤال
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
};
سؤال
What is a default constructor? When does a class not have a default constructor?
سؤال
If we use an out of range index with a vector,there be an error message from the compiler.
فتح الحزمة
قم بالتسجيل لفتح البطاقات في هذه المجموعة!
Unlock Deck
Unlock Deck
1/32
auto play flashcards
العب
simple tutorial
ملء الشاشة (f)
exit full mode
Deck 7: Constructors and Other Tools
1
A constructor is like a function.It can return any type value needed.
False
2
A constructor is a special kind of member function.It is automatically called when an object of that class is declared.
True
3
A constructor usually terminates by falling off the end of its block,but a return statement is permitted if there is no argument add following the word return..
True
4
Assignment behaves essentially the same for vectors as for arrays.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 32 في هذه المجموعة.
فتح الحزمة
k this deck
5
A local class and a nested class are the same thing.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 32 في هذه المجموعة.
فتح الحزمة
k this deck
6
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;
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 32 في هذه المجموعة.
فتح الحزمة
k this deck
7
The set of integers ranging from -MAXINT to MAXINT make up the int data type.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 32 في هذه المجموعة.
فتح الحزمة
k this deck
8
A class may not have another class type object as a member.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 32 في هذه المجموعة.
فتح الحزمة
k this deck
9
A constructor is always named construct with class name attached.If the class is Foo,then the constructor name is constructFoo.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 32 في هذه المجموعة.
فتح الحزمة
k this deck
10
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;
};
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 32 في هذه المجموعة.
فتح الحزمة
k this deck
11
A static variable of a class cannot be changed.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 32 في هذه المجموعة.
فتح الحزمة
k this deck
12
The keyword static is used in a static function declaration in a class but not in the function definition.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 32 في هذه المجموعة.
فتح الحزمة
k this deck
13
size and capacity of a vector are two names for the same thing.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 32 في هذه المجموعة.
فتح الحزمة
k this deck
14
The functions or data members declared in the private: section of a class can be accessed only in the definition those functions declared in that class.Note that friend functions are also declared (but not defined)in the class to which they are friends,so they also have access to private as well as public members.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 32 في هذه المجموعة.
فتح الحزمة
k this deck
15
Any use of the keyword const is a promise to the compiler,and a request to the compiler to enforce the promise.What promises?
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 32 في هذه المجموعة.
فتح الحزمة
k this deck
16
Vector assignment is well behaved.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 32 في هذه المجموعة.
فتح الحزمة
k this deck
17
You can write a class that is useful with all its constructors in the private section.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 32 في هذه المجموعة.
فتح الحزمة
k this deck
18
A constructor can be called implicitly or explicitly.(Implicitly means the compiler did it for you. )In the interest of uniformity in answers,please use class A;for your examples.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 32 في هذه المجموعة.
فتح الحزمة
k this deck
19
Inline functions are always more efficent than noninline functions.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 32 في هذه المجموعة.
فتح الحزمة
k this deck
20
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?
}
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 32 في هذه المجموعة.
فتح الحزمة
k this deck
21
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
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 32 في هذه المجموعة.
فتح الحزمة
k this deck
22
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?
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 32 في هذه المجموعة.
فتح الحزمة
k this deck
23
A constructor

A)can only be used to initialize
B)must initialize all member variables
C)can do anything any other method can do.
D)usually initializes all,or most,member variables
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 32 في هذه المجموعة.
فتح الحزمة
k this deck
24
Describe in terms of who needs access to class members why the public members should come first in a class definition.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 32 في هذه المجموعة.
فتح الحزمة
k this deck
25
Given 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;
};
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 32 في هذه المجموعة.
فتح الحزمة
k this deck
26
Suppose you have a class whose objects are very,very large.Briefly,describe the advantages and drawbacks of call-by-value and call-by-reference for large objects.Describe a parameter passing mechanism that will allow the safety of call-by-value and the efficiency of call-by-reference.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 32 في هذه المجموعة.
فتح الحزمة
k this deck
27
Explain why data members,in particular should be placed in the private section of a class.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 32 في هذه المجموعة.
فتح الحزمة
k this deck
28
Which of the following are accurate comparisons between call-by-value and const call-by-reference?

A)Both protect against changing the caller's argument.
B)Both are very fast for all sizes of objects.
C)Call-by-value copies the argument whereas const call-by-reference does not
D)Call by value uses more memory than const call-by-reference in making the copy.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 32 في هذه المجموعة.
فتح الحزمة
k this deck
29
A class member that is to be shared among all objects of a class is called

A)A const member
B)A reference member
C)A static member.
D)A value member
E)A function member
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 32 في هذه المجموعة.
فتح الحزمة
k this deck
30
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
};
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 32 في هذه المجموعة.
فتح الحزمة
k this deck
31
What is a default constructor? When does a class not have a default constructor?
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 32 في هذه المجموعة.
فتح الحزمة
k this deck
32
If we use an out of range index with a vector,there be an error message from the compiler.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 32 في هذه المجموعة.
فتح الحزمة
k this deck
locked card icon
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 32 في هذه المجموعة.