Numbers, Expressions, and Simple Programs. Today’s Goals Discipline! Order! Developing programs requires care! Programs are useful but delicate entities.

Slides:



Advertisements
Similar presentations
UFCEKU-20-3Web Games Programming Game Math. UFCEKU-20-3Web Games Programming Agenda Revise some basic concepts Apply Concepts to Game Elements.
Advertisements

Introduction to Programming in C++ John Galletly.
2009 Spring Errors & Source of Errors SpringBIL108E Errors in Computing Several causes for malfunction in computer systems. –Hardware fails –Critical.
Functions in Maple 教授:蔡桂宏 博士 學生:柯建豪 學號: 統資軟體課程講義.
Engineering EG167C - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect M1 P. 1Winter Quarter Midterm I Review.
1 Chapter Six Algorithms. 2 Algorithms An algorithm is an abstract strategy for solving a problem and is often expressed in English A function is the.
INTRODUCTION TO PROGRAMMING
Numeric literals and named constants. Numeric literals Numeric literal: Example: A numeric literal is a constant value that appears in a Java program.
Comp 205: Comparative Programming Languages Functional Programming Languages: Haskell Lecture notes, exercises, etc., can be found at:
CMPT 354, Simon Fraser University, Fall 2008, Martin Ester 52 Database Systems I Relational Algebra.
CSC 160 Computer Programming for Non-Majors Lecture #4: Defining Variables Prof. Adam M. Wittenstein
Complexity Analysis (Part I)
CS 201 Functions Debzani Deb.
CSC 160 Computer Programming for Non-Majors Lecture #7: Variables Revisited Prof. Adam M. Wittenstein
Chapter 7 Expressions and Assignment Statements. Copyright © 2007 Addison-Wesley. All rights reserved. 1–2 Arithmetic Expressions Arithmetic evaluation.
Compiler Construction
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand the structure of a C-language program. ❏ To write your first C.
1 Relational Algebra and Calculus Yanlei Diao UMass Amherst Feb 1, 2007 Slides Courtesy of R. Ramakrishnan and J. Gehrke.
Copyright 2008 by Pearson Education 1 Building Java Programs Chapter 2 Lecture 2-1: Expressions and Variables reading:
Local Definitions, Scope, Functional Abstraction, and Polymorphism.
Language Evaluation Criteria
1. Reference  2  Algorithm :- Outline the essence of a computational procedure, step by step instructions.  Program :- an.
Algorithmic Problem Solving CMSC 201 Adapted from slides by Marie desJardins (Spring 2015 Prof Chang version)
A First Program CSE 1310 – Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington Credits: a significant part of.
Programming Languages: History & Traditional Concepts CSC 2001.
Computer Science 101 Introduction to Programming.
Numeric Data Types Lesson CS1313 Spring Numeric Data Types Outline 1.Numeric Data Types Outline 2.Data Types 3.Integers in Mathematics 4.Integers.
D-1 University of Washington Computer Programming I Lecture 4: Arithmetic Expressions © 2000 UW CSE.
OCR Computing GCSE © Hodder Education 2013 Slide 1 OCR GCSE Computing Python programming 6: Variables and constants.
Ch4 Data Types Every value has a type associated with it. The computer needs to know how much memory to allocate. Every value is either a primitive type.
Summary of what we learned yesterday Basics of C++ Format of a program Syntax of literals, keywords, symbols, variables Simple data types and arithmetic.
David Streader Computer Science Victoria University of Wellington Copyright: David Streader, Victoria University of Wellington Java Programing Basics COMP.
Chapter Twenty-ThreeModern Programming Languages1 Formal Semantics.
What does a computer program look like: a general overview.
Formal Semantics Chapter Twenty-ThreeModern Programming Languages, 2nd ed.1.
Major objective of this course is: Design and analysis of modern algorithms Different variants Accuracy Efficiency Comparing efficiencies Motivation thinking.
Principles of programming languages 5: An operational semantics of a small subset of C Department of Information Science and Engineering Isao Sasano.
Grading Exams 60 % Lab 20 % Participation 5% Quizes 15%
Elements of a Java Program Bina Ramamurthy SUNY at Buffalo.
Copyright 2008 by Pearson Education 1 Building Java Programs Chapter 2 Lecture 2-1: Expressions and Variables reading:
Engineering 1020 Introduction to Programming Peter King Winter 2010.
School of Computing and Mathematics, University of Huddersfield CHA2545: WEEK 4 LECTURE: DENOTIONAL SEMANTICS OF A SIMPLE LANGUAGE TUTORIAL: Do exercises.
1 CSC 221: Computer Programming I Spring 2008 course overview  What did we set out to learn?  What did you actually learn?  Where do you go from here?
Copyright 2010 by Pearson Education 1 Building Java Programs Chapter 2 Lecture 2-1: Expressions and Variables reading:
A First Program CSE 1310 – Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington Credits: a significant part of.
Introduction to Computer Science Lab 1: Numbers and Arithmetic.
Section 02 Numbers, Expressions, Simple Programs Version Prepared by: IT Group Last modified: Apr 04, 2008.
Programming Language Descriptions. What drives PL Development? Computers are “in charge” of extremely important issues Execute a program literally. Exercise.
Volume: The Shell Method
1 Building Java Programs Chapter 2 Lecture 2-1: Expressions and Variables reading:
D-1 University of Washington Computer Programming I Lecture 4: Arithmetic Expressions © 2000 UW CSE.
Clicker Question 1 What is the area enclosed by f(x) = 3x – x 2 and g(x) = x ? – A. 2/3 – B. 2 – C. 9/2 – D. 4/3 – E. 3.
Lecture 3: More Java Basics Michael Hsu CSULA. Recall From Lecture Two  Write a basic program in Java  The process of writing, compiling, and running.
Introduction to Analysis of Algorithms
CSC 221: Computer Programming I Spring 2010
Big-O notation.
CSC 221: Computer Programming I Fall 2005
Primitive Data, Variables, Loops (Maybe)
Chapter 2 ERROR ANALYSIS
Higher-Order Procedures
Objective of This Course
Functional Programming
Building Java Programs
Building Java Programs
Building Java Programs
Building Java Programs
Building Java Programs
Building Java Programs
Compiler Construction CS 606 Sohail Aslam Lecture 1.
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Presentation transcript:

Numbers, Expressions, and Simple Programs

Today’s Goals Discipline! Order! Developing programs requires care! Programs are useful but delicate entities. They run fast but can also easily get derailed. If program running car engine fails, can lead to loss of life To understand programs (“computation”), We should know how to write them correctly … this is more subtle than it seems at first. Coolest thing in this course: Design Recipes.

Why the Scheme Programming Language? Simple syntax (and we'll use only a subset) Function definition Function application Conditionals Structure definitions Local definitions Assignment Simple semantics Can be understood abstractly Can be understood rigorously Nice integrated design environment (IDE)

Computing with Numbers Naturals: 0, 1, 2, … Integers: -1, -12, … Rationals: (3/4), (-5/6), … Reals: pi, e, phi … Complex numbers: (sqrt(-1)) Note: Exact computation is still a an active research topic.

Computer Representations All the above types of numbers can be represented More typically, more limited forms are used: "int" : 5 as (0101) "float" : 0.5*10^6 as (1000), (0110) DrScheme has arbitrarily large integers. But reals are fixed.

Primitive Computation Basic "data types" are good. But operations on them are more fun! (+ 1 2), (* 3 4), or ( 4 2) where  {-,/,exp,mod,div} (+ (+ 1 2) 3) (+ 1 (+ 2 3)) (* (+ 1 2) (+3 4)) How does this compare to 1+2*3+4? Good: Unambiguous: result is 11, 13, 15, or 21!? Bad: Longer!

Defining Our First Program Example: The area of a circle Mathematically, A(r) = pi * r^2 If we approximate pi by 3.14, in DrScheme: (define (area-of-disk radius) (* 3.14 (* radius radius))) Note: “A” became “area-of-disk”, “r” became “radius”. Longer names optional, but help readability! What language constructs do we use here? 1) function definition: “(define …)”, 2) variables: “radius”, 3) primitive operators: “*”, 4) literal constants: “3.14”

Using our first program We've just made a big investment in implementing the formula. What's the benfit from doing that? Now, all we need to do is to type: (area-of-disk 5) This evaluates to = (* 3.14 (* 5 5)) = (* ) = 78.5 Without our procedure definition, we have to type (* 3.14 (* x x)) over and over again…

Now that we know how to implement “area-of-circle”… What other things can we implement? volume of a cone GPA for fixed number of courses sum of a list fixed length list What things can we NOT implement yet GPA for arbitrary number of courses Sum for list of arbitrary list So, we can implement a lot of algorithms, but not all.