cs110 week one

Subdecks (1)

Cards (68)

  • Program
    A sequence of steps. Instructions.
  • Programs
    • They break a task down into manageable, trivial chunks
    • Every step must be described in detail, and will be completed literally
  • What is a program, or algorithm?
  • Steps to solve a problem
    1. Step 1
    2. Step 2
    3. Step 3
  • Please open socrative.com, and select the room MBOON
  • Computer Science
    • CS is about solving problems
    • Sorting, searching, data representation, network protocols, artificial intelligence, algorithm analysis, encryption
  • In CS110, you will learn the basics of C++ programming. Programming skills are transferable to other languages.
  • Who uses computer programs?
    • Just about everyone
  • What do people use computer programs for?
    • Just about every discipline
  • Very few people write computer code. And you are about to become one of the few that can!
  • Computer
    • A machine for doing math
    • Math with numbers that can mean letters, shapes, colours, sounds
    • Math that can complete algorithms
    • Algorithms that can make decisions, trade stocks, buy a pair of sneakers, play a cat video
  • Algorithm
    • A recipe, or a procedure, or step-by-step guide
    • It breaks down a problem into manageable, trivial chunks
    • Coding an algorithm is like teaching a child or an alien how to do something, every step must be described, will be completed literally, to the letter
  • Example Algorithms
    • Lift a box
    • Make Cookie Dough
  • What steps can a computer perform?

    • Sequence
    • Selection
    • Repetition
    • Subroutine
  • Hardware
    The physical components
  • Software
    • The instructions (e.g. operating system, applications, etc.)
    • Software can be easily (to some extent) manipulated, which allows the same hardware to be used for multiple purposes
  • Hardware Components
    • CPU
    • Memory
    • Storage devices
    • Input devices (Keyboard, Mouse, Microphone)
    • Output devices (Monitor, speakers)
    • Communication devices
  • Central Processing Unit (CPU)
    Many things affect CPU performance: clock speed, number of cores, cache size, interconnect bandwidth, word length (32-bit vs. 64-bit)
  • Random Access Memory (RAM)
    • Short-term storage used for both data and CPU instructions
    • Data stored in RAM is volatile, which means that if power is lost, the data stored is also lost
    • Computers store data in binary format — 1's and 0's. 1 or 0 is one bit. 8 bits is called a byte
  • Storage Devices
    • Programs and data are permanently stored on storage devices and are moved to RAM when the computer actually uses them
    • Examples: Internal storage: HDD (Hard Disk Drive) and/or SSD (Solid State Drive), External storage: HDD, SSD, Flash drives, DVDs, tape, etc.
  • Software
    • A set of instructions a computer will follow when the program is executed
    • Computers are stupid, they only do what they are told to do, and they need to be told in a language they understand
  • Programming Languages
    • Machine Language
    • Assembly Language
    • High-Level Language
  • Machine Language
    • A set of primitive instructions built into every computer
    • Programming with native machine language is a tedious process, the language depends on the CPU you are programming, and the programs are highly difficult to read and modify
  • Assembly Language
    • Developed to make programming easier, but still requires a program called assembler to convert assembly language programs into machine code
    • Programs are machine-dependent, so a different program must be written for every machine architecture you want to run it on
  • High-Level Language
    • English-like and easier to learn and program
    • Largely independent of the computer they are being run on
  • Popular High-Level/3G Languages
    • Python
    • JavaScript
    • Java
    • C#
    • C
    • C++
  • Fourth and Fifth Generation Languages
    • Fourth generation languages are not general purpose, they have specific and limited capabilities, and are much easier to use if you are new to programming
    • Fifth generation languages are designed to express constraints so that a program can solve the problem — the programmer does not write any algorithms
  • Boundary Blurring Languages
    Some 3G languages manage to have many of the user-friendly advantages of 4G languages while remaining general purpose, sometimes these features are part of the core language, and sometimes they require the use of external packages or libraries
  • Operating System (OS)

    A program that manages and controls a computer's activities
  • Most popular operating systems
    • Windows (10/11)
    • MacOS
    • Linux (Ubuntu)
  • Compiled vs. Interpreted Source Code
    • Compiled languages are more efficient/run faster, but require a two-step process to run your code (compile, then run the compiled file)
    • Interpreted languages are slower, but only require a one-step process (run the code)
  • Sequence for compiling code
    1. Translates into language the machine can understand
    2. Links the object file with other supporting library code
  • Basic Control Structures
    • Sequence
    • Selection (branch)
    • Looping/Iteration (repetition)
    • Subroutine
  • Sequence
    A series of statements that execute one after another
  • Selection (branch)
    Used to determine which of two or more statements to execute, based on certain conditions
  • Looping/Iteration (repetition)

    Used to repeat statements while certain conditions are met
  • Subroutine
    A smaller part of a program; a collection of these work together to solve the original problem
  • Interaction: Input and Output
    A program can interact with the outside world through input (prompting a user for information, collecting information from a sensor) and output (displaying information to the user, sending information to another system)
  • Example: Is a Year a Leap Year?
    1. Prompt user for four-digit year
    2. Input Year
    3. Compute YearIsLeapYear
    4. If YearIsLeapYear is true, write "Year is a leap year", otherwise write "Year is not a leap year"
  • YearIsLeapYear Algorithm
    1. Divide the year by 4
    2. If the remainder isn't zero, return false (The year is not a leap year)
    3. Otherwise divide the year by 100 and if the remainder isn't 0, return true (The year is a leap year)
    4. Otherwise, divide the year by 400 and if the remainder isn't 0 return false (The year is not a leap year)
    5. Otherwise, return true (year is a leap year)