📚

Midterm Study Guide summary

Sep 11, 2025

Overview

This lecture reviews key topics for the upcoming midterm, including programming fundamentals, variable types, control structures, binary arithmetic, debugging, and functions in Python and C++.

Midterm Logistics & Study Recommendations

  • The midterm exam will be on Monday the 15th during normal class time and location.
  • Content covers modules 1–4, including computing basics, syntax, arithmetic, flow control, functions, binary, and boolean expressions.
  • Review lecture materials first, use practice exams (found on Canvas), and revisit readings and assignments.
  • Email the instructor with questions before the exam.

Variable Types Overview

  • Integer: Whole numbers (e.g., 5).
  • Float: Decimal numbers with less precision in C++ (e.g., 3.14f).
  • Double: Decimal numbers with higher precision in C++.
  • Character: Single letter or symbol (e.g., 'a').
  • Boolean: True or false values.
  • String: Text data (e.g., "hello").
  • List: Ordered, mutable collection (Python).
  • Dictionary: Collection of key-value pairs (Python).

Arithmetic Operations & Order of Operations

  • Basic operators: addition (+), subtraction (-), multiplication (*), division (/), modulus (%).
  • Modulus returns the remainder after division (e.g., 10 % 3 = 1).
  • Use PEMDAS (Parentheses, Exponents, Multiplication, Division, Addition, Subtraction) for operation order.*

Input Handling

  • In Python, input() returns a string by default; cast to int for numeric input.
  • In C++, use cin from the iostream library for input.

Errors & Debugging

  • Syntax errors: Mistyped code, missing symbols, prevent code from running.
  • Logical errors: Incorrect logic or formulas; code runs but gives wrong output.
  • Debug by using print statements and pseudocode, and test with various inputs.

Conditional Statements

  • Used for decision-making in code with if, elif/else if, and else.
  • Proper indentation is important in both Python and C++.

Loops (For and While)

  • For loop: Use when the number of iterations is known.
  • While loop: Use when repetition depends on a condition being true.
  • Both examples print numbers 1 to 5 using different loop types in Python and C++.

Binary, Two’s Complement, and Bitwise Operations

  • Binary: Base-2 number system using digits 0 and 1.
  • Convert decimal to binary by dividing by 2 and recording remainders.
  • Two’s complement: Represents signed integers; invert bits and add one for negatives.
  • Bitwise operations include AND (&), OR (|), XOR (^), NOT (~), left shift (<<), and right shift (>>).

Code Optimization

  • Avoid redundant code by using loops, functions, and proper structure.
  • Simplify repeated patterns for readability and efficiency.

Functions in Python and C++

  • Functions are reusable code blocks to organize and modularize programs.
  • C++ requires specifying return types and parameter types.
  • Python functions use def without declaring types and rely on indentation.

Key Terms & Definitions

  • PEMDAS — Order of operations: Parentheses, Exponents, Multiplication, Division, Addition, Subtraction.
  • Modulus (%) — Operator returning division remainder.
  • Two’s complement — Method for representing signed integers in binary.
  • Bitwise operator — Manipulates binary digits directly (AND, OR, XOR, NOT).

Action Items / Next Steps

  • Review all lecture materials and practice exams on Canvas.
  • Revisit relevant book readings and assignment methods.
  • Practice converting numbers between decimal and binary, and using bitwise operations.
  • Email the instructor with any questions before the exam.