Building Abstractions with Variables (Part 1) CS 21a: Introduction to Computing I First Semester, 2013-2014.

Slides:



Advertisements
Similar presentations
CS107: Introduction to Computer Science Lecture 2 Jan 29th.
Advertisements

CHAPTER 2 GC101 Program’s algorithm 1. COMMUNICATING WITH A COMPUTER  Programming languages bridge the gap between human thought processes and computer.
CS0007: Introduction to Computer Programming Console Output, Variables, Literals, and Introduction to Type.
CS105 INTRODUCTION TO COMPUTER CONCEPTS INTRO TO PROGRAMMING Instructor: Cuong (Charlie) Pham.
CMPT 354, Simon Fraser University, Fall 2008, Martin Ester 52 Database Systems I Relational Algebra.
Chapter 2: Algorithm Discovery and Design
ECE122 L3: Expression Evaluation February 6, 2007 ECE 122 Engineering Problem Solving with Java Lecture 3 Expression Evaluation and Program Interaction.
CS 201 Functions Debzani Deb.
Programming Fundamentals (750113) Ch1. Problem Solving
ECE122 L17: Method Development and Testing April 5, 2007 ECE 122 Engineering Problem Solving with Java Lecture 17 Method Development and Testing.
Chapter 2: Algorithm Discovery and Design
ECE122 L9: While loops March 1, 2007 ECE 122 Engineering Problem Solving with Java Lecture 9 While Loops.
OBJECT ORIENTED PROGRAMMING IN C++ LECTURE
Writing algorithms using the while-statement. Previously discussed Syntax of while-statement:
CS61A Lecture 2 Functions and Applicative Model of Computation Tom Magrino and Jon Kotker UC Berkeley EECS June 19, 2012.
Programming Languages CPS120: Introduction to Computer Science Lecture 5.
GENERAL CONCEPTS OF OOPS INTRODUCTION With rapidly changing world and highly competitive and versatile nature of industry, the operations are becoming.
Structure and Interpretation of Computer Programs Presented by Yan Yan CSE 294, UCSD, April 13, Chapter Harold Abelson, Gerald and Julie.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 122 – Data Structures Recursion Review.
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.
Introduction to Computational Linguistics Programming I.
Spring 2005, Gülcihan Özdemir Dağ Lecture 3, Page 1 BIL104E: Introduction to Scientific and Engineering Computing, Spring Lecture 3 Outline 3.1 Introduction.
University of Toronto Department of Computer Science CSC444 Lec05- 1 Lecture 5: Decomposition and Abstraction Decomposition When to decompose Identifying.
Nonvisual Arrays and Recursion by Chris Brown under Prof. Susan Rodger Duke University June 2012.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Structural Program Development: If, If-Else Outline.
Reading – Chapter 10. Recursion The process of solving a problem by reducing it to smaller versions of itself Example: Sierpinski’s TriangleSierpinski’s.
Copyright 2008 by Pearson Education 1 Building Java Programs Chapter 2 Lecture 2-1: Expressions and Variables reading:
Lecture 11 Data Structures, Algorithms & Complexity Introduction Dr Kevin Casey BSc, MSc, PhD GRIFFITH COLLEGE DUBLIN.
PROGRAM DEVELOPMENT CYCLE. Problem Statement: Problem Statement help diagnose the situation so that your focus is on the problem, helpful tools at this.
Useful IDLE Alt-ENTER Commenting-out. Writing a Program CMSC 120: Visualizing Information 2/14/08.
Methods. Methods also known as functions or procedures. Methods are a way of capturing a sequence of computational steps into a reusable unit. Methods.
© Janice Regan, CMPT 102, Sept CMPT 102 Introduction to Scientific Computer Programming Introduction to simple functions.
What is the main focus of this course? This course is about Computer Science Geometry was once equally misunderstood. Term comes from ghia & metra or earth.
1/32 This Lecture Substitution model An example using the substitution model Designing recursive procedures Designing iterative procedures Proving that.
Building Abstractions with Variables (Part 2) CS 21a: Introduction to Computing I First Semester,
PHY 107 – Programming For Science. Announcements no magic formulas exist  Need to learn concepts: no magic formulas exist  Single solution not useful;
Chapter 2: Algorithm Discovery and Design Invitation to Computer Science.
CS Class 04 Topics  Selection statement – IF  Expressions  More practice writing simple C++ programs Announcements  Read pages for next.
Software. Introduction n A computer can’t do anything without a program of instructions. n A program is a set of instructions a computer carries out.
Copyright © Curt Hill The Assignment Operator and Statement The Most Common Statement you will use.
Some of the utilities associated with the development of programs. These program development tools allow users to write and construct programs that the.
Foundations of Programming: Java
CMSC201 Computer Science I for Majors Lecture 19 – Recursion
Operational Semantics of Scheme
Functional Programming
Algorithms and Problem Solving
Topic: Programming Languages and their Evolution + Intro to Scratch
MSc/ICY Software Workshop , Semester 2
Computational Thinking, Problem-solving and Programming: General Principals IB Computer Science.
Introduction to Computer Science / Procedural – 67130
CMSC201 Computer Science I for Majors Lecture 18 – Recursion
Java 4/4/2017 Recursion.
The Selection Structure
Programming Fundamentals
Structured Program
Programming Fundamentals (750113) Ch1. Problem Solving
Functional Programming
This Lecture Substitution model
What would be our focus ? Geometry deals with Declarative or “What is” knowledge. Computer Science deals with Imperative or “How to” knowledge 12/25/2018.
Coding Concepts (Basics)
CS105 Introduction to Computer Concepts Intro to programming
What would be our focus ? Geometry deals with Declarative or “What is” knowledge. Computer Science deals with Imperative or “How to” knowledge 2/23/2019.
This Lecture Substitution model
This Lecture Substitution model
CS105 Introduction to Computer Concepts Intro to programming
Structural Program Development: If, If-Else
Lecture 2 - Names & Functions
Lecture 6 - Recursion.
Presentation transcript:

Building Abstractions with Variables (Part 1) CS 21a: Introduction to Computing I First Semester,

Last Time… ► How to write, compile, and run programs in Java ► Introduction to OOP, Java classes and objects

The Next Several Meetings… ► Why OOP? Why does it look so complicated? ► How did programming get that way? ► Step by step development towards OOP

Outline ► Introduction and Motivation ► A Trivial Program ► Combination through Expressions ► Combination through Statements

Three Elements of Every Powerful Programming Language ► Primitives ► Simplest entities in a language ► Combination ► Means by which compound elements are built from simpler ones ► Abstraction ► Means by which compound elements can be named and manipulated as a unit ► Means by which compound elements can be treated as “primitives”

Why Primitives? ► We only care about a certain level of detail. ► There is a point where language ends and action begins. ► Real solutions to real problems must be easily convertible to real means for carrying them out. ► Computers are concerned mainly with performance. ► Limit to the number of primitives allows computers to be efficient.

Why Combination? ► Science demands generality. ► Limit to number of primitives must be compensated by endless possibilities of wholes that can be formed by them. ► Humans need modularity. ► We can’t keep viewing everything in terms of the smallest parts, especially as the systems we’re looking at grow larger and larger.

Why Abstraction? ► Science demands generality. ► Useful solutions are those which can be applied in many circumstances, infinitely many selections of valid input. ► Giving a name to the input data is one of the many abstractions that can allow us to deal with infinity. ► You abstract away from the concrete situation of the world by giving symbols to things and manipulating only the symbols, turning the symbols back into things whenever the concrete situation calls for it.

Why Abstraction? ► Humans need modularity. ► Once we’ve built larger parts out of the smaller parts, there has to be a way to treat the larger parts as small parts to talk about even larger parts. ► Building abstraction barriers allow us to think in different levels of detail and choose one most appropriate to our goal.

Everything

Outline ► Introduction and Motivation ► A Trivial Program ► Combination through Expressions ► Combination through Statements

Note ► Throughout this lecture System.out.print will be abbreviated to just print.

A Trivial Program print( 3 * 2 ); ► 6 is the result of evaluating the expression. ► 6 gets printed out because the computer executed the statement. ► 3 and 2 are operands of the * operator, the result of that ( 6 ) is the argument to the print procedure call. statement expression primitives

A Trivial Program print( 3 * 2 ); ► 6 is the result of evaluating the expression. ► 6 gets printed out because the computer executed the statement. ► 3 and 2 are operands of the * operator, the result of that ( 6 ) is the argument to the print procedure call. statement expression primitives Note: The print procedure in Java is not really a primitive of the Java language, but the beauty of abstraction is that we can regard it as one for our purposes. It is someone else’s obligation to express the print procedure as a combination of lower- level primitives.

Note the Analogy ► Statement ► Procedure Call ► Argument ► More on arguments and procedures later... ► Expression ► Operator ► Operand ► The imperative programming paradigm distinguishes between the two.

Values ► The value of an expression is the result of evaluating it.

A Trivial Program ► Solves a very limited number of problems ► Only one, in fact ► Has no meaning

Outline ► Introduction and Motivation ► A Trivial Program ► Combination through Expressions ► Combination through Statements

Combination through Expressions print( 3 * 2 – ( / 3 )); ► Expressions are recursive in nature and can be nested to form an expression tree. ► Use parentheses to specify evaluation order. ► MDAS is default evaluation order, but is an artefact of tradition and not intrinsic to programming. expression (*, 6)expression (/, 4) expression (+, 8) expression (-, -2)

Not This!

Think ► (Upside down) family tree ► File system ► Organization chart CEO Chief Technical Officer Project Head ResearcherDeveloper Project Head Human Resources Officer Chief Financial Officer node levels

The Recursive Nature of Expressions ► An expression is either ► A single atom ► A number by itself is an expression ► Or a combination of two expressions

The Recursive Nature of Expressions ► Each expression forms a tree. A tree is either ► A single node ► Or combinations of trees joined by a single node.

The Recursive Nature of Expressions ► The value of an expression is ► The value of itself if it’s an atom. ► The result of applying the combination operator on the values of the two expressions, if it’s a combination.

Combination through Expressions ► Try it out on your computers!

Practice ► Draw the expression tree for the following expression: 3*5-(6+3)/(3+2*(7-4)) ► Determine the value at each node.

Practice ► How many nodes are there in the tree? ► How many trees are there in the tree? ► How many expressions are there in the expression? ► How many levels deep does the tree go at the most?

Outline ► Introduction and Motivation ► A Trivial Program ► Combination through Expressions ► Combination through Statements

Combination through Statements ► Another, hopefully obvious, way to combine primitives is to perform them one after the other – direct sequencing. ► Try it: evaluate several expressions and print the results using one program.

Combinations of Expressions/Statements ► Still only solve one problem, but different problems can be solved with different combinations ► Still have no meaning

Summary ► Expressions and statements are the simplest parts of a program. ► Expressions have values. ► Expressions and statements can be primitives or can also be combinations. ► Expressions are combined by operators and nesting, in a recursive manner. ► Expressions can be visualized with trees. ► Statements are combined by direct sequencing.

Practice Programming Problem

Next Time… ► Each combination of expressions/statements only solves one question at a time. ► I don’t want a really expensive calculator. ► How to fix that, next time