Submit the quiz individually during the first two weeks but work on it as a group
Openly discuss what you believe to be the best answers for the questions
Decide how to agree on the answers
Strive to reach a consensus on quiz answers
If no consensus, work it out as you and others in your group see fit
Turn in the quiz individually as agreed upon by the group
Each group member will receive the same score
Return to the main meeting room when finished
Quiz Appeals
After completing the team quiz, team members may appeal an answer
Appeals can be based on two criteria:
Question is factually wrong
Appeal must included citations to sources of information that document or support an alternative answer. Team may access reference materials during the appeal.
Question is confusing based on it's wording
Appeal must include an appropriate rewrite of questions or answers that you interpret as ambiguous or confusing.
Work with teammates to develop and write any appeals
Team has up to 24 hours after the quiz to email appeal to instructor
If appeal is granted, only the teams that submitted appeal gets credit
Understanding variables and assignment is critical to being able to
program but can be confusing at first. Get over this hurdle and
programming will be far easier.
For this exercise we break into teams. Within the team, work with each other to complete a series of exercises where you step through short fragments of code. This is an important activity to reinforce your understanding of variables. The instructor will step through the first exercise with you.
Suggestion: for each exercise, try working through the boxes for the problem on your own and then compare answers with the rest of the team. Correct any errors and then repeat for the remaining problems.
Specifications
Start a text editor and create a file named variables.txt
Remember that C++ has two general types of numbers: integers and floating-point
We identify which type of number we use with the data type
Integers
An integer number is zero or any positive or negative number without a decimal point
Examples of integers include:
0 1 -1 +5 -27 1000 -128
We call plain numbers like these literal integers because they stand for what they look like
By comparison, a variable may contain an integer value but is not a literal integer
int num1 = 3;
Literal numbers are constant and do not change while a program executes
The compiler usually stores integers in four (4) bytes of computer memory
Floating-Point Value
A floating-point number is any signed or unsigned number with a decimal point
A floating point number approximates a real number and has a trade-off between range and precision
For example:
0.0 1.0 -1.1 +5. -6.3 3234.56 0.33
Note that 0.0, 1.0 and +5. are floating-point numbers, but could be rewritten as integers
In C++, both integers and floating-point numbers cannot have any commas or special symbols
The compiler usually stores floating-point numbers in eight (8) bytes of computer memory
Assigning Initial Values to Variables
As programmers we must decide whether or not to initialize variables when declared:
// Not initialized when declared and have unknown values
int sum;
double amount;
// Initialized when declared with assigned values
int sum = 0;
double amount = 42 * 2;
Good programming practice: initialize variables when declared
For this exercise we break into teams. Within the team, work with each other to develop a solution. When the team has finished, Choose one member to show your solution to the class by sharing your screen. The instructor will ask one team to share their solution.
Specifications
Start Repl.it and copy the following code into the code editor.
#include <iostream>
using namespace std;
int main() {
// Enter your code here
return 0;
}
Declare constant variables and assignment them the following numerical values:
The count of the number of people in this meeting (see participants)
Michael Jordan's jersey number (23)
The price of a new toy ($15.42)
The price of a new cell phone ($349.99)
The value of Pi (3.14159265359)
Compile your code to make sure you added the constants correctly.
Write an output statement for each constant followed by a newline.
Compile and run your code to make sure you added the code correctly.
When you run the program, the output should look like:
42
23
15.42
349.99
3.14159
Once satisfied with your code, copy it into a text editor, save the file as "myconst.cpp", and submit the file to Canvas with the rest of the exercise files for the week.
When finished developing your code click here to verify. Code need not look exactly the same. After you have completed your own program, reviewing another is often helpful in learning how to improve your programming skills.
Example Completed Program
#include <iostream>
using namespace std;
int main() {
const int PARTICIPANTS = 42; // your number will be different
const int JORDAN_JERSEY = 23;
const double TOY_COST = 15.42;
const double PHONE_COST = 349.0;
const double PI = 3.14159265359;
// output each constant
cout << PARTICIPANTS << endl;
cout << JORDAN_JERSEY << endl;
cout << TOY_COST << endl;
cout << PHONE_COST << endl;
cout << PI << endl;
return 0;
}
Through the miracles of computer science, we will now convert your $500 computer into a $5 calculator! Along the way, we learn how to work with arithmetic using C++.
For this exercise we break into teams. Within the team, work with each other to develop a solution. When the team has finished, Choose one member to show your solution to the class by sharing your screen. The instructor will ask one team to share their solution.
Specifications
Start Repl.it, update the code in the text editor, and then compile and run the starter program to make sure you typed it correctly.
#include <iostream>
using namespace std;
int main() {
// Type your code here
}
Within the curly braces of the main() function, declare two double variables named a and b, and assign them a value of 5 and 2 respectively. For instance:
double a = 5, b = 2;
Add a line of code to display the arithmetic expression (a + b) and then recompile and run the program.
cout << "a + b = " << a + b << endl;
Notice that the last letter on endl is a lower-case "L", NOT a one. Verify the output of the program looks like this:
a + b = 7
If you do not see this output, please type a chat message asking for help.
Add three more lines of code like the previous one that computes the expressions: a - b, a * b and a / b. Compile and run your program again and make sure your program now displays the following output:
a + b = 7
a - b = 3
a * b = 10
a / b = 2.5
The order of operations matters in C++ just like it does in algebra. Multiplication and division are performed before addition and subtraction. Add the following two statements to your program:
cout << "a + b / 2 = " << a + b / 2 << endl;
cout << "(a + b) / 2 = " << (a + b) / 2 << endl;
Compile and run your program again and compare the output. Your program should now display the following output:
a + b = 7
a - b = 3
a * b = 10
a / b = 2.5
a + b / 2 = 6
(a + b) / 2 = 3.5
Note how the output of the two statements is different. You can change the order of operation using parenthesis, just like in algebra. For more information on the order of operations see section: 2.3.3: Arithmetic.
As you can see, arithmetic in C++ works much like you would expect.
Once satisfied with your code, copy your code into a text editor, save the file as "arithmetic.cpp", and to submit the file to Canvas with the rest of the exercise files for the week.
When finished developing your code click here to verify. Code need not look exactly the same. After you have completed your own program, reviewing another is often helpful in learning how to improve your programming skills.
Example Completed Program
#include <iostream>
using namespace std;
int main() {
double a = 5, b = 2;
cout << "a + b = " << a + b << endl;
cout << "a - b = " << a - b << endl;
cout << "a * b = " << a * b << endl;
cout << "a / b = " << a / b << endl;
cout << "a + b / 2 = " << a + b / 2 << endl;
cout << "(a + b) / 2 = " << (a + b) / 2 << endl;
return 0;
}
In this exercise we use integer division, modulus, and mathematical functions to create a deluxe calculator.
For this exercise we break into teams. Within the team, work with each other to develop a solution. When the team has finished, Choose one member to show your solution to the class by sharing your screen. The instructor will ask one team to share their solution.
Integer Division: Modify your arithmetic.cpp code from the last exercise by changing the data type of the two variables from double to int, like this:
int a = 5, b = 2;
Compile and run your program again and compare the output. Note how the result of the division operation changed. What happened to the decimal part of the result?
In programming terms, we say that the decimal part is truncated (cut short). We have to watch out for this in C++ programming or we may get unexpected results in our calculations.
Modulus (%) operator: Sometimes we want the integer remainder from an integer division. To see the integer remainder, we use the modulus (%) operator. Add the following statements after the other cout statements:
cout << "a % b = " << a % b << endl;
cout << "a / b % b = " << a / b % b << endl;
cout << "a / (b * b) = " << a / (b * b) << endl;
Compile and run your program again with this added statement. Your program should now display the following output:
a + b = 7
a - b = 3
a * b = 10
a / b = 2
a + b / 2 = 6
(a + b) / 2 = 3
a % b = 1
a / b % b = 0
a / (b * b) = 1
Mathematical functions: More complex mathematical operations require the use of a function in C++. One such function is sqrt(number) which calculates the square root of the number inside the parenthesis.
Add the following statement to your program:
cout << "sqrt(a + b) = " << sqrt(a + b) << endl;
Your program will not compile with this new statement because you must include a library of the mathematical functions. Add the statement: #include <cmath> to the top of your program like this:
#include <iostream>
#include <cmath> // math function library
using namespace std;
Compile and run your program again with this added statement. Your program should now compile and display the following output when run:
a + b = 7
a - b = 3
a * b = 10
a / b = 2
a + b / 2 = 6
(a + b) / 2 = 3
a % b = 1
a / b % b = 0
a / (b * b) = 1
sqrt(a + b) = 2.64575
Once satisfied with your code, copy your code into a text editor, save the file as "calculator.cpp", and to submit the file to Canvas with the rest of the exercise files for the week.
When finished developing your code click here to verify. Code need not look exactly the same. After you have completed your own program, reviewing another is often helpful in learning how to improve your programming skills.
Example Completed Program
#include <iostream>
#include <cmath> // math function library
using namespace std;
int main() {
int a = 5, b = 2;
cout << "a + b = " << a + b << endl;
cout << "a - b = " << a - b << endl;
cout << "a * b = " << a * b << endl;
cout << "a / b = " << a / b << endl;
cout << "a + b / 2 = " << a + b / 2 << endl;
cout << "(a + b) / 2 = " << (a + b) / 2 << endl;
cout << "a % b = " << a % b << endl;
cout << "a / b % b = " << a / b % b << endl;
cout << "a / (b * b) = " << a / (b * b) << endl;
cout << "sqrt(a + b) = " << sqrt(a + b) << endl;
return 0;
}