COP3330 - EXAM 1
what g++ command can be used to invoke the compile stage only?
"-c"
the aggregation/composition terms are also known as the...
"has-a" relationship. For example we might place an Engine object inside a Car object as member data, because a "car has an engine"
In the case of aggregation, the containing class is the....
"user" of the embedded objects
fp1->Show(); is equivalent to
(*fp1).show()
If gList is a pointer storing the start address of an array of Ghost objects, then which of the following is a syntactically correct call to the Scare() function of the Ghost class?
(*gList).Scare();
In an assignment operator, you must return the object itself (by reference), so you can return the target of:
*this
Whats the main difference between C and C++?
In C, data and functions are separate.
A very common form of accessor is a:
Getter. This is a function that returns some internal data to the caller, usually by value (as a copy) or in some other read-only way
What is a constructor?
a special member function of a class whose purpose is typically to initialize the member data of an object, thus setting it to a valid semantic state immediately upon creation.
when an array isn't always full, what can you use to help?
a tracking variable to track amount of slots used.
base class / derived class relationship is often referred to as
an "is a" relationship, because the derived object really is an instance of the base object
What is an object?
an encapsulation of data and functions that act upon that data
When an object is created, its constructor runs, but also must invoke the constructors of....
any embedded object
is the insertion operator a binary or unary operator?
binary
when a binary operator is written as a stand-alone function, what would the parameters look like?
both operands would be sent as parameters, so it would be a function with two parameters
how would u go about implementing aggregation?
by embedding an object of one class type (or a pointer or reference) inside as member data of another class type
When electing to choose a member function instead of using a 'friend' function, one of the objects must be the...
calling object
what are the rules for overloading an operator?
cannot change its precedence, associativity, arity (numb of operands) and you can't create brand new operators.
The name of an overloaded operator is always a...
conjunction of the keyword operator and the operator symbol itself
what is a byte?
consists of 8 bits, and is special because it is usually the smallest unit of directly addressible storage. This means - it is the smallest item that we can create a variable out of. Addresses in memory are usually applied to bytes.
anything that is passed by value in and out of functions causes...:
copies to be made
what does the DDU design entail?
declaring, defining and using a class
what does the term "Aggregation" or "Composition" mean?
defines the relationship between objects
If you do not want a constructor to be considered a conversion constructor, what keyword could you use?
explicit
Compilation and linker errors result in a:
failed compilation of the program
An operator in C++ is just a...:
function that is called with special notation
To invoke a constructor with parameters for an embedded object, use the...
initialization list
when a variable is declared with const in a normal block of code, it must be...
initialized on the same line
When there is a pointer (inside an object) that points to dynamic data, the shallow copy is not sufficient, because...:
it does not copy the dynamic data, only the pointer
when a binary operator is written as a member function, how would the function look?
the first operand would be the calling object, and the other would be sent as a parameter (i.e. a function with one parameter)
The public section of a class is essentially
the interface of an object
when a unary operator is written as a stand-alone function, what is sent in as a parameter?
the operand is sent in as a parameter
In the example: int x = 420; Which is the l-value? which is the r-value?
the r-value is the 420 while the l-value is the x.
what is a bit?
the smallest unit of storage in a computer. It stores a 0 or a 1
Destructors cannot have parameters which means
there can only be one destructor for a class
From inside any member function, an object has access to its own address through a pointer called:
this
when is the term "composition" used?
to refer to a stronger form of aggregation, where the embedded objects would typically not exist independent of the container object
why do we include header files in our .cpp files?
to satisfy "declare before use"
Run-time errors usually consist of:
two varieties. 1. Fatal -- cause program to crash during execution 2. Non-fatal (or logical) -- don't crash the program, but produce erroneous results.
Linker errors usually consist of:
undefined functions or multiply-defined functions or symbols
what are some tips/suggestions for debugging run-time errors?
use a bunch of cout statements to locate the issue.
when is a character array a c-string?
when terminated with the null-character
when can run-time errors be tested?
while running a fully-compiled program.
Run-time errors occur...
while the program is running (after successful compilation)
A class module normally consists of:
1. A header file - contains the declaration of the class (without implementation details) 2. An implementation file - contains implementations of the class members
downsides of c-strings:
1. Fixed length, when declared as a normal C-style array 2. string name really just acts as a pointer, since it's the name of an array 3. Must be careful of array boundaries
What are the main reasons for data hiding?
1. Makes interface simpler for user. 2. Principle of least priveledge (need-to-know) 3. More secure. Less chance for misuse (accidental or malicious). 4. Class implementation easy to change without affecting other modules that use it.
What are the 3 aspects of Objects?
1. Name -- the variable name we give it 2. Attributes (member data) -- the data that describes the what the object is 3. Behavior (member functions) -- behavior aspects of the object (functions that describe what the object does)
what reasons would the copy constructor be invoked?
1.An object is defined to have the value of another object of the same type 2.An object is passed by value into a function 3.An object is returned (by value) from a function
If x stores the binary number 11011001, what is the value of the operation (x << 3)?
11001110
If x stores the binary number 01011010 and y stores the binary number 11001110, what is the value of the operation (x | y)?
11011110
To ensure that a const object cannot be changed, the compiler enforced the following rule:
A const object may only call const member functions
What does the declaring part of DDU do when coding?
A function declaration tells us how to use it
What does the definition part of 'DDU' consist of?
A function definition is the code that makes a function work
what is operator overloading?
the creation of new versions of operators for use with user-defined types
What is an L-value? What is an R-value?
An L value is something that points to a specific location while an R-value is something points to pretty much nowhere. You can think of L values as containers and R values as the things inside the container
what does the level "protected" mean
Any member that is protected can be accessed directly by the class in which it is declared, and by any classes that are derived from that class
bitwise AND (&)
Bits in the result set to 1 if corresponding operand bits are both 1, and set to 0 otherwise
The "compilation" of a program actually consists of two major stages:
Compile stage and the linking stage
what do we use to call a member function of an existing object?
the dot operator
what happens in the linking stage?
Links the object code into an executable program, function calls are matched up with their definitions, and the compiler checks to make sure it has one, and only one, definition for every function that is called.
Suppose SeaCritter is an abstract class, and Starfish is a class that is derived from SeaCritter. Which of the following statements is illegal?
SeaCritter* p = new SeaCritter;
A very common form of mutator is a:
Setter. This is a function that takes data in through parameters in order to set them into private variables on the inside
left shift ( << ) operator
Shifts the bits of the first operand to the left, by the number of bits specified in the second operand. Right fill with 0 bits.
The default version of the copy constructor (created by the compiler) makes a....:
a shallow copy
what happens when you declare an object as a const?
The constructor will always run to initialize the object, but after that, the object's data cannot be changed
What is an interface in the context of OOP?
What the user sees
Suppose X is of type unsigned char (1 byte) and Y is a variable with this bit pattern: 00000010 . Which of the following statements will always change the 2nd bit from the right in X to 1, leaving the rest of the bits in X unaffected?
X = X | Y;
The keyword friend allows...
a class to gain access to another class/function members including private functions/data
what happens when an object is passed by value?
a copy is made of the object. Any R-value can be sent in the call
A struct consists of:
a name that we give it and the data inside of it
what is a throw point
a point where an exception occurs
The user of an executable program uses the:
keyboard, mouse and graphical interface
Suppose we have this declaration: unsigned char mask; Which of the following statements would initialize mask so that it would store the bit pattern 00010000 ?
mask = 1 << 4;
what ways can an operator been written as?
member functions of a class or as stand-alone functions (usually use 'friend' here)
member functions fall into 2 main categories: ______ and ______
mutators and accessors
is a 'friend' public or private?
neither so this means it does not matter where you place the function at inside the class block
what happens when an object is passed by reference?
no copy is made, and only an L-value can be sent on the call
can the 'const' keyword be used on stand-alone functions?
no! only on member functions
in the linking stage, what type of code does the compiler work on?
object code, NOT the original source code.
how does a unary operator look when written as a member function?
one calling object, no parameters
A conversion constructor is a constructor with
one parameter
the insertion and output operators should always be defined as...
outside functions (usually 'friend')
example of high-level procedural languages
pascal, fortran
parameters in friend functions are passed in using
pass by value
The user of a function is a...
programmer, who makes calls to the function
The user of a class is a...
programmer, who uses the class by creating objects and calling the available functions for those objects.
High level languages are much more _____ for programmers
readable
When defining overloads of << and >> , always pass the stream parameters by
reference
what is the double-colon (::) called when calling functions?
scope resolution operator, and it is used for specifying which class a member belongs to when we define it separately from its declaration inside the class
We use the initialization list to call the next higher constructor explicitly, in order to:
send the needed parameters up to the parent constructor
bitwise OR (inclusive) ( | )
set to 1 if at least one of the corresponding bits in the two operands is 1. 0 otherwise.
bitwise exclusive OR ( ^ )
set to 1 if exactly one of the corresponding bits in the two operands is 1. Result bit set to 0 if both corresponding bits in operands are the same.
the default version of the assignment operator makes a ....
shallow coy
memory allocation comes in two varieties, what are they?
static and dynamic
Compilation errors usually consist of:
syntax errors, undeclared variables and functions, improper function calls
What happens in the compile stage?
syntax is correct, matching function calls to prototypes, translation to object code.
Whats the main goal to strive for when creating classes and objects?
that an object is always in a valid semantic state, regardless of what features the user calls upon
what is the smallest built in data type?
the char, which on most systems today is 1 byte
what is automatically called when you declare an object?
the constructor.