Abstraction IS 101Y/CMSC 101 Computational Thinking and Design Tuesday, September 9, 2014 Carolyn Seaman Susan Martin University of Maryland, Baltimore.

Slides:



Advertisements
Similar presentations
08/2012Tanya Mishra1 EASYC for VEX Cortex Llano Estacado RoboRaiders FRC Team 1817.
Advertisements

Code Elements and Processing Coordinate System. Code elements: pages Comments: are documentation notes that are ignored by the computer but are.
 Variables  What are they?  Declaring and initializing variables  Common uses for variables  Variables you get “for free” in Processing ▪ Aka: Built-in.
Chapter 2: Using Objects Part 1. To learn about variables To understand the concepts of classes and objects To be able to call methods To learn about.
CS0007: Introduction to Computer Programming Console Output, Variables, Literals, and Introduction to Type.
Data: Programming Design and Modularization IS 101Y/CMSC 101 Computational Thinking and Design Thursday, September 26, 2013 Marie desJardins University.
10-Jun-15 Just Enough Java. Variables A variable is a “box” that holds data Every variable has a name Examples: name, age, address, isMarried Variables.
Chapter 2: Algorithm Discovery and Design
Computer Programming and Basic Software Engineering 4. Basic Software Engineering 1 Writing a Good Program 4. Basic Software Engineering 3 October 2007.
Program Design and Development
1 Key Concepts:  Why C?  Life Cycle Of a C program,  What is a computer program?  A program statement?  Basic parts of a C program,  Printf() function?
Computer Science 1620 Programming & Problem Solving.
CS 201 Functions Debzani Deb.
Programming Logic and Design, Introductory, Fourth Edition1 Understanding Computer Components and Operations (continued) A program must be free of syntax.
Chapter 1 Program Design
Chapter 8: Introduction to High-Level Language Programming Invitation to Computer Science, C++ Version, Fourth Edition.
Chapter 2: Algorithm Discovery and Design
Chapter 2: Algorithm Discovery and Design
Chapter 3 Planning Your Solution
PROCESSING Animation. Objectives Be able to create Processing animations Be able to create interactive Processing programs.
Concept of Computer Programming November 2, 2011.
Adapted from slides by Marie desJardins
DCT 1123 PROBLEM SOLVING & ALGORITHMS INTRODUCTION TO PROGRAMMING.
COMPUTER SCIENCE I C++ INTRODUCTION
Abstraction IS 101Y/CMSC 101 Computational Thinking and Design Tuesday, September 17, 2013 Carolyn Seaman University of Maryland, Baltimore County.
1 Shawlands Academy Higher Computing Software Development Unit.
Programming for Artists ART 315 Dr. J. R. Parker Art/Digital Media Lab Lec 10 Fall 2010.
O BJECT O RIENTATION F UNDAMENTALS Prepared by: Gunjan Chhabra.
CPSC 171 Introduction to Computer Science 3 Levels of Understanding Algorithms More Algorithm Discovery and Design.
CIS Computer Programming Logic
Introduction to Python
Design IS 101Y/CMSC 101 Computational Thinking and Design Tuesday, October 15, 2013 Carolyn Seaman University of Maryland, Baltimore County.
Java: Chapter 1 Computer Systems Computer Programming II.
Java Language and SW Dev’t
Program Design CMSC 201. Motivation We’ve talked a lot about certain ‘good habits’ we’d like you guys to get in while writing code. There are two main.
Chapter 2: Algorithm Discovery and Design Invitation to Computer Science, C++ Version, Third Edition.
Invitation to Computer Science, Java Version, Second Edition.
Algorithmic Problem Solving COMP 101 Computational Thinking and Design Thursday, September 4, 2014 Carolyn Seaman Susan Martin University of Maryland,
DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UWA WELLASSA 1 CST 221 OBJECT ORIENTED PROGRAMMING(OOP) ( 2 CREDITS.
1 The Software Development Process  Systems analysis  Systems design  Implementation  Testing  Documentation  Evaluation  Maintenance.
The Java Programming Language
Abstraction IS 101Y/CMSC 101 Computational Thinking and Design Tuesday, September 17, 2013 Marie desJardins University of Maryland, Baltimore County.
School of Computer Science & Information Technology G6DICP - Lecture 9 Software Development Techniques.
Chapter 13 Recursion. Learning Objectives Recursive void Functions – Tracing recursive calls – Infinite recursion, overflows Recursive Functions that.
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 5: Software Design & Testing; Revision Session.
1 © 2002 John Urrutia. All rights reserved. Qbasic Constructing Qbasic Programs.
Property of Jack Wilson, Cerritos College1 CIS Computer Programming Logic Programming Concepts Overview prepared by Jack Wilson Cerritos College.
C++ Basics C++ is a high-level, general purpose, object-oriented programming language.
CMP-MX21: Lecture 4 Selections Steve Hordley. Overview 1. The if-else selection in JAVA 2. More useful JAVA operators 4. Other selection constructs in.
The Software Development Process
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
1 CSCD 326 Data Structures I Software Design. 2 The Software Life Cycle 1. Specification 2. Design 3. Risk Analysis 4. Verification 5. Coding 6. Testing.
Algorithmic Problem Solving IS 101Y/CMSC 101 Computational Thinking and Design Tuesday, September 10, 2013 Marie desJardins University of Maryland, Baltimore.
Lecture 71 CS110 Lecture 8 February 19, 2004 Announcements –hw3 due tonight –hw4 available, due Thursday February 26 –exam Tuesday March 2 Agenda –questions.
Introduction to Python Dr. José M. Reyes Álamo. 2 Three Rules of Programming Rule 1: Think before you program Rule 2: A program is a human-readable set.
Simulation and Modeling: Predator-Prey Processing Lab IS 101Y/CMSC 101 Computational Thinking and Design Tuesday, September 23, 2014 Carolyn Seaman Susan.
Chapter 3 Decisions Three control structures Algorithms Pseudocode Flowcharts If…then …else Nested if statements Code blocks { } multi statement blocks.
1 The Software Development Process ► Systems analysis ► Systems design ► Implementation ► Testing ► Documentation ► Evaluation ► Maintenance.
INVITATION TO Computer Science 1 11 Chapter 2 The Algorithmic Foundations of Computer Science.
Data: Programming Design and Modularization IS 101Y/CMSC 101 Computational Thinking and Design Thursday, September 25, 2014 Carolyn Seaman Susan Martin.
Test Review. General Info. All tests will be comprehensive. You will be tested more on your understanding of code as opposed to your ability to write.
Chapter 1 The Phases of Software Development. Software Development Phases ● Specification of the task ● Design of a solution ● Implementation of solution.
Chapter 2: Algorithm Discovery and Design Invitation to Computer Science.
Chapter 2: Data and Expressions. Variable Declaration In Java when you declare a variable, you must also declare the type of information it will hold.
Progression in KS3/4 Algorithms MONDAY 30 TH NOVEMBER SUE SENTANCE.
Review A program is… a set of instructions that tell a computer what to do. Programs can also be called… software. Hardware refers to… the physical components.
11 Making Decisions in a Program Session 2.3. Session Overview  Introduce the idea of an algorithm  Show how a program can make logical decisions based.
Algorithm Discovery and Design
Vocabulary Algorithm - A precise sequence of instructions for processes that can be executed by a computer Low level programming language: A programming.
Just Enough Java 17-May-19.
Presentation transcript:

Abstraction IS 101Y/CMSC 101 Computational Thinking and Design Tuesday, September 9, 2014 Carolyn Seaman Susan Martin University of Maryland, Baltimore County

Big Idea: Abstraction Abstraction is the process of generalizing away from the details of a problem to simplify and focus on its key aspects We use abstraction for problem solving, design, organization, and simplification Examples from everyday life: Smart thermostats Maps Steering wheel Restaurant menu Language!!

Abstraction in Computing Abstraction is ubiquitous in all computing disciplines Data is “All Just Bits” but… The interpretation (meaning) of data depends on how it is used The same bit sequence can represent an integer, a decimal number, a sequence of characters, or anything else you might decide it means Programming languages are abstractions of machine language Layers of computing hardware, including gates, chips, and components Programs are abstractions of the problem being solved Functional decomposition == layers of abstraction Models and simulations are abstractions of real-world phenomena We can study, analyze, and experiment with models more easily than experimenting on the real world

Programming Programs are written to execute algorithms Requires an understanding of how instructions are processed Programs are executed to automate processes A single program can be run multiple times, on many machines Executable programs increase the scale of solvable problems Programming is facilitated by appropriate abstractions Functions are re-usable programming abstractions Parameterization can be used to generalize a specific solution Data abstraction can separate behavior from implementation APIs and libraries simplify complex programming tasks Programs are developed and used by people Developing programs is an iterative process Finding and eliminating errors is part of the process Documentation is needed for maintainable programs

Big Idea: Design Problem solving often produces multiple possible solutions Or multiple ways to implement the solution Design is the process of making those decisions and choices Design at a high level Is it cost-effective to automate kidney exchange? Should we use a relational or object-oriented database? Design at a low level How do I structure this function? What do I call this variable?

Design Process for Programs First, understand the problem clearly Second, write the solution in English Test its correctness by manually applying it to some simple – and then more complex -- examples Optionally, “translate” the solution into pseudocode Advanced programmers will use this step as an abstraction to avoid the syntactic details of a particular programming language Next, translate the solution into a programming language Finally, implement (type) and test (carefully!) your solution

Example: Counting Print the numbers from one to N N is a variable that can change each time the program is called For example, “printNumbers (7)” should print:

Counting in English: Attempt #1 First attempt at English: Count from one to N Print out each number Not really an algorithm – just a restatement (what is the primitive action “count”??)

Counting in English: Attempt #2 Next attempt: Set the variable “current” to 1 Print the value of “current” Add one to “current” If “current” is greater than N, stop Otherwise, go back to “print” step Turns out that “go to” statements are bad design (for reasons we’ll talk about later) Let’s try it again, using something that looks more like a loop with a condition

Counting in English: Attempt #3 (almost right!) Set the variable “current” to 1 While “current” is less than N: Print the value of “current” Add one to “current” Test by hand: what if N = 3? Boundary cases: what if N = 0? N = -4? Possible error cases: what if N = 8.73? what if N = “this isn’t a number”?

Counting in English: Processing Version void printNumber (int N) { int current = 1; while (current <= N) { println (current); current = current + 1; }

Exercise: Multiplication Work in your team – OK to split into smaller groups of 2 or 3 when you’re at the implementation step How would you multiply two numbers, using only the addition operator? Understand the problem – state some examples Write the solution in English Test the English solution! Write the solution in pseudocode Test the program on paper Concepts: iterations, efficiency

Break Announcements Visitor on Thursday I’m away next week Reminders?

Processing Language for programming graphical and interactive computations

Processing Demonstration “My Crazy Squares” by Marcella Todaro CrazySquares.pde

Processing: Program Basics setup: initialize the display void setup() { size (500, 500); } draw: invoked each time step to update the display. Example: void draw() { if (mousePressed) { background(0); } else { background(255); } } A ; character is needed after every statement in Processing size() is a function that changes the size of the display window. size(w,h) sets the display to be w pixels wide and h pixels high. background() changes the color of the display background. 0 is black; 255 is white; numbers in between are shades of gray. If you give three values to background(), it uses them as RGB (red/green/blue) color components.

Processing: Defining Variables A variable stores a piece of information (i.e., a value) Variable types: int (integer) float (real-valued) boolean (“true” or “false”) char (character, such as ‘x’ or ‘+’) Variable definition: [= ] Examples: int brightness = 0; float xPosition; boolean makeBrighter; Variable definitions should always go at the top of your program or at the beginning of a function Variables should have meaningful names. We’ll generally use “camel case” as shown here to separate words in a variable name.

Processing: Manipulating Variables Changing the value of a variable: = must be an expression that evaluates to a value of the correct type Examples: brightness = 255; brightness = brightness + 1; brightness++; xPosition = xPosition – 3.0; makeBrighter = ! makeBrighter; Note: White space (spaces, tabs, carriage returns) are ignored by Processing – white space is primarily used to make code more readable The “!” operator means “not” – it changes “true” to “false” and “false” to “true”. Other boolean operators include && (and) and || (or) These do the same thing! What do you think “brightness--” does?

Processing: Drawing Pictures Lines: line(x1, y1, x2, y2); Basic shapes: rect(x, y, width, height); // x,y = upper left ellipse (x, y, width, height); triangle(x1, y1, x2, y2, x3 y3); General polygon: beginShape(); vertex(x,y);...; endShape(); Line attributes: strokeWeight(thickness); fill(grayscale) OR fill(R, G, B); All locations on the screen are specified by two values: x (distance from left edge) and y (distance from top edge). The upper left corner is (0, 0).

Processing: Conditionals { } { } else { } Example: if ( makeBrighter ) { brightness--; } else { brightness++; }

Processing: for Loops for ( ; ; ) { } Performs the initialization step Tests - if false, STOPS! Else... Performs Goes back to “Tests” step Example: int i; for ( i=0 ; i<3 ; i++ ) { rect (100*i, 50, 50, 50); }