How many times does this for loop run?
for (int i = 0; i < 5; i++) {
...
}
5 times
What's the include for file input/output?
#include <fstream>
How do you declare a vector of ints size 2?
vector<int> name(2);
What does a constant variable mean?
It cannot be modified after being initialized.
How do you declare a function?
return_type function_name (parameters);
How many times does this for loop run?
for (int i = 7; i > 2; i--) {
...
}
5 times
What variable declaration (lets call it input) do you need to begin file input?
ifstream input;
How can you reverse a vector? (Generally, no code needed)
Make a copy, start at the end and set each index to size - i;
How do we make a random number in the range of 5-25?
rand() % 21 + 5
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.
What is the standard loop to iterate through a string s?
for (unsigned int i = 0; i < s.size(); i++) {
...
}
How can you tell you're at the end of a file?
input.eof()
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);
What is the scope of a variable?
The curly braces it was declared in.
What is the return value for a void function?
n/a - don't return anything!
How many times does the asterisk get output?
for (int i = 0; i < 5; i++) {
for (int j = 0; j < 10; j++) {
cout << '*';
}
}
50
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;
}
What are parallel vectors and what are their benefits?
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
How do you use a default parameter in c++?
type function (ptype parameter = value);
Output this pattern:
****
***
**
*
for (int i = 0; i < 4; i++) {
for (int j = 4; j > i; j--) {
cout << '*';
}
cout << endl;
}
What should you always do after you're done with a file?
file.close();
What's the difference between .at() and []?
What does a computer's memory look like?
A huge array, boxes with data inside, etc...
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.