Loops
File Input/Output
Vectors
Variables
Functions
100

How many times does this for loop run?

for (int i = 0; i < 5; i++) {

   ...

}

5 times

100

What's the include for file input/output?

#include <fstream>

100

How do you declare a vector of ints size 2?

vector<int> name(2);

100

What does a constant variable mean?

It cannot be modified after being initialized. 

100

How do you declare a function?

return_type function_name (parameters);

200

How many times does this for loop run?

for (int i = 7; i > 2; i--) {

    ...

}

5 times

200

What variable declaration (lets call it input) do you need to begin file input?

ifstream input;

200

How can you reverse a vector? (Generally, no code needed)

Make a copy, start at the end and set each index to size - i;

200

How do we make a random number in the range of 5-25?

rand() % 21 + 5

200

If there's a variable in main that isn't passed in, can a function see it?

No, it can only see variables declared in the function or arguments.

300

What is the standard loop to iterate through a string s?


for (unsigned int i = 0; i < s.size(); i++) {

   ...

}

300

How can you tell you're at the end of a file?

input.eof()

300

What are the two ways you can add something to the end of a vector?

1. vector.resize(size + 1);
vector.at(end) = newValue;

2. vector.append(newValue);

300

What is the scope of a variable? 

The curly braces it was declared in.

300

What is the return value for a void function?

n/a - don't return anything!

400

How many times does the asterisk get output?

for (int i = 0; i < 5; i++) {

    for (int j = 0; j < 10; j++) {

        cout << '*';

    }

}

50

400

How can you read input into a variable named str until you reach the end of a file?

cin >> str;

while (!input.eof() && !input.fail()) {

   cin >> str;

}

400

What are parallel vectors and what are their benefits?

Two vectors that have related information in each index. Can 'store' two pieces of information at once
400

What's the output of this math statement?

double a = 2.5; int b = 2;

cout << static_cast<int> (a / static_cast<double>b);

1

400

How do you use a default parameter in c++?

type function (ptype parameter = value);

500

Output this pattern:

****

***

**

*

for (int i = 0; i < 4; i++) {

    for (int j = 4; j > i; j--) {

         cout << '*';

     }

    cout << endl;

}

500

What should you always do after you're done with a file?

file.close();

500

What's the difference between .at() and []?

.at() has boundary checking, while [] doesn't. Always use .at() when dealing with vectors
500

What does a computer's memory look like?

A huge array, boxes with data inside, etc...

500

What can you pass in to a function as a pass by value argument? What can you pass in to a function as a pass by reference argument?

Anything that has a single value: variable, literal, other function output.

A variable.