1. GSP 125 Final Exam Guide
Purchase This Material Click below Link
FOR MORE CLASSES VISIT
www.gsp125rank.com
Question 1. 1. In addition to grouping functions together, a class also groups (Points :
3)
libraries.
math operations.
print statements.
variables.
Question 2. 2. Hiding data in a class is also called (Points : 3)
encapsulation.
accessibility inversion.
confusion culling.
redirection.
Question 3. 3. The public members of a class (Points : 3)
can be changed after compiling, even functions.
must be accessed from an object of that class.
need a special interface to accessed from an object.
can only be accessed within member functions of that class.
Question 4. 4. Constructors are called (Points : 3)
whenever an object is created.
2. whenever a new line of code is typed.
only after math operations.
only after a work contract is defined.
Question 5. 5. Unions are (Points : 3)
defined just like structs, though their memory behaves differently.
a place to store multiple data types simultaneously.
a concept from the C language that is uncommon in C++.
All of the above
Question 6. 6. When objects contain other objects, it is called (Points : 3)
composition.
data blending.
subobjecting.
enclosures.
Question 7. 7. Using the sizeof operator, the compiler will provide the size in bytes of
a (Points : 3)
class or data type.
statically allocated array.
variable instance or object.
All of the above
Question 8. 8. When de-allocating arrays dynamically allocated with new, _____
should be used to ensure proper de-allocation. (Points : 3)
destructor.
3. delete.
delete [].
free().
Question 9. 9. A pointer stores a(n) (Points : 3)
address.
variable.
value.
None of the above
Question 10. 10. The most common operator used when accessing members of an
object through a pointer is this. (Points : 3)
&
->
.
::
Question 11. 11. The following can be used to determine the number of elements in a
statically allocated array in C or C++. (Points : 3)
sizeof(arrayname)/sizeof(arrayname[0])
elementsof<arrayname>
arrayname.length()
None of the above
Question 12. 12. When returning by reference, (Points : 3)
the method can be used as an l-value.
other functions cannot use the result as a parameter.
4. C-style code must be capitalized, as per standard convention.
There is no such thing as returning by reference.
Question 13. 13. Overloaded methods in a class must use (Points : 3)
the exact same argument types, but different return types.
the exact same name.
default arguments.
None of the above
Question 14. 14. The copy constructor takes (Points : 3)
no arguments.
a single argument by reference.
a single argument by value.
any number of arguments.
Question 15. 15. A shallow copy is dangerous because (Points : 3)
it has a knife and is very clumsy.
it may cause bad de-allocation in a properly written destructor in a class that
allocates memory.
it prevents recursive methods from being called by using significant amounts of
stack space.
None of the above
Question 16. 16. When using inheritance, the class that is doing the inheriting is called
a (Points : 3)
subclass.
child class.
derived class.
5. All of the above
Question 17. 17. A UML class diagram is commonly used to (Points : 3)
exactly describe code before writing it.
help programmers explain design to other programmers.
define code standards (for syntax) for programming teams.
All of the above
Question 18. 18. Downcasting is considered safe because (Points : 3)
the compiler is very smart about types.
it is safe to assume a parent can do everything a child can do.
downcasting can only be done on upcasted objects.
downcasting is not considered safe.
Question 19. 19. If unsure whether to use inheritance or composition, use (Points : 3)
inheritance, because it saves the most typing.
inheritance, because C++ supports multiple inheritance.
composition, because it gives programmers the most options.
composition, because it is more efficient than inheritance.
Question 20. 20. Creating classes in separate .h and .cpp files is good because (Points :
3)
moving code to separate files is good design (separation of concerns).
separating declaration from definition allows decoupling of dependencies.
many smaller files are easier to maintain by teams of programmers.
All of the above
6. Question 21. 21. When using the virtual keyword, C++ can detect the type of an
object by using (Points : 3)
Compile Time Type Information.
dynamic_cast.
a "constructor inference" pattern.
C++ does not support any kind of reflection.
Question 22. 22. Passing pointers by reference (e.g., "(int * & arg)") is possible but
limited, because (Points : 3)
NULL cannot be passed as a valid pointer by reference.
a raw address (&variable) cannot be passed as a valid pointer by reference.
r-values cannot be passed as pointers by reference.
All of the above
Question 23. 23. Stack memory is where (Points : 3)
global variables and raw machine code are stored.
local variables and execution of instructions are kept track of.
dynamic memory is allocated to.
None of the above
Question 24. 24. A compiler will put sentinel values into memory to (Points : 3)
help detect array out-of-bound errors.
keep track of how many times a function recurses.
stop bad functions from being executed.
prevent memory leaks.
Question 25. 25. Virtual functions have a cost when compared to normal (statically
bound) functions; specifically, they are (Points : 3)
slower and less optimizable.
7. less dynamic.
unusable with polymorphism.
more difficult to read than extern or static functions.
Question 26. 26. In C++, the diamond problem that results from multiple inheritance
can be solved by (Points : 3)
extern inheritance.
static inheritance.
virtual inheritance.
inline inheritance.
Question 27. 27. Test-driven development is (Points : 3)
writing software after finishing multiple choice exams about software quality.
writing many small tests that initially fail, and working on each test until all
succeed.
another name for object-oriented programming.
All of the above
Question 28. 28. Which piece of the C/C++ compile tool chain arranges compiled
code into the final executable? (Points : 3)
Preprocessor
Compiler
Linker
Debugger
Question 29. 29. For C-style error codes to be used effectively, a programmer should
(Points : 3)
always do logic on function returns to test success.
check errno after potentially failed operations to see if any errors occurred.
read documentation to make sense of error codes.
All of the above
8. Question 30. 30. A class template allows (Points : 3)
a class to be re-defined with different types but the same code.
the compiler to ignore unused methods of the templated class.
the templated type to be any type, including another templated type.
All of the above
Question 31. 31. Write a “Hello World” program in C++. (Points : 2)
Question 32. 32. Write code for a struct called “Coin.” The Coin class should have a
floating-point member for radius and thickness and weight, a c-string member for
name, and an integer member for color. (Points : 7)
Question 33. 33. Write code for a class called "Double." The Double class should
have a single double member, value. Create accessors and mutators for value. The
default constructor of Double should set value to zero. (Points : 7)
Question 34. 34. Write a class named Person and create another class called Teacher,
which inherits from Person (Person is the parent class and Teacher is the child class).
(Points : 7)
Question 35. 35. Write code that instantiates an integer and prints out its address.
(Points : 7)
Question 36. 36. Write the body of thfollowing function so that it returns the square of
the number pointed at by the pointer argument.
float square(float * valuePtr)
{
} (Points : 7)
Question 37. 37. Consider the following class.
class ManagedArray {
public:
float * data;
int size;
ManagedArray():data(0),size(0){}
void setSize(int a_size){ size = a_size; data = new float[size]; }
9. };
Write a destructor for this class to de-allocate any memory it may have allocated.
(Points : 7)
Question 38. 38. Write code that dynamically allocates a two-dimensional array of
integers called map, 5 high, and 7 wide. Then, de-allocate the two-dimensional array.
(Points : 7)
Question 39. 39. Write code that allocates an integer on the stack and allocates another
integer array on the heap. (Points : 7)
Question 40.
40. Write an abstract base class called LivingThing that has the following methods:
breathe and eat. (Points : 7)