Chapter 7: Introduction to Classes and Objects
73 flashcards · Programming Languages · by Gabriella Torres
An ______________ is a general model of something. It is a definition that includes only the general characteristics of an object without the details that characterize specific instances of the object.
abstraction
To use any data type you need to know just two things about it:
what values it can hold and what operations apply to it.
_______ describes any data type whose implementation details are kept separate from the logical properties needed to use it.
Abstract data type (ADT)
The ADT term is used to refer to ____.
data types created by the programmer
__________ is a method of writing software centered on the procedures, or functions, that carry out the actions of the program.
Procedural programming
_______ is a software entity that combines both data and the procedures that work with it in a single unit.
An object
An object's data items are also referred to as its _______.
attributes
An object's data items are stored in __________.
member variables.
The procedures that an object performs are called its ___________.
member functions
This bundling of an object's data and procedures together is called ________.
encapsulation
The procedures that an object performs are called ________.
methods
_______ refers to an object's ability to hide its data from code outside the object.
Data hiding
Only the object's _______________ can directly access and make changes to its data.
member functions
In C++, that class is the _______ primarily used to create objects.
contstruct
A _______ is a programmer-defined data type that describes what objects of the class will look like when they are created.
class
To create your own class, you must write a __________.
class declaration
The general format of a class declaration:
class ClassName // Class declaration begins with { // the key word class and a name. Declarations for class member variables and member funcitons go here. }; // Notice the required semicolon
The first step of building a class:
Determine what member variables and member functions the class should have.
The second step of building a class:
is to write the class declaration. This tells the compiler what the class includes.
Class with private and public keywords:
class Circle { private: double radius; public: void setRadius(double r) { radius = r; } double calcArea() { return 3.14 * pow(radius, 2); } };
________ designate who can access various members of the class.
Access specifiers
A _______ variable can be accessed by functions outside the class, and a _______ function can be called by functions outside the class.
public member, public member
A _______ variable can only be accessed by a function that is a member of the came class, and a _______ function can only be called by other functions that are members of the class.
private member, private member
If you omit the words public and private altogether, everything would have defaulted to being ______.
private
Member data is usually made ______ to safeguard it.
private
True/False: It does not matter whether we list the private or public members first.
True
Each object created from a class declaration is called an ______.
instance
Public members of a class object are accessed with the _________.
dot operator
Defining a class object is called _______ the class.
instantiating
An example of using the dot operator:
cout << city.length() << endl;
Member functions, just like regular functions can be passed ________ when they are called if they have been defined to accept _________.
arguments, arguments
An object's member variables are usually declared to be ________.
private
If an object's member variable were declared to be ________, it also could be accessed from outside the class by using the __________.
public, dot operator
A function like this, that uses the value of a class variable but does not change it, is known as a(n) __________.
accessor
A member function like this, which stores a value in a member variable or changes its value, is known as a(n) _________.
mutator
Some programmers refer to mutators as _________ or _________ because they set the value of a class variable.
set functions, setter functions
Some programmers refer to accessors as ________ or _________ because they just retrieve or use the value.
get functions, getter functions
When a class function is defined within the class declaration itself, it is called a(n) _________.
inline function
________ OR definition provides the actual code that determines the behavior of the function.
Function implementation
The :: is called the ________. It is needed to indicate that these are class member functions and to tell the compiler which class they belong to.
scope resolution operator
It is common to name a(n) ________ with the word ________ followed by the name of the member variable whose value it is _________.
mutator, set, setting
It is common to name a(n) ________ with the word ________ followed by the name of the member variable whose value it is ________ if all it does is return the value stored in the variable.
accessor, get, getting
When the value of an item is dependent on other data and that item is not updated when the other data is changed, we say that the item has become ________.
stale
A number of special items, such as the address to return to when the function has finished executing and the values of the function arguments, must be stored in a section of memory called the ________.
stack
This is why only a function with ________ of code should be written as an ________.
very few, inline function
A ________ is a member function that is automatically called when a class object is created.
constructor
If the programmer does not write a constructor, C++ ________.
automatically provides one
Most often programmers use a constructor to ________ an object's member variables.
initialize
A constructor looks like a regular function except that its name _________ as the name of the class it is a part of. This is how the compiler knows that a particular member function is a constructor.
must be the same
A constructor is ________ to have a return type.
not allowed
Here's how the function header for the demo constructor would look like if we defined it outside the class.
Demo::Demo() // Constructor { cout << "Now the constructor is running.\n"; }
Just like other functions, class member functions may be ________.
overloaded
As long as each constructor has a _________, creating a unique signature, the compiler can tell them apart.
different list of parameters
In C++ when an object is defined using the default constructor, instead of passing arguments, there ________ be any paratheses.
must not
If you do not have a default constructor, and the program tries to create an object without passing any arguments, ________.
it will not compile
A constructor which has no parameters is called a ________.
default constructor
If the programmer doesn't write any constructors for a class, the compiler ________ a default constructor for it.
automatically creates
When the programmer writes one or more constructors, even ones that all have parameters, the compiler ________ create a default constructor.
does not
In a process known as ________, the compiler replaces every call to the function with the actual code of the function itself. If the function is called from multiple places in the program, the entire body of its code will be inserted multiple times, increasing the size of the program.
inline exansion
A ________ is a special public member function that is automatically called to construct a class object when it is created.
A class may have many constructors but can have ________ default constructor.
only one
A(n) ________ is a list of member variables with their initial values that appear after the constructor heading and before the opening brace of the body.
member initialization list
The member initialization list includes:
the name of each variable to be initialized, followed by its initial value enclosed in parentheses .
When a constructor has a member initialization list, the initializations take place ________ any statements in the body of the constructor execute.
before
You can initialize member variables when they are defined inside the class declaration, this is known as ________.
in-place initialization
Example of in-place initialization: This gives the variables initial default values for every object of the class that is created. If a program wants to override them, the object can be created using a constructor that accepts arguments.
class Rectangle { private: double width = 0.0; double length = 0.0; public: // Public member functions go here ... };
It is possible for one constructor to call another constructor in the same class, this is known as ________.
constructor delegation
A(n) ________ is a member function that is automatically called when an object is destroyed.
destructor
Destructors are ________ with the same name as the class, preceded by a tilde character (~).
public member functions
Like constructors, destructors have _________.
no return type
Destructors ________ accept arguments, so they ________ a parameter list.
cannot, never have
There can be ________ destructors.
only one