What does the 'cout' statement do in c++?
it prints stuff out
What is the final value of numItems?
bonusVal = 10;
numItems = 1;
if (bonusVal == 10) {
numItems = numItems + 3;
}
4
How do we check if a number is even?
% by 2
Which statement is used to immediately jump out of a loop and execute the next line of code?
Break
Which function is used to append an element to the end of a vector?
push_back()
the output of the following code:
int x = 99;
x /= 2;
cout << x % 5;
4
Is x =< y a valid expression?
no
When should you use a while loop instead of a for loop?
When you don't know how many iterations there will be
Which statement will end the current iteration of a loop and begins the next
Continue
Declare an integer array with a size of 3
int arr[3];
what is 7 in binary?
0111
What is y's ending value if the input is 15?
int x;
int y = 0;
cin >> x;
if (x = 20) {
y = 3;
}
3
What are all the rules for variable names (how do we know if they are valid identifiers)
be a sequence of letters (a-z, A-Z), underscores (_), and digits (0-9)
start with a letter or underscore
Which type of loop always runs at least once?
do while loop
Which of these is NOT a vector function
.pop_back()
.back()
.size()
.length()
.at()
.push_back()
.length()
Which line(s) of code give an error?
double pi = 3.14;
circleRadius = 5;
int perimeter = 2(pi * circleRadius);
cout << perimeter;
circleRadius = 5;
int perimeter = 2(pi * circleRadius);
If the input sets int x with 5 and int y with 7, what is the ending value of z? z is declared as a boolean.
z = (x > y);
false
There are about 8 billion people on this planet, create a variable named humanPop that can hold this number
long long humanPop;
OR
unsigned long long humanPop;
How many times will this loop run?
int x = 0;
for(int i = 0; i <= 10; i++){
x++;
}
11
x = v.size()-1;
OR
x = v.back();
the output of the following code
int x = 10;
x++;
cout << (sqrt(4+x/20));
2
the final value of y
int x = 6;
int y = 8;
if (x < 10) {
if (y < 5) y = y + 1;
else y = 7;}
else y = y + 10;
7
what is the output of the following code:
double x = 0.1;
double y = 0.2;
if(x + y == 0.3)
cout << "true" << endl;
else
cout << "false" << endl;
false
What is the missing line of code in the following program?
int x = 0;
int sum = 0;
while(x < 10){
sum += x;
}
x++ (or any way to increment x)
Write a program to print the elements of a vector of any size. The name of the vector is v
for(int i = 0; i < v.size(); i++)
cout << v.at(i);