Midterm 1 Review Supplements
Instructions
 Take out a piece of paper and put your name on the paper.
 Your work will be reviewed and graded, so make it presentable.
 We will complete as many of the following sections as we have time during class.
 The rest of the sections are to be completed at home and are due the day of the test.
 For those sections completed at home, review by another student is optional.
^ top
Variables and Assignment (5m)
 Write the heading for this problem on your paper.
 In Lesson 3A review Review of Variables
 On your paper, declare a variable and assign a value for storing each of the following types of data:
 Dollars and cents
 The count of the number of people in a room
 A single letter
 Whether or not an LED is on or off
 Write the value of a and b on your paper after the following code snippet executes
int a = 10;
int b = 20;
a = b;
a is ________ b is ________  Exchange papers with another student in the class for grading.
 When grading, mark the number correct and the number of questions next to the problem heading, like: 5 / 6. (1m)
 Return the papers, discuss the grading and ask questions.
Test Yourself (Optional)
 The problem with the following code snippet is ________.
int value;
value = 1.23;
 The "value" variable is never initialized.
 The data type for the "value" variable is not specified.
 The "value" variable is never assigned a value.
 The "value" variable is assigned a decimal value, but it can store only a whole number value.
 In an airline reservation system, the cost of an airline ticket is
required. The data type that should be used to store this value is a
single ________.
int bool double char
^ top
Conditional Statements (4m)
 Write the heading for this problem on your paper.
 In Lesson 3B review Using ifelse Statements and Nested if Statements.
 On your paper, write a solution to the following problems:
 The value of x after the following code executes is ________.
int x = 7;
if (x == 3) {
x = 1;
}
 The value of x after the following code executes is ________.
int x = 3; // was x = 7
int y = 4;
if (x < y) {
x = y;
}
 The value of x after the following code executes is ________.
int x = 5; // was x = 7
if (x > 3) {
x = x  2;
}
else {
x = x + 2;
}
 The following code snippet prints ________.
int x = 1; // was x = 7
if (x > 0) {
x = x + 5;
} else if (x > 1) {
x = x + 2;
} else {
x = x + 7;
}
Serial.println(x);
 Exchange papers with another student in the class for grading.
 When grading, mark the number correct and the number of questions next to the problem heading, like: 3 / 4. (1m)
 Return the papers, discuss the grading and ask questions.
^ top
Electricity and Resistance (3m)
 Write the heading for this problem on your paper.
 In Lesson 4A review Ohm's Law, Reading Resistors and Voltage Dividers .
 On your paper, write a solution to the following problems:
 The colored bands for a 560 ohm resistor with a five percent tolerance are: ________.
 If you make a voltage divider circuit with R1 = 10K and R2 = 10K, and your Vin is 12V, your Vout is ________.
 Exchange papers with another student in the class for grading.
 When grading, mark the number correct and the number of questions next to the problem heading, like: 2 / 2. (1m)
 Return the papers, discuss the grading and ask questions.
Test Yourself (Optional)
 The colored bands for a 4,700 ohm resistor with a ten percent tolerance are ________.
 yellow, violet, orange, gold
 yellow, violet, red, silver
 yellow, violet, red, gold
 orange, violet, red, silver
 If you make a voltage divider circuit with R1 = 10K and R2 = 10K, and your Vin is 12V, your Vout is ________.
 12v
 10v
 6v
 5v
^ top
Numbers and Computations (3m)
 Write the heading for this problem on your paper.
 In Lesson 4B review Arithmetic, Integer Division and Modulus and Mathematical Functions.
 On your paper, write a solution to the following problems:
 First operation performed in
1 + 2 * 3 / 4 % 5 is ________.  The value of x after the following code executes is ________.
double x = 9 / 4;
 The value of x after the following code executes is ________.
double x = pow(3, 2);
 Exchange papers with another student in the class for grading.
 When grading, mark the number correct and the number of questions next to the problem heading, like: 2 / 3. (1m)
 Return the papers, discuss the grading and ask questions.
^ top
Characters and Strings (3m)
 Write the heading for this problem on your paper.
 In Lesson 4B review Joining Strings (Concatenation), and String Functions.
 On your paper, write a solution to the following problems:
 The value of
s3 after the following code executes is ________.
String s1 = "Hi ", s2 = "Mom!";
String s3 = s1 + s2;
 The following code displays ________.
String message = "Hi mom!";
Serial.println(message.length());
 The following code displays ________.
String message = "Hi mom!";
Serial.println(message.substring(3, 6));
 Exchange papers with another student in the class for grading.
 When grading, mark the number correct and the number of questions next to the problem heading, like: 2 / 3. (1m)
 Return the papers, discuss the grading and ask questions.
^ top
Function Definitions (5m)
 Write the heading for this problem on your paper.
 In Lesson 5A review Defining a Function and Flow of Control for a Function Call.
 On your paper, write a solution to the following problems:
 The following code snippet prints ________.
int x = 12;
void setup() {
Serial.begin(9600);
int x = 2;
x = x + 7;
}
void loop() {
cout << x << endl;
}
 Write a function named
add that takes two parameters, sums the parameters and returns the sum as a type double .
 Exchange papers with another student in the class for grading.
 When grading, mark the number correct and the number of questions next
to the problem heading, like 7 / 8, using the following criteria for the
second problem. (1m)
 Correct return type: 1 point
 Correct function name: 1 point
 Correct parameter syntax and data type: 2 points (1 point each parameter)
 Correct function body syntax like curly brace placement, no semicolon after parenthesis, etc: 1 point
 Correct calculation statement inside the function body: 1 point
 Correct return statement: 1 point
 Return the papers, discuss the grading and ask questions.
^ top
Variable Scope (4m)
 Write the heading for this problem on your paper.
 In Lesson 5A review Variable and Parameter Scope, Constants and Magic Numbers and Static Variables.
 On your paper, write a solution to the following problems:
 The following code snippet prints ________.
int x = 12;
void setup() {
Serial.begin(9600);
x = 2;
x = x + 7;
}
void loop() {
cout << x;
}
 Declare a global constant variable and assign it the value of π (3.14159265359).
 Declare a local
static int variable named "save "
and assign it the value zero (0). Add 1 to this variable every time
the loop runs. Print out: " save = " followed by the vaue for save.
What will the output look like? How is it different if you don't use
the static keyword?
 Exchange papers with another student in the class for grading.
 When grading, mark the number correct and the number of questions next to the problem heading, like: 2 / 3. (1m)
 Return the papers, discuss the grading and ask questions.
