cs110 lec 6

Cards (20)

  • Math, including:
    Numeric operators
    Precedence
    Exponents
    Integer division
  • Numeric operators
    • = assignment operator
    • + addition
    • - subtraction
    • * multiplication
    • / division
    • % remainder
  • Precedence
    Order of operations (PEMDAS) determines what to do first in an expression
  • Exponents
    pow(a, b) is equivalent to a^b
  • Integer division
    5 / 2 yields an integer 2, 5.0 / 2 yields a double 2.5, 5 % 2 yields the remainder 1
  • string is not "built-in" to C++, it is in the C++ standard string library, so #include <string> is required to use it
  • string

    Sequence of characters
  • string operations
    • Comparing 2 string values
    • Searching a string for a particular character
    • Joining one string to another
  • Input
    Extraction from the input stream (cin) using the >> operator
  • Input is messy because users are messy, more details on input cleaning, good prompts, and dealing with users will come later
  • Extraction operator cin >>

    Skips any leading whitespace, can have multiple extractions in one statement
  • It is a common error to mix up the insertion << and extraction >> operators
  • ComputeArea
    1. Read in radius
    2. Compute area
    3. Display the area
  • ComputeAverage
    1. Read in multiple inputs
    2. Compute average
  • DisplayTime
    Obtain hours and minutes from seconds
  • ComputeChange
    Find the maximum number of dollars, quarters, dimes, nickels, and pennies for a given amount
  • Common errors in C++ programming include:
    1. Undeclared/Uninitialized Variables and Unused Variables
    2. Integer Overflow
    3. Round-off Errors
    4. Unintended Integer Division
    5. Forgetting Header Files
  • Compiling source code
    Preprocessor removes comments and handles preprocessor directives like #include
  • Libraries like <iostream> and <string>
    Have an interface (header file) and implementation (other file), #include refers to the header file
  • Comments
    Notes for the programmer, should be informative and plentiful, not just reiterating code