Deck 3: Introduction to Classes, Objects and Strings

Full screen (f)
exit full mode
Question
C++ Standard Library function getline, from the header, reads characters up to, but not including, a(n)________ (which is discarded), then places the characters in a string.

A) tab
B) period
C) newline
D) \
Use Space or
up arrow
down arrow
to flip the card.
Question
A header file is typically given the filename extension:

A) .h
B) .hdr
C) .header
D) .cpp
Question
3.2 Q2. Which of the following statements is false?

A) Class names, member function names and data member names are all identifiers.
B) By convention, variable-name identifiers begin with an uppercase letter, and every word in the name after the first word begins with a capital letter; this naming convention is known as camel case.
C) Also by convention, class names begin with an initial uppercase letter, and member function and data member names begin with an initial lowercase letter.
D) All of the above are true.
Question
The ________ statement passes a value back to a function's caller.

A) recover
B) restore
C) pass
D) return
Question
C++ is a(n) ________ programming language because you can define new class types as needed.

A) strongly typed
B) extensible
C) inextensible
D) None of the above.
Question
A main function can "drive" an object by calling its member functions-without knowing how the class is implemented. In this sense, main is referred to as a(n) ________ program.

A) manipulator
B) driver
C) controller
D) operator
Question
Each class you create becomes a new ________ you can use to declare variables and create objects.

A) variable
B) object
C) type
D) access modifier
Question
The return type ________ indicates that when a function completes its task, it does not return (i.e., give back) any information to its calling function.

A) null
B) virtual
C) nullptr
D) void
Question
Which of the following statements is true?

A) The compiler knows about fundamental types that are "built into" C++.
B) A new type that you create is known as a user-defined type.
C) New classes, when packaged properly, can be reused by other programmers.
D) All of the above are true.
Question
A member-function call can supply ________ that help the function perform its task.

A) parameters
B) arguments
C) classes
D) frameworks
Question
Functions that are not members of a class are called ________ functions.

A) isolated
B) global
C) universal
D) general
Question
Assuming that text is a variable of type string, what will be the contents of text after the statement cin >> text; is executed if the user types Hello World! then presses Enter?

A) "H"
B) "Hello"
C) "Hello World"
D) "Hello World!"
Question
Typically, you cannot call a member function of a class until you create a(n) ________ of that class.

A) object
B) image
C) header
D) constructor
Question
Which of the following statements is true?

A) A class's body is enclosed in an opening left brace and a closing right brace.
B) A class definition terminates with a required semicolon.
C) Typically, each class definition is placed in a separate header with the .h filename extension.
D) All of the above are ture.
Question
Which of the following statements is false?

A) The number and order of arguments in a function call must match the number and order of parameters in the function definition's parameter list.
B) Every function body is delimited by an opening left brace and a closing right brace. Within the braces are one or more statements that perform the function's task(s).
C) When program execution reaches a function's closing brace, the function returns to its caller.
D) None of the above is false.
Question
Which of the following statements is false?

A) Variables declared in a particular function's body are local variables, which can be used only in that function.
B) When a function terminates, the values of its local variables are preserved.
C) A function's parameters also are local variables of that function.
D) The argument types in the member function call must be consistent with the types of the corresponding parameters in the member function's definition.
Question
To call a member function for a specific object, you specify the object's name, followed by a(n) ________, then the member function name and a set of parentheses.

A) dot operator
B) colon
C) ::
D) ->
Question
Files ending in .cpp are known as ________ files.

A) executable
B) secure C++
C) source-code
D) class
Question
Which of the following statements is false?

A) Each object of a class shares one copy of the class's data members.
B) An object's data members exist before a program calls member functions on an object, while they are executing and after the member functions complete execution.
C) Data members are declared inside a class definition but outside its member functions' bodies.
D) Headers should never contain using directives or using declarations.
Question
The default value for a string is ________.

A) null
B) void
C) blanks
D) the empty string
Question
Which of the following statements is false?

A) The default constructor does not initialize the class's fundamental-type data members, but does call the default constructor for each data member that's an object of another class.
B) A string's default constructor initializes the object to the empty string.
C) An uninitialized fundamental-type variable is implicitly initialized to zero.
D) If a class defines a constructor, the compiler will not create a default constructor for that class.
Question
Which of the following statements is false?

A) Each class can define a constructor for custom object initialization.
B) A constructor is a special member function that must have the same name as the class.
C) C++ requires a constructor call for every object that's created.
D) A constructor cannot specify parameters.
Question
Which of the following statements is false?

A) A constructor that specifies a single parameter should be declared implicit.
B) A constructor does not specify a return type, because constructors cannot return values.
C) Constructors cannot be declared const (because initializing an object modifies it).
D) None of the above statements is false.
Question
Which of the following statements is false?

A) Variables or functions listed after the public access specifier (and before the next access specifier, if there is one) are "available to the public." They can be used by other functions in the program, and by member functions of other classes.
B) By default, everything in a class is private, unless you specify otherwise.
C) You must list an access specifier for every member.
D) Declaring data members private is known as data hiding. private data members are encapsulated (hidden) in an object and can be accessed only by member functions of the object's class.
Question
Normally, constructors are ________.

A) private
B) protected
C) privy
D) public
Question
A default constructor has how many parameters?

A) 0.
B) 1.
C) 2.
D) Variable number.
Question
A member function that does not, and should not, modify the object on which it's called is declared with ________ to the right of its parameter list.

A) final
B) const
C) firm
D) immutable
Question
Which of the following statements is false?

A) Through the use of set and get member functions, you can validate attempted modifications to private data and control how that data is presented to the caller.
B) A client of a class is any other code that calls the class's member functions.
C) Any client code can see a private data member and do whatever it wants with it, including setting it to an invalid value.
D) Tightly controlling the access to and presentation of private data can greatly reduce errors, while increasing the usability, robustness and security of your programs.
Question
You can initialize fundamental-type data members in their declarations. This is known as a(n) ________ initializer and was introduced in C++11.

A) explicit
B) implicit
C) global
D) in-class initializer
Question
Which of the following statements about UML class diagrams is false?

A) Like operations, the UML models constructors in the third compartment of a class diagram.
B) To distinguish a constructor from the class's operations, the UML requires that the word "constructor" be enclosed in guillemets and placed before the constructor's name.
C) It's customary to list constructors before other operations in the third compartment.
D) All of the above are true.
Question
Which of the following statements is false?

A) The keyword private is an access specifier.
B) Access specifiers are always followed by a semicolon (;).
C) A private data member is accessible only to its class's member functions.
D) Most data-member declarations appear after the private access specifier.
Question
Which statement about UML class diagrams is true?

A) UML class diagrams can be used to summarize a class's attributes and operations.
B) In the UML, each class is modeled in a class diagram as a rectangle with three compartments.
C) The top compartment contains the class name centered horizontally in boldface type and the middle compartment contains the class's attribute names, which correspond to the data members of a class.
D) All of the above are true.
Question
The compiler will implicitly create a default constructor if:

A) The class does not contain any data members.
B) The programmer specifically requests that the compiler do so.
C) The class does not define any constructors.
D) The class already defines a default constructor.
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/33
auto play flashcards
Play
simple tutorial
Full screen (f)
exit full mode
Deck 3: Introduction to Classes, Objects and Strings
1
C++ Standard Library function getline, from the header, reads characters up to, but not including, a(n)________ (which is discarded), then places the characters in a string.

A) tab
B) period
C) newline
D) \
C
2
A header file is typically given the filename extension:

A) .h
B) .hdr
C) .header
D) .cpp
A
3
3.2 Q2. Which of the following statements is false?

A) Class names, member function names and data member names are all identifiers.
B) By convention, variable-name identifiers begin with an uppercase letter, and every word in the name after the first word begins with a capital letter; this naming convention is known as camel case.
C) Also by convention, class names begin with an initial uppercase letter, and member function and data member names begin with an initial lowercase letter.
D) All of the above are true.
B
4
The ________ statement passes a value back to a function's caller.

A) recover
B) restore
C) pass
D) return
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
5
C++ is a(n) ________ programming language because you can define new class types as needed.

A) strongly typed
B) extensible
C) inextensible
D) None of the above.
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
6
A main function can "drive" an object by calling its member functions-without knowing how the class is implemented. In this sense, main is referred to as a(n) ________ program.

A) manipulator
B) driver
C) controller
D) operator
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
7
Each class you create becomes a new ________ you can use to declare variables and create objects.

A) variable
B) object
C) type
D) access modifier
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
8
The return type ________ indicates that when a function completes its task, it does not return (i.e., give back) any information to its calling function.

A) null
B) virtual
C) nullptr
D) void
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
9
Which of the following statements is true?

A) The compiler knows about fundamental types that are "built into" C++.
B) A new type that you create is known as a user-defined type.
C) New classes, when packaged properly, can be reused by other programmers.
D) All of the above are true.
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
10
A member-function call can supply ________ that help the function perform its task.

A) parameters
B) arguments
C) classes
D) frameworks
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
11
Functions that are not members of a class are called ________ functions.

A) isolated
B) global
C) universal
D) general
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
12
Assuming that text is a variable of type string, what will be the contents of text after the statement cin >> text; is executed if the user types Hello World! then presses Enter?

A) "H"
B) "Hello"
C) "Hello World"
D) "Hello World!"
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
13
Typically, you cannot call a member function of a class until you create a(n) ________ of that class.

A) object
B) image
C) header
D) constructor
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
14
Which of the following statements is true?

A) A class's body is enclosed in an opening left brace and a closing right brace.
B) A class definition terminates with a required semicolon.
C) Typically, each class definition is placed in a separate header with the .h filename extension.
D) All of the above are ture.
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
15
Which of the following statements is false?

A) The number and order of arguments in a function call must match the number and order of parameters in the function definition's parameter list.
B) Every function body is delimited by an opening left brace and a closing right brace. Within the braces are one or more statements that perform the function's task(s).
C) When program execution reaches a function's closing brace, the function returns to its caller.
D) None of the above is false.
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
16
Which of the following statements is false?

A) Variables declared in a particular function's body are local variables, which can be used only in that function.
B) When a function terminates, the values of its local variables are preserved.
C) A function's parameters also are local variables of that function.
D) The argument types in the member function call must be consistent with the types of the corresponding parameters in the member function's definition.
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
17
To call a member function for a specific object, you specify the object's name, followed by a(n) ________, then the member function name and a set of parentheses.

A) dot operator
B) colon
C) ::
D) ->
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
18
Files ending in .cpp are known as ________ files.

A) executable
B) secure C++
C) source-code
D) class
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
19
Which of the following statements is false?

A) Each object of a class shares one copy of the class's data members.
B) An object's data members exist before a program calls member functions on an object, while they are executing and after the member functions complete execution.
C) Data members are declared inside a class definition but outside its member functions' bodies.
D) Headers should never contain using directives or using declarations.
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
20
The default value for a string is ________.

A) null
B) void
C) blanks
D) the empty string
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
21
Which of the following statements is false?

A) The default constructor does not initialize the class's fundamental-type data members, but does call the default constructor for each data member that's an object of another class.
B) A string's default constructor initializes the object to the empty string.
C) An uninitialized fundamental-type variable is implicitly initialized to zero.
D) If a class defines a constructor, the compiler will not create a default constructor for that class.
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
22
Which of the following statements is false?

A) Each class can define a constructor for custom object initialization.
B) A constructor is a special member function that must have the same name as the class.
C) C++ requires a constructor call for every object that's created.
D) A constructor cannot specify parameters.
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
23
Which of the following statements is false?

A) A constructor that specifies a single parameter should be declared implicit.
B) A constructor does not specify a return type, because constructors cannot return values.
C) Constructors cannot be declared const (because initializing an object modifies it).
D) None of the above statements is false.
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
24
Which of the following statements is false?

A) Variables or functions listed after the public access specifier (and before the next access specifier, if there is one) are "available to the public." They can be used by other functions in the program, and by member functions of other classes.
B) By default, everything in a class is private, unless you specify otherwise.
C) You must list an access specifier for every member.
D) Declaring data members private is known as data hiding. private data members are encapsulated (hidden) in an object and can be accessed only by member functions of the object's class.
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
25
Normally, constructors are ________.

A) private
B) protected
C) privy
D) public
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
26
A default constructor has how many parameters?

A) 0.
B) 1.
C) 2.
D) Variable number.
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
27
A member function that does not, and should not, modify the object on which it's called is declared with ________ to the right of its parameter list.

A) final
B) const
C) firm
D) immutable
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
28
Which of the following statements is false?

A) Through the use of set and get member functions, you can validate attempted modifications to private data and control how that data is presented to the caller.
B) A client of a class is any other code that calls the class's member functions.
C) Any client code can see a private data member and do whatever it wants with it, including setting it to an invalid value.
D) Tightly controlling the access to and presentation of private data can greatly reduce errors, while increasing the usability, robustness and security of your programs.
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
29
You can initialize fundamental-type data members in their declarations. This is known as a(n) ________ initializer and was introduced in C++11.

A) explicit
B) implicit
C) global
D) in-class initializer
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
30
Which of the following statements about UML class diagrams is false?

A) Like operations, the UML models constructors in the third compartment of a class diagram.
B) To distinguish a constructor from the class's operations, the UML requires that the word "constructor" be enclosed in guillemets and placed before the constructor's name.
C) It's customary to list constructors before other operations in the third compartment.
D) All of the above are true.
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
31
Which of the following statements is false?

A) The keyword private is an access specifier.
B) Access specifiers are always followed by a semicolon (;).
C) A private data member is accessible only to its class's member functions.
D) Most data-member declarations appear after the private access specifier.
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
32
Which statement about UML class diagrams is true?

A) UML class diagrams can be used to summarize a class's attributes and operations.
B) In the UML, each class is modeled in a class diagram as a rectangle with three compartments.
C) The top compartment contains the class name centered horizontally in boldface type and the middle compartment contains the class's attribute names, which correspond to the data members of a class.
D) All of the above are true.
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
33
The compiler will implicitly create a default constructor if:

A) The class does not contain any data members.
B) The programmer specifically requests that the compiler do so.
C) The class does not define any constructors.
D) The class already defines a default constructor.
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
locked card icon
Unlock Deck
Unlock for access to all 33 flashcards in this deck.