C++ Syntax
Name that type!
What Does It Return?
Good Coding Practices
Trivia
100
All lines should end with a ____.
What is a semicolon (";")?
100
This type stores longer numbers than floats can.
What is double?
100
int x = 2; int y = x; return y;
What is 2?
100
This should always be included in your .cpp (C++) file if you want to do anything that involves input and output.
What is #include?
100
This is the person after which Boolean (true/false) logic was named.
Who is George Boole?
200
If you want to check if a variable "x" is equal to the variable "y", what do you use?
What is "==" or the comparison operator?
200
A string is really just an array of ______.
What are chars or characters?
200
How might you make this code more efficient? Write it on the board! Note: arrayOfIntegers is an array, or collection, of integers. Because computer scientists always count starting at 0, 8 is the "zeroth" element, 6 is the first element, and so on. If you want to access these, you use square brackets. So, arrayOfIntegers[0] = 8, arrayOfIntegers[1] = 6, etc. int sumOfIntegers = 0; int arrayOfIntegers[4] = {8,6,2,4}; sumOfIntegers = sumOfIntegers + arrayOfIntegers[0]; sumOfIntegers = sumOfIntegers + arrayOfIntegers[1]; sumOfIntegers = sumOfIntegers + arrayOfIntegers[2]; sumOfIntegers = sumOfIntegers + arrayOfIntegers[3]; return sumOfIntegers;
int sumOfIntegers = 0; int arrayOfIntegers[4] = {8,6,2,4}; for (int i = 0; i < 4; ++i) { sumOfIntegers = sumOfIntegers + arrayOfIntegers[i]; } return sumOfIntegers;
300
What goes in the blank? To take in user input, you would write: ___ >> userInput;
What is cin?
300
Fill in the blank in the code snippet: for ( ___ i = 0; i < 10; i++) { ... }
What is an int?
300
float x = 7.7; int y = x; return y;
What is 7?
300
/* WILDCARD ROUND */ You have one minute to get together with your teammates and come up with as many reasons as you can for the following: Why is it a good idea to comment your code? Every reason is worth 50 points!
Some good answers include: - To make sure your code is readable to other programmers - To understand what your code means if you go back and look at it in the future - To write notes for your future self for things you might want to build upon in the future! (TODOs) - To make debugging MUCH easier
400
Which of the following is not a primitive (built-in) type in C++? (Remember, it's okay to Google). a. int b. string c. bool d. char e. void
What is b. string? NOTE: Just because it's not a primitive type, doesn't mean it doesn't exist! It's just not built into the language; instead, strings are included in the C++ standard library, a library of objects that expand upon the ones built into the language. When you type "using namespace std" at the top of your file, you're telling C++ to add the standard library to the list of things you can use. Like strings. (phew!)
400
What's wrong with this code? (assume all of the functions are all fine). int LOTS = 100; while ( amountOfFun < LOTS ) { int amountOfFun = 0; goToCamp(); writeNeatCode(); playGames(); earnTickets(); ++amountOfFun; } cout << "We've had a lot of fun! Time to go home" << endl;
It runs forever! :(
500
This type can store numbers that are up to about 7 digits long.
What is a float?