Programming C++
How many characters will the following statement read into the variable myString? cin >> setw(10) >> myString;
9
A(n) _____ is a set of instructions that the computer follows to solve a problem.
program
What is the value of number after the following statements execute? int number; number = 18 % (4 + 2);
0
What is the value of x after the following code executes? int x; x = 3 / static_cast(4.5 + 6.4);
0
When a relational expression is FALSE, it has the value _____.
0
What will the following code display? int x = 0; while (x < 5) { cout << x << " "; x++ }
0 1 2 3 4
What will the following code display? int x = 0; while (x < 5) { cout << x << " "; x++; }
0 1 2 3 4
What's the range Arduino can read from its Analog inputs?
0 to 1023
What is assigned to the variable result given the statement below with the following assumptions: x = 10, y = 7, and x, result, and y are all int variables. result = x >= y;
1
What is assigned to the variable result given the statement below with the following assumptions: x = 10, y = 7, and x, result, and y are all int variables. result = x >=y;
1
What is the output of the following code? int w = 98; int x = 99; int y = 0; int z = 1; if (x >= 99) { if (x < 99) cout << y << endl; else cout << z << endl; } else{ if (x == 99) cout << x << endl; else cout << w << endl;}
1
What will be displayed after the following statements execute? int funny = 7, serious = 15; funny = serious % 2; if (funny != 1) { funny = 0; serious = 0; } else if (funny == 2) { funny = 10; serious = 10; } else { funny = 1; serious = 1; } cout << funny << " " << serious << endl;
1 1
What will the following code display? #include using namespace std; void doSomething(int); int main() { int x = 2; cout << x << endl; doSomething(x); cout << x << endl; return 0; } void doSomething(int num) { num = 0; cout << num << endl; }
2 0 2
How many times will the following loop display "Hello world!"? for (int i = 0; i < 20; i++) cout << "Hello world!" << endl;
20
How many times will the following loop display "Hello world!"? for (int i = 0; i < 20; i++)c out << "Hello world!" << endl;
20
How many times will the following loop display "Looping!"? for (int i = 20; i > 0; i--) cout << "Looping!" << endl;
20
What is the value of result after the following code executes? int a = 60; int b = 15; int result = 10; if (a = b) result *= 2;
20
How many times will the following loop display "Looping again!"? for (int i = 0; i <= 20; i++) cout << "Looping again!" << endl;
21
What is the output of the following segment of code if the value 2 is input by the user? int num; int total = 0; cout << "Enter a number from 1 to 10: "; cin >> num; switch (num) { case 1: case 2: total = 5; case 3: total = 10; case 4: total = total + 3; case 8: total = total + 6; default: total = total + 4; } cout << total << endl;
23
What will the following code display? int x = 23, y = 34, z = 45; cout << x << y << z << endl;
233445
What is output of the following statement? cout << 4 * (15 / (17 % 3)) << endl;
28
Given the following code segment, what is the output? int x = 1, y = 1, z = 1; y = y + z; x = x + y; cout << "result = " << (x < y ? y : x) << endl;
3
What is the value of number after the following statements execute? int number = 10; number += 5; number %= 2; number *= 3;
3
What is the value of result after the following statement executes? result = (3 * 5) % 4 + 24 / (15 + (7 - 4)) * 0;
3
What is the value stored in the variable myNum after the following assignment statement executes? myNum = 23 % 5
3
What will the following code display? int x = 0; for (int count = 0; count < 3; count++) x += count; cout << x << endl;
3
In the following statement, what will be executed first according to the order of precedence? result = 6 - 3 * 2 + 7 - 10 / 2;
3 * 2
The cout statement in the following program segment will display 5: (true/false) int x=5; cout << ++X;
false
If you want a user to enter exactly 20 values, which loop would be the best to use?
for
The _____ loop is a good choice when you know how many times you want the loop to iterate in advance of entering the loop.
for
A collection of statements that performs a specific task is a(n) _____.
function
Every complete C++ program must have a
function named main
Which of the following statements will read an entire line of input into the string object, address?
geline(cin, address);
A computer stores a program while is is running _____.
in main memory
In a for statement, this expression is executed only once:
initialization
Which of the following statements correctly assigns the character M to the variable named letter?
letter = 'M'
You can control the number of significant digits in your output with the _____ manipulator.
setprecision
This manipulator is used to establish a field width for the value that follows it:
setw
Programs are normally stored in _____ and loaded into main memory as needed.
secondary storage
A special value that marks the end of a list of values is a _____.
sentinel
In the following statement, the characters Hello! are a(n) cout << "Hello!";
string literal
This is a set of rules that must be followed when constructing a program:
syntax
The two parts of the CPU are _____.
the Control Unit and the Arithmetic and Logic Unit
In a C++ program, two slash marks (//) indicate
the beginning of a comment
When the final value of an expression is assigned to a variable, it will be converted to _____.
the data type of the variable
Which of the following must be included in any program that uses the cin object?
the header file iostream
Which of the following must be included in any program that uses the cout object?
the header file iostream
Function Prototype are terminated with a semicolon. (true/false)
true
The cout statement in the following program segment will display 5: (true/false) int x=5; cout << X++;
true
When C++ is working with an operator, it strives to convert operands to the same type. This is known as _____.
type conversion
A named storage location in the computer's memory that holds a piece of information is a(n):
variable
You may define a _____ in the initialization expression of a for loop.
variable
The _____ loop is a good choice when you do not want the loop to iterate if the condition is FALSE in the beginning.
while
What color is typically used for wires that go to ground in electronic circuits like the ones with Arduinos?
Black
A function is executed when it is _____.
called
Which of the following lines must be included in a program that has string variables?
#include <String>
After the following code executes, what is the output if user enters 1? int x = -1; cout << "Enter a 0 or 1: "; cin >> x; if (x) cout << false << endl; else cout << true << endl;
0
Given that x = 2, y = 1, z = 0, what will the following cout statement display? cout << "answer = " << ( ( x || !y) && z) << endl;
0
What is the value of donuts after the following statement executes? int donuts = 10; if (donuts != 10) donuts = 0; else donuts += 2; donuts *= donuts == 10;
0
What is the value of donuts after the following statement executes? int donuts = 10; if (donuts = 1) donuts = 0; else donuts += 2;
0
What will be displayed after the following statements execute? int funny = 7, serious = 5; funny = serious % 2; if (funny != 1) { funny = 0; serious = 0; } else if (funny == 2) { funny = 10;s erious = 10; } else { funny = 1; serious = 1; } cout << funny << " " << serious << endl;
1 1
What is the output of the following code segment? n = 1; while (n <= 5) cout << n << ' ' : n++;
1 1 . . . and on forever
What is the output of the following code segment? n = 1; while (n <= 5) cout << n << ' '; n++;
1 1 . . . and on forever
What is the value of x after the following code executes? int x = 0; int y = 5; int z = 4; x = 2 * (x + y) + z % 2;
10
Which value can be entered to cause the following code segment to display the message "That number is acceptable"? int number; cin >> number; number /= 2; if (number > 10 && number < 100) cout << "That number is acceptable.\n"; else cout << "That number is not acceptable.\n";
100
What is output of the following statement: cout << 4 * (15 / (1 + 3)) << endl;
12
What is the value of donuts after the following statement executes? int donuts = 10; if (donuts != 10) donuts = 0; else donuts += 2;
12
What is the value of x after the following code executes? int x = 0; int y = 5; int z = 4; x = x + y + z * 2;
13
Given the following program, which line(s) cause(s) output to be displayed on the screen? 1// This program displays my gross wages. 2// I worked 40 hours and I make $20.00 per hour. 3#include 4using namespace std; 5 6int main() 7{ 8int hours; 9double payRate, grossPay; 10 11hours = 40; 12payRate = 20.0; 13grossPay = hours * payRate; 14cout << "My gross pay is $" << grossPay << endl; 15return 0; 16}
14
After the following code executes, what is the value of my_value if the user enters 0? cin >> my_value; if (my_value > 5) my_value = my_value + 5; else if (my_value > 2) my_value = my_value + 10; else my_value = my_value + 15;
15
After the following code executes, what is the value of my_value if the user enters 5? cin >> my_value; if (my_value > 5) my_value = my_value + 5; else if (my_value > 2) my_value = my_value + 10; else my_value = my_value + 15;
15
What is the value of result after the following code executes? int a = 60; int b = 15; int result = 10; if (a == b) result *= 2; else a %= result; result = a + b;
15
Which of the following is NOT a valid C++ identifier?
1user
What is the value of donuts after the following statement executes? int donuts = 10; donuts %= donuts; if (donuts == 1) donuts = 0; else donuts += 2;
2
What is the value of average after the following code executes? double average; average = 10.0 + 2.0 + 6.0 / 0.3;
32
What is the value of number after the following statements execute? int number = 10; number += 5; number -= 2; number *= 3;
39
What is the value of number after the following statements execute? int number; number = 18 / 4
4
What will the following code display? #include using namespace std; void showDub(int); int main() { int x = 2; showDub(x); cout << x << endl; return 0; } void showDub(int num) { cout << (num * 2) << endl; }
4 2
What will the following code display? #include using namespace std; void showDub(int); int main() { int x = 2; showDub(x); cout << x << endl; return 0; } void showDub(int num) { cout << (num * 2) << endl;}
4 2
What will the following code display? int number = 6; int x = 0; x = --number; cout << x << endl;
5
What will the following code display? int number = 6; cout << number++ << endl;
6
What will the following code display? int number = 6; int x = 0; x = number--; cout << x << endl;
6
What will the following code display? int number = 6; ++number; cout << number << endl;
7
What will the following code display? int number = 6; cout << ++number << endl;
7
What will the following code display? int number = 6; number++; cout << number << endl;
7
What is the value of cookies after the following statements execute? int number = 38, children = 4, cookies; cookies = 1 + number % children * 4;
9
What is the output of the following code? int w = 98; int x = 99; int y = 0; int z = 1; x = z + 2 * y + w - x; if (x >= 99) { if (x < 99) cout << y << endl; else cout << z << endl; } else { if (x == 99) cout << x << endl; else cout << w << endl; }
98
Which value can be entered to cause the following code segment to display the message "That number is acceptable"? int number; cin >> number; if (number > 10 && number < 100) cout << "That number is acceptable.\n"; else cout << "That number is not acceptable.\n";
99
The _____ is an equality (or comparison) operator.
==
A multi-line comment _____.
All of these are true
Which of the following is NOT a valid C++ identifier?
April*2018
What's the main benefit of wisely choosing the wire colors?
Easier debugging the circuit
What will the following code display? cout << "Four\n" << "score\n"; cout << "and" << "\nseven"; cout << "\nyears" << " ago" << endl;
Four score and seven years ago
What will the following code display? cout << "Four\n" << "score\n"; cout << "and" << "\nseven"; cout << "\nyears" << " ago" << endl;
Four score and seven years ago
What is the output of the following code segment if the user enters 23? int number; cout << "Enter a number: "; cin >> number; number*=-1; if (number > -23) cout << "Hi, there!" << endl; else cout << "Good-bye." << endl;
Good-bye.
When assigning value to pins, what does HIGH and LOW means in the Arduino code?
HIGH means ON and LOW means OFF
What is the output of the following code segment if the user enters 23? int number; cout << "Enter a number: "; cin >> number; if (number > 0) cout << "Hi, there!" << endl; else cout << "Good-bye." << endl;
Hi, there!
What is TRUE about the following statement? cout << setw(4) << num4 << " ";
It allows four spaces for the value in num4.
What is TRUE about the following statement? cout << setw(4) << num4 << " ";
It allows four spaces for the value in num4;
Which is correct about a servo?
It can rotate between 0 and 180 degrees.
Why an LED burns if directly connected to a battery?
Lack of resistance in the circuit.
An LED positive leg is shorter or longer?
Longer
What will the following code display? cout << "Monday \n"; cout << "Tuesday \n"; cout << " Wednesday";
Monday Tuesday Wednesday
What will the following code display? cout << "Monday"; cout << "Tuesday"; cout << "Wednesday";
MondayTuesdayWednesday
What kind of circuit element is a Servo?
Motor
An Arduino uses which of the following methodologies to turn a digital signal into an analog signal?
Pulse Width Modulation
What element we should use to limit the flow of electricity in a circuit?
Resistor
What will the following code display? cout << "Roses " << "are red"; cout << "and " << "violets/n" cout << "are" << "blue" << endl;
Roses are redand violets/n are blue
A potentiometer has three terminals. What the middle terminal is most commonly used for?
Signal
A battery is connected directly to an LED. What will happen right after electricity flows in the circuit?
The LED lights up and burns right after.
What does the Tilda (~) sign on the Arduino indicated about a pin?
The pin can produce signals with values between 0 and 1.
In an Arduino code, what happens at the end of the code after last line?
The program returns to the first line
What will be displayed after the following statements execute? int num1 = 5; int num2 = 3; cout << "The result is " << (num1 * num2 + 10) << endl;
The result is 25
What is the output of the following code segment? int x = 0; if (x <= -2) cout << "This is true!" << endl; else cout << "This is false!" << endl; cout << "That's all, folks!" << endl;
This is false! That's all, folks
What is the output of the following code segment? int x = 5; if (x = 2) cout << "This is true!" << endl; else cout << "This is false!" << endl; cout << "That's all, folks!" << endl;
This is true! That's all folks
The while loop is a pretest loop. (true/false)
True
What is the output of the following code segment if the user enters 50 for the score? cout << "Enter your test score: "; cin >> test_score; if (test_score <= 50) cout << "You failed the test." << endl; if (test_score > 50) cout << "You passed the test." else cout << "You need to study harder next time." << endl;
You failed the test. You need to study harder next time.
What is the output of the following code segment if the user enters 90 for the score? cout << "Enter your test score: "; cin >> test_score; if (test_score < 60) cout << "You failed the test." << endl; if (test_score > 60) cout << "You passed the test." else cout << "You need to study harder next time." << endl;
You passed the test.
What will be the output after the following lines of code execute? bool choice;choice = true; cout << "Your choice is " << choice << endl;
Your choice is 1
What will be the output after the following lines of code execute? bool choice; choice = false; cout << "Your choice is " << "choice" << endl;
Your choice is choice
How much resistance a potentiometer has when completely clocked down?
Zero or Minimum
Given the if/else statement: if (a < 5) b = 12; else d = 30; Which of the following performs the same operation?
a < 5 ? b = 12 : d = 30;
Given the if/else statement; if (a < 5) b = 12; else d = 30; Which of the following performs the same operation?
a < 5 ? b = 12 : d = 30;
Which of the following causes a function to execute?
a function call
A set of well-defined steps for performing a task or solving a problem is known as a(n):
algorithm
A(n) _____ is information that is passed to a function, and a(n) _____ is information that is received by a function.
argument, parameter
The statements in the body of a while loop may never be executed while the statements in the body of a do-while loop will be executed ____.
at least once
Function Headers are terminated with a semicolon. (true/false)
false
Which data type typically requires only one byte of storage?
char
The _____ causes a program to wait until information is typed at the keyboard and the [Enter] key is pressed.
cin object
Which of the following statements will pause the screen until the [Enter] key is pressed?
cin.get();
Which of the following functions tells the cin object to skip one or more characters in the keyboard buffer?
cin.ignore
The function pow(x, y) requires which header file?
cmath
What is the value of result after the following code executes? int a = 60; int b = 15; int result = 10; if (a = b) result += 2;
code will not execute
_____ are used to translate each source code instruction into the appropriate machine language instruction.
compilers
Which step uncovers any syntax errors in your program?
compiling
To use the rand() function, you must include the _____ header file?
cstdlib
If you intend to place a block of statements within an if statement, you must place _____ around the block.
curly braces { }
A function _____ contains the statements that make up the function.
definition
The data type used to declare variables that can hold real numbers is _____.
double
In a cout statement, which of the following will advance the output position to the beginning of the next line?
endl or \n
After the following code executes, what is the output if user enters 0? int x = -1; cout << "Enter a 0 or 1: "; cin >> x; if (c) cout << "true" << endl; else cout << "false" << endl;
false
Which line in the following program contains the header for the showDub function? 1 #include 2 using namespace std; 3 void showDub(int); 4 int main() 5 { 6 int x = 2; 7 showDub(x); 8 cout << x << endl; 9 return 0; 10 } 11 void showDub(int num) 12 { 13 cout << (num * 2) << endl; 14 }
line 11
Which line in the following program contains the prototype showDub function? 1 #include 2 using namespace std; 3 void showDub(int); 4 int main() 5 { 6 int x = 2; 7 showDub(x); 8 cout << x << endl; 9 return 0; 10 } 11 void showDub(int num) 12 { 13 cout << (num * 2) << endl; 14 }
line 3
Which line in the following program will cause a compiler error? 1 #include 2 using namespace std; 3 int main() 4 { 5 int number = 100; 6 if (number >= 0 && 100) 7 cout << "passed.\n"; 8 else 9 cout << "failed.\n"; 10 return 0;11 }
line 6
Which line in the following program contains a call to the showDub function? 1 #include 2 using namespace std; 3 void showDub(int); 4 int main() 5 { 6 int x = 2; 7 showDub(x); 8 cout << x << endl; 9 return 0; 10 } 11 void showDub(int num) 12 { 13 cout << (num * 2) << endl; 14 }
line 7
Which line in the following program will cause a compiler error? 1 #include 2 using namespace std; 3 4 int main() 5 { 6 const int MY_VAL = 77; 7 MY_VAL = 99; 8 cout << "MY_VAL" << endl; 9 return 0; 10 }
line 7
Which line in the following program will cause a compiler error? 1 #include 2 using namespace std; 3 4 int main() 5 { 6 const int MY_VAL = 77; 7 MY_VAL = 99; 8 cout << MY_VAL << endl; 9 return 0; 10 }
line 7
Data items whose values do NOT change while the program is running are _____.
literals
To change the range of a variable, which function is used in Arduino code?
map
A loop that is inside another loop is called a(n)
nested loop
In memory, C++ automatically places a(n) _____ at the end of string literals which _____.
null terminator, marks the end of the string
Which statement is equivalent to the following? number = number * 2;
number *= 2;
Which statement is equivalent to the following? number += 1;
number = number + 1;
The while loop is a _____ loop.
pre-test
The two methods used by C++ to write computer programs are:
procedural programming and object-oriented programming
A function _____ eliminates the need to place a function definition before all calls to the function.
prototype
Given the following code segment, what is the output? int x = 1, y = 1, z = 1; y = y + z;x = x + y; cout << "result = " << (x < y ? y : x) << endl;
result = 3
Which of the following functions will return the value of x, rounded to the nearest whole number?
round(x)