When I declare variables inside a class without specifying an access modifier, are they private or public by default?
Private
This keyword lets us dynamically allocate memory in C++.
the "new" keyword
We include this header file so we can perform input and output to the console.
what is #include<iostream> or just <iostream>
You include this key word when your function does NOT return a value
What is "void"
When you declare a struct in C++, are the member variables public or private by default?
What is public
What special method is automatically called when an object of a class is created?
A constructor
This error occurs when you forget to use the delete keyword after dynamically allocating memory with new.
I have a user defined header file called "Foo.h", how would I include it into my main.cpp file?
What is #include "Foo.h"
How would you write a void function that doubles the value of a given integer variable?
void myFunc(int &x) {
x *= 2;
}
This algorithm allows us to search through a sorted array very quickly by repeatedly dividing the search interval in half.
What is binary search
Whenever we use pointers or dynamically allocated memory in a class, we must define this special method to properly clean up after the object is destroyed.
(Hint: its symbol is ~)
A destructor
What does this following program print
int x = 10;
int* y = &x;
int z = *y;
scout << "This program prints: " << z << endl;
This program prints: 10
Which header file should I include if I want arrays that can grow and shrink in size at runtime?
This following function demonstrates what method?
int factorial(int n) {
if (n <= 1) return 1;
return n * factorial(n - 1);
}
What is recursion?
Declaring a member function with this keyword after the parentheses promises not to modify the object.
What is const
Given this declaration of a class
class Foo {
int x;
double y;
string z;
};
Create a constructor using the following type declaration (assume namespace std)
Foo(num1, num2, word);
Foo(int num1, double num2, string word) {
x = num1;
y = num2;
z = word;
}
(DAILY DOUBLE)When we dynamically allocate an object of a class, this operator allows us to access its methods directly.
What is the '->' operator (arrow)
Given the following declaration
vector<int> arr = {1, 2, 3};
How would you add another entry with the value 4 to this vector?
What is arr.push_back(4); ?
What process is being done in the following code snippet?
Vector2D operator+(const Vector2D &other) {
return Vector2D(x + other.x, y + other.y);
}
What is operator overload?
This sorting algorithm repeatedly checks if the number after an index is smaller, and swaps positions if it is, moving larger numbers to the end of the array.
What is bubble sort.
Given this class
class Animal {
public:
void speak() { cout << "Animal sound\n"; }
};
Finish this class header so that Dog inherits Animal
class Dog {
};
class Dog : public Animal {};
(DAILY DOUBLE)What does the following program print?
float x = 5;
float y = &x;
cout << y << endl;
This code will compile as an error (the declaration for float y is wrong since it's missing "float* y")
Fix the following program so it compiles correctly:
#include <iostream>
int main() {
int x = 0;
int y = 2;
cout << "num 1 is " << x << " num 2 is " << y << endl;
}
std::cout << "num 1 is " << x << " num 2 is " << y << std::endl;
In the following code snippet, what does typename T represent?
template <typename T>
T add(T a, T b) {
return a + b;
}
It allows ANY datatype to work with the function.
This directive ensures that a header file is included only once in a compilation, preventing multiple definition errors.