Methods
Random
Vectors
General/UNIX
100
Which one copies, pass-by-value or pass-by-reference?
Pass-by-value
100

string line = "Bob";
cout << "Hey! " << line << endl;

Hey! Bob
100
What are the two best kinds of loops to use for printing out the contents of vectors?
for
for-each
100
I have a file called
movies.csv
and I want to do a case-insensitive search for 'mad max'.
grep -i "mad max" movies.csv
200

void printMe(int& i)
{
 cout << i << endl;
}

/*********************/
printMe(1);
printMe(2);

1
2
200

If I want to read an entire line of text into a string called 's' (i.e., not just a single word). HINT: getline()

std::string s;
std::getline(std::cin, s);
200
I have a vector of string's called 'vec'. How do I print out the _third_ element?
cout << vec.at(2) << endl;
200
void printMe(std::string& s)

Does the above function use pass-by-value or pass-by-reference?
pass-by-reference
300

void printMe(int& i)
{
 cout << i << endl;
}

/*********************/
int i = 0;
printMe(i);
i = 5;
printMe(5);

0
5
300
What type do you use to read from a user? (hint: c??)
cin
300
vector<string> vec;
vec.push_back("bob");
vec.push_back("shaq");
cout << vec.at(2) << endl;
crashes because of a runtime error
try it outself at http://goo.gl/nbjLKN
300
What do I need to include to get access to sin, cos, tan, etc.?
cmath
400

void printMe(int& i)
{
 cout << i << endl;
}

/*********************/
int n = 37;
++n;
printMe(n);

38
400
int x = 5;
if(x == 5 || x % 2 == 0)
{ cout << "yes" << endl;
} else { cout << "no" << endl;
}
yes
400

What's the difference between accessing vectors using [] and calling .at()? e.g.,

cout << vec.at(0) << endl;
cout << vec[0] << endl;
.at(index) checks whether index is valid, but [] does not
400
I have a file called "weather_reports.csv" that looks like this:
Zip,High,Low
08108,78,61
08033,77,60
19093,79,63
I just want the second columns, the high's.

HINT: use the 'cut' command.
cut -d',' -f2 weather_reports.csv
500

void changeMe(int& i)
{
 i = 5;
}

/*********************/
int n = 37;
changeMe(n);
cout << n << endl;

5
500
vector<double> vec;
for(int i = 0; i < 10; ++i)
{
vec.push_back(i);
}
cout << vec.size() << endl;
10
500
What's wrong with this piece of code?
double CalculateMinimumDatingAge(int age)
{
	return age / 2 + 7;
}
"age / 2" does not do fractions. You need to tell the computer to use the FPU by doing "age / 2.0"