Joshua's Thoughts

CIT-120 Week 1 Notes

Tags: , ,

Week #1 of CIT-120, Introduction to Computer Science and Object Oriented Programming was mostly a review for me, but I did learn some great things about the transfer program I’m in, as well as a some Window’s development topics I wasn’t so familiar with.

Each week, I will try and a provide a summary of the notes for my class. If the class has anything to add, please feel free to drop a comment and add clarification.

Notes

  • Object Oriented Programming (a case sensitive language)
    • Benefits
      • Ability to create own data types
      • OO (Object Oriented) approach reduces duplicity
    • Data Types
      • User Defined Data Types

        • A class is a user defined data type
        • A class is a complex data type
        • If a class is declared, you are creating an object
      • Trivial Data Types
        • Store only one piece of information
        • Types (the main ones): int, double, char, bool
          • int - holds whole numbers only
          • double - can share #’s with decimals
          • char - can store one character
          • unsigned - strictly positive
    • Color Highlighting in Visual Basic
      • Blue - keywords, such as data type declarations
      • Black - strings and values
      • Green - comments are in green
      cout << "Delta"; // cout is a stream object, cout (console output)
    • Library - someone elses code that you include. Take caution when including a library. Only include libraries that are essential to your code’s functionality.
      • Two ways to include a library
        • .h method - this is the professor’s preferred method as it results in a slightly smaller executable size
        • Namespace method
        • .cpp files are text only and header files end in .h
    • Operators and Operands
      • Mathematic Operators (+ - / % *)
      • “to Overload Operators” - making existing operators misbehave
      • Exp: 5 * 3, 5 and 3 are the operands and the * is the operator
      • Most operators are binary, they can act on two entities
      • Cascade - using more than one operator at a time
      • In this next example, 5 and 2 are the operands and / is the operator. Notice the result is an integer. That is because the two operands are also integers.
      cout << 5/2; // Returns 2
      • Notice that as soon as you introduce a “real” data type into the operation, the result changes.
      cout << 5.0/2; // Returns 2.5
      cout << 5/2.0 // Returns 2.5
      cout << 5.0/2.0 // Returns 2.5
      • Modular Operator - %
        • Works only with integers and gives you the remainder. This is a great way of finding out if a result is even or odd. If you divide a number and the remainder is zero, it is even.
        • Examples
        cout << 15%2; // Returns 1 (2*7 = 14 + 1 = 15)
        cout << n % 1 // A number (n) modulated by 1 is always ZERO
        cout << 5 % n; // Will crash if n is zero
      • Shortcut Operators
        • They are: +=, -=, /=, %=
        • Exp: x+=5, the same as x=5+x
    • Errors
      • Runtime - occurs during the run, depends on the input
      • Syntax error - Compiler error-developer error
      • Logical error - A logic error - something doesn’t work as expected even if it compiler
    • Strings and Escape Sequences
      • Anything between double quotes “is a string”
      • Escape sequences allow you to do something to the output that if left unescaped, the compiler would throw and error. Some of the more commons ones are:
        • \n = new line
        • \t = tab
        • \r = carriage return
        • \a = alert (make the machine beep)

No Comments, Comment or Ping

Reply to “CIT-120 Week 1 Notes”