1/76
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
Warnings can always be safely ignored.
True
False
False
What happens if you try to set an unsigned variable to a value less than the minimum possible value?
Nothing will happen.
The value will be set to 0.
The value will be set to the lowest possible value for that data type.
The value will underflow.
The value will underflow.
Warnings will stop your code from compiling and prevent you from building your program.
True
False
False
What value does the following variable have?
int someValue;
The minimum value for the data type
0
1
Impossible to know
The default value for all integers
Impossible to know
The first stage of the C++ build process is the _________________?
Predecessor
Preprocessor
Compiler
Linker
Comparator
Preprocessor
This is the final stage of the building process creates the executable.
Compiler
Linker
Preprocessor
Linker
A _________________ has everything a function has, except the implementation.
prototype
pointer
null function
definition
prototype
Sometimes, when building a program, we get a lot of compiler errors. Depending on what you're working on, it could be literally hundreds of them. Which of these errors should you fix first?
The longest one.
The first one.
The last one.
The one that looks easiest to fix.
The one that sounds the scariest.
The first one.
Which of the following is the appropriate way to print "Hello, world!" to the screen?
cout << "Hello, world!";
cout("Hello, world!");
cout "Hello, world!";
cout >> "Hello, world!";
cout << "Hello, world!";
What is the minimum value of any unsigned data type?
-1
It depends on the data type
There is no minimum
0
1
0
What is the return type for constructors?
int
No return type
void
char
No return type
Given a class called Widget, which of the following are valid constructors?
Mark all that apply
Widget(float x, double y, unsigned int num = 0);
int Widget();
void Widget(int x);
Widget(int x);
Widget();
Widget(float x, double y, unsigned int num = 0);
Widget(int x);
Widget();
While a class can only have one default constructor (more would be a compiler error), which of the following COULD be a default constructor for a class called Spaceship?
Mark all that apply
Spaceship(string name = "Spaceship", float weight = 0.0f);
Spaceship(float cost, string name, float weight);
Spaceship();
Spaceship(int serialNumber, bool movingSpaceship = true);
Spaceship(string name = "Spaceship", float weight = 0.0f);
Spaceship();
When writing classes, a header file is where you should write the:
prototype definitions
function definitions
class definition
class member function definitions
class definition
Which of the following declarations is an accessor?
int Student::GetGrade() { return grade; }
void SetName(string studentName);
void Print();
string GetName();
string GetName()
When writing classes, a source file is where you should write the:
class definition
variable definitions
class member function definitions
function definitions
class member function definitions
Given the following code:
// If the boss is at half health...
if (bossMonster.GetHitpoints() <= bossMonster.GetMaximumHitpoints() * 0.5f)
{
// Look out player, you won't like him when he's angry!
// TODO: Write really powerful boss behavior
}
What are the functions being called in the if statement considered?
Constructors
Mutators
Behaviors
Accessors
Destructors
Accessors
Grouping data and functionality together, otherwise known as ____________, is the core of why we use classes.
dynamic allocation
inheritance
polymorphism
encapsulation
encapsulation
Which of the following statements is true about public member functions of a class?
A class user need not understand how each public member function behaves.
A class user can call the functions to operate on the object.
A class user needs to know how the class' functions are implemented.
A class user can declare a variable of the class type to create a new function.
A class user can call the functions to operate on the object.
A class function could be used a number of times, by a number of different instances of that class.
In a class member function, how would you access the object that has called the function?
this.
that.
this->
that->
thisThingHere->
this->
Class variables are _______________ by default.
protected
public
private
private
In C++, objects must be constructed using the new keyword before they can be used.
True
False
False
What is this code called (collectively, all of it together)?
class Container
{
vector<int> stuffHeldByContainer;
public:
Container();
void AddThingToContainer(int thingToAdd);
int NumberOfElementStored();
bool IsEmpty();
void EmptyContainer();
};
class structure
class creation
class definition
class demarcation
class definition
Given the following code:
#include <iostream>
#include <string>
using namespace std;
class Student
{
public:
void SetName(string studentName);
void SetScore(int studentScore);
string GetGrade();
private:
string name;
int score;
};
void Student::SetScore(int studentScore)
{
score = studentScore;
}
string Student::GetGrade()
{
string grade;
if (score < 40)
grade = "C";
else if (score < 70)
grade = "B";
else
grade = "A";
return grade;
}
What will the output of this program be?
int main()
{
Student stu1;
stu1.SetScore(80);
cout << stu1.GetGrade();
return 0;
}
B
A
80
C
A
What is the output of this code?
What is the output of the following code?
#include <iostream>
using namespace std;
class Greet
{
public:
Greet();
};
Greet::Greet()
{
cout << "Hello";
}
int main()
{
Greet greetings;
return 0;
}
Hello Hello
Error: When compiling the code.
No Output.
Hello
Hello
Given the following function prototype:
void Hero::AttackEnemy(Enemy* target);
And the following objects declared in main():
Hero mainCharacter;
Enemy badGuy;
How would you call the function correctly?
mainCharacter.AttackEnemy(->badGuy);
mainCharacter.AttackEnemy(*badGuy);
mainCharacter.AttackEnemy(&badGuy);
mainCharacter->AttackEnemy(&badGuy);
mainCharacter.AttackEnemy(&badGuy);
What is the default value of a pointer?
NULL
nullptr
unknown, it is uninitialized
it depends on the type of pointer
unknown, it is uninitialized
In order to access a pointer's pointee (i.e. the thing it's pointing to), you must do what?
delete the pointer
reference the pointer
depoint the pointer
derive the pointer
dereference the pointer
dereference the pointer
For the following function, which line of code could complete the desired functionality. Assume the classes are properly defined and any variables written do what their names suggest.
// Purpose: Deal damage to the passed in target, according to the Hero's attack power.
void Hero::AttackEnemy(Enemy& target)
{
// TODO: Write this function!
}
target.TakeDamage(this.attackPower);
target->TakeDamage(this.attackPower);
target.TakeDamage(this->attackPower);
target->TakeDamage(this->attackPower);
target.TakeDamage(this->attackPower);
References, once initialized (or "bound") to something, for all intents and purposes, ARE that thing.
True
False
True
Which of the following are true about pointers AND references?
Mark all that apply.
They can be reassigned as needed
They MUST be initialized
They allow for data to be shared between functions without creating copies of the original
They can be set to nullptr to indicate they aren't pointing to anything
They allow for data to be shared between functions without creating copies of the original
Pointers provide what type of access to data?
direct access
reference access
indirect access
immediate access
memory access
indirect access
Which of the following causes a stack overflow error?
When your program tries to use more stack memory than is available
When the stack pointer is at the maximum value and it gets incremented, causing it to wrap around to the minimum value
When your program uses recursion
When you exceed the maximum number of variables in a function
When your program tries to use more stack memory than is available
Given the following code:
int count;
cin >> count;
float* values = new float[count];
float total = 0;
for (int i = 0; i < count; i++)
cin >> values[i];
for (int i = 0; i < count; i++)
total += values[i];
cout << "Average: " << total/count << endl;
values = nullptr;
Is the memory allocated for the values variable deallocated correctly?
True
False
False
Memory that is allocated with new, but never deleted with delete (or delete[]), will result in what?
A memory leak
An exception
Nothing at all
A stack overflow error
A memory leak
What do pointers point to?
variables
objects
memory addresses
variables
references
memory addresses
Where is dynamically allocated memory stored?
The stack
The heap
The heap
What is the preferred way of indicating that a pointer does not point to anything?
Setting it to 0
Setting it to delete
Setting it to nullptr
Setting it to NULL
Setting it to nullptr
What is the output of the following code?
void Foo(int& y)
{
y = 10;
}
void Function(int& x)
{
Foo(x);
x += 2;
}
int main()
{
int value = 5;
Function(value);
cout << value;
return 0;
}
12
17
5210
5
12
What is the output of the following code?
void Function(int& x)
{
x += 6;
}
int main()
{
int value = 12;
Function(value);
cout << value;
return 0;
}
18
126
12
6
18
What will the following code print out?
int x = 7;
int* one = &x;
x = 14;
int* two = &x;
*two -= 3;
cout << *one << *two;
714
711
77
1111
1111
Which of the following lines would create a constant variable?
constant float smallerPie = 3.141f;
const float twoPI = 6.28319f;
constfloat PI = 3.14159f;
float morePI const = 3.142f;
const float twoPI = 6.28319f;
Why do we pass or return variables by
const*
or
const&
To pass or return quickly AND prevent changes to them
To prevent changes to them
To pass or return them quickly
To pass or return quickly AND prevent changes to them
What is the Rule of Three?
If you define any members of the Big Three, the compiler will define correct versions for the other two.
If you define one member of the Big Three, you should define the other two.
If you don't define all members of the Big Three, the compiler will generate errors.
The programmer must always implement all members of the Big Three.
If you define one member of the Big Three, you should define the other two.
What class member function is called when an object falls out of scope?
Destructor
Default Constructor
Copy Constructor
Constructor
Destructor
If you don't define a copy assignment operator for your class...
the compiler implicitly defines one that will always work, no matter what
the compiler will generate an error
the compiler implicitly defines one that performs a member-to-member copy
nothing happens at all
the compiler implicitly defines one that performs a member-to-member copy
Which of the following is a copy assignment operator for a class Hero?
Hero& copy(const Hero& h);
Hero& operatorCopy(const Hero& h);
Hero& operator=(const Hero& h);
Hero& copyAssignmentOperator(const Hero& h);
Hero& operator=(const Hero& h);
Given a class, Matrix, what function is being called on the indicated line?
Matrix transform;
Matrix adjacent;
transform.SetIdentity();
transform.RotateX(3.14159f);
adjacent = transform; <====== What function is called here?
copy assignment operator
default constructor
copy constructor
constructor
copy assignment operator
Given a class, Turret, what function is being called on the indicated line?
Turret mainTurret;
mainTurret.Initialize();
Turret secondTurret = mainTurret; <==== What function is called here?
secondTurret.SetPosition(100, 300);
default constructor
constructor
copy constructor
copy assignment operator
copy constructor
For a class Widget, identify the incorrect way(s) to call a copy constructor to copy an existing Widget named object1 to object2.
Mark all that apply.
Widget object2(object1);
Widget object2(&object1);
Widget object2.copy(object1);
Widget object2 = object1;
Widget object2(&object1);
Widget object2.copy(object1);
A copy constructor that does a member-to-member copy of all class variables, including dynamically allocated pointers, is performing what type of copy?
deep copy
pointer copy
reference copy
shallow copy
shallow copy
Which of the following are NOT members of the Big Three?
Mark all that apply.
Copy constructor
Destructor
Default constructor
Constructor
Copy assignment operator
Default constructor
Constructor
Which of the following is a destructor for a class named Menu?
~Menu(int);
~Menu();
void ~Menu(delete);
void ~Menu();
~Menu();
Which of the following blocks of code would correctly create a copy of the dynamically allocated data that originalArray is pointing to?
Quaternion* originalArray = new Quaternion[10];
// Assume some cool stuff happens here
Block A
Quaternion* copy = originalArray;
Block B
Quaternion* copy = new Quaternion[10];
for (int i = 0; i < 10; i++)
copy[i] = originalArray[i];
Block B
Block A
Block B
Given the following code, what is the purpose of const?
class Recipe {
/* Assume complete definition */
};
class CookBook {
Recipe *recipeList;
public:
const Recipe* GetRecipeList();
};
const Recipe* CookBook::GetRecipeList() {
return recipeList;
}
The prevent the returned pointer from being reassigned to another Recipe.
To protect the "this" pointer inside Cookbook.
To prevent changes to the recipeList variable through the returned pointer.
The protect the invoking object.
To prevent changes to the recipeList variable through the returned pointer.
What does the const keyword do in the following function?
float BankCustomer::GetTotalBalance() const
{
float total = 0.0f;
for(unsigned int i = 0; i < _accountNum; i ++)
total += _accounts.GetBalance();
return total;
}
Makes variables defined in the function const by default
Prevents overloading this function
Indicates that the function is "read only" by preventing changes to "this"
Makes the returned value const
Indicates that the function is "read only" by preventing changes to "this"
Given the following code:
int input;
cin >> input;
int* data = new int[input];
for (int i = 0; i < input; i++)
data[i] = i * 5;
int* copy = data;
delete[] data;
What is the variable copy considered after deleting data?
A null pointer
A dangling pointer
A valid pointer
A deleted pointer
A dangling pointer
Template classes and functions allow a programmer to reuse code that operates on different:
numbers of function parameters
data types
types of member functions
numbers of member variables
data types
The Stack data structure stores information in a specific order. What order is that?
First in, first out
First in, largest out
Largest in, smallest out
Last in, first out
Last in, first out
Template classes should be split into header files and source files, like any other class.
True
False
False
Given a class called Widget, the following code is several examples of what?
bool Widget::operator==(const& Widget otherWidget) const;
Widget& Widget::operator=(const& Widget otherWidget);
Widget Widget::operator+(const& Widget otherWidget) const;
operator integration
operator initializing
operator overloading
operator overgrowing
operator overloading
What kind of limitation exists on the number of operators that can be implemented in any given class?
Hard limit, as defined by the language
Soft limit, defined by the individual programmer on a per-class basis
Soft limit, defined by the individual programmer on a per-class basis
The Queue data structure stores information in a specific order. What order is that?
Last in, first out
Oldest in, youngest out
First in, first out
Largest in, newest out
First in, first out
Which of the following are valid template declarations?
Mark all that apply.
typename <template NewType>
typename <template T>
template <typename T>
template <typename CustomType>
template <typename T>
template <typename CustomType>
Given the following code:
Game Game::operator+(Game newGame)
{
Game myGame;
myGame.score = score + newGame.score;
//Return statement to be written here
}
What is the correct return statement for this operator?
return new Game;
return Game;
return this;
return myGame;
return myGame;
Given the following code, what will the output be?
Stack<int> stack;
for (int i = 0; i < 5; i++)
stack.push(i);
int first = stack.pop();
cout << first;
4
Given the following code, what will the output be?
Queue<int> q;
for (int i = 2; i < 8; i += 2)
q.enqueue(i);
cout << q.dequeue();
cout << q.dequeue();
cout << q.dequeue();
246
Which of the following is NOT a class that we can use to open files in C++?
ifstream
fstream
filestream
ofstream
filestream
When reading and writing files, where is the default location from which a program will open or create these?
For example, if a file was created like this:
ofstream exampleFile("test.txt");
Where would it get created?
The root directory of your hard drive
In your user documents directory
The location of your source code
In the same directory as the program itself
In the same directory as the program itself
Which of the following are absolute paths?
Mark all that apply.
data/playerSettings.zyx
D:/Documents/hpotter/magic/notes.spellbook
numbers.txt
C:/Bob/Unicorns/favorites.txt
D:/Documents/hpotter/magic/notes.spellbook
C:/Bob/Unicorns/favorites.txt
Where does the data in a data-driven program come from?
the source code of the program
files inside the program
the program itself
files outside the program
files outside the program
What delimiter does a CSV file use?
a colon
a semicolon
a comma
a carat
a comma
What operator can we use to read data from a file?
<=>
^
cin
<<
>>
>>
What function can we use to read an entire line from a file?
fromline
readline
inline
streamline
getline
inputline
getline
What operator do we use to write data to a file?
+=
<<
^
>>
cout
<<
A full path for a file is made of which of the following (one of which could technically have no value)?
Mark all that apply
a description of the file contents
an extension
a name
a directory
the name of the program that created it
a file size
an extension
a name
a directory
Which of the following characters could be used as a delimiter? Mark all that apply
a
,
|
%
?
$
a
,
|
%
?
$