CS 1321. CS1321: Introduction to Programming Georgia Institute of Technology College of Computing Lecture 6 Sept 6th, 2001 Fall Semester.

Slides:



Advertisements
Similar presentations
Summer Computing Workshop. Introduction to Variables Variables are used in every aspect of programming. They are used to store data the programmer needs.
Advertisements

Demonstration Speech Goal: To convey clear instructions to enable a person to effectively complete a task Opener Introduction Benefits Task Breakdown Use.
How to study for A&P Adapted from “get ready for A&P” By Lori K. Garrett.
Events Part III The event object. Learning Objectives By the end of this lecture, you should be able to: – Learn to use the hover() function – Work with.
Exponential Functions Logarithmic Functions
QUOTING THINGS CORRECTLY "Did you think to kill me? There's no flesh and blood within this cloak to kill. There is only an idea. Ideas are bulletproof.
EXPOSITORY ESSAY Mrs. Carrie Hunnicutt 6 th Grade ELAR
M. George Physics Dept. Southwestern College
Sampling Distributions
Solving Linear Equations
Welcome to SCEN101 Physics for Poets George Watson Sharp Lab 232 Office Hours: Monday 7:25-8:15am Friday 5:00-6:00pm.
Quantum Theory of Hydrogen shrödinger's equation for hydrogen separation of variables “A facility for quotations covers the absence of original thought.”—
CS 106 Introduction to Computer Science I 10 / 16 / 2006 Instructor: Michael Eckmann.
Allen Daniel. Problem Solving Method (chip envelope) What I learned from this project is that things need a lot of planning before you are finished with.
Multiplication and Division Addition and Subtraction PracticeExponentsParenthesesHomeQuizIntroduction Objective and Standards Please Excuse My Dear Aunt.
A quadratic equation is a second degree polynomial, usually written in general form: The a, b, and c terms are called the coefficients of the equation,
Moreno Valley High School January 2013
CS CS1321: Introduction to Programming Georgia Institute of Technology College of Computing Lecture 5 Sept 4th, 2001 Fall Semester.
Lecture 18 Page 1 CS 111 Online Design Principles for Secure Systems Economy Complete mediation Open design Separation of privileges Least privilege Least.
READING FOR HIGH SCHOOL AND BEYOND. WHAT I DO NOW: *BEFORE I READ *WHEN I READ *AFTER I FINISHBEFORE I READWHEN I READAFTER I FINISH Reading Actively.
Conditional & Joint Probability A brief digression back to joint probability: i.e. both events O and H occur Again, we can express joint probability in.
© Worth Weller. Your essays must be your own words with your own thoughts and your own voice. However, quoting sources in your essays:  adds authority.
Object Oriented Programming Philosophy. Part 1 -- Basic Understanding & Encapsulation.
Unit 1 (Chapter 5): Significant Figures
Programming with Alice Computing Institute for K-12 Teachers Summer 2011 Workshop.
CS CS1321: Introduction to Programming Georgia Institute of Technology College of Computing Lecture 11 Sept 27th, 2001 Fall Semester.
+ The Practice of Statistics, 4 th edition – For AP* STARNES, YATES, MOORE Chapter 8: Estimating with Confidence Section 8.1 Confidence Intervals: The.
Descriptive Statistics A Short Course in Statistics.
Computer Engineering 1 nd Semester Dr. Rabie A. Ramadan 1.
Chapter 26 Michelson-Morley Continued Relativistic Energy and Momentum.
+ The Practice of Statistics, 4 th edition – For AP* STARNES, YATES, MOORE Chapter 8: Estimating with Confidence Section 8.1 Confidence Intervals: The.
+ Warm-Up4/8/13. + Warm-Up Solutions + Quiz You have 15 minutes to finish your quiz. When you finish, turn it in, pick up a guided notes sheet, and wait.
1 Lesson 8: Basic Monte Carlo integration We begin the 2 nd phase of our course: Study of general mathematics of MC We begin the 2 nd phase of our course:
How the secant line became the tangent line A story of two points coming together Note: This was converted from a Keynote presentation so some of the formatting.
Math 105: Problem Solving in Mathematics
Algorithms CS139 – Aug 30, Problem Solving Your roommate, who is taking CS139, is in a panic. He is worried that he might lose his financial aid.
Compound Data. Last Lecture Booleans Only two elements Symbols Not to be confused with variables Strings Notions of equality on values.
Three Cs Clarity Conciseness Consistency. Clarity Being clear is our main priority when communicating. What might prevent us from communicating clearly?
Welcome to CS61A Disc. 29/47 :D Dickson Tsai OH: Tu, Th 4-5pm 411 Soda Previous stop: None >>> Today: Working effectively in.
Writing & Graphing Inequalities Learning Target: Today I am learning how to write and graph inequalities on the number line because I want to be able.
Grade Book Database Presentation Jeanne Winstead CINS 137.
CS CS1321: Introduction to Programming Georgia Institute of Technology College of Computing Lecture 10 Sept 25th, 2001 Fall Semester.
Paper writing tips This will be short … kind of How to use Word to build references For every fact you need to credit, you must use an in-text citation.
1 CS161 Introduction to Computer Science Topic #9.
Solution of. Linear Differential Equations The first special case of first order differential equations that we will look is the linear first order differential.
CS 106 Introduction to Computer Science I 09 / 26 / 2007 Instructor: Michael Eckmann.
CRE Programming Club - Class 2 Robert Eckstein and Robert Heard.
Getting the Interview: Make your Application Stand Out and Get Noticed Matthew Heiydt.
Order of Operations Tutorial By: Melissa Griswold Lesson Examples Assessment Use the navigation buttons on the left to begin. If you are just beginning.
Math 010 online work that was due today at the start of class: Section 1.3A Online Homework.
The Last Lecture CS 5010 Program Design Paradigms "Bootcamp" Lesson © Mitchell Wand, This work is licensed under a Creative Commons Attribution-NonCommercial.
CS CS1321: Introduction to Programming Georgia Institute of Technology College of Computing Lecture 13 October 4, 2001 Fall Semester.
Algebra Geek Patrol The Pocket Protectors of Algebra  2007 Scott Endres.
The expected value The value of a variable one would “expect” to get. It is also called the (mathematical) expectation, or the mean.
Relations And Functions © 2002 by Shawna Haider. A relation is a set of ordered pairs. {(2,3), (-1,5), (4,-2), (9,9), (0,-6)} This is a relation The domain.
+ The Practice of Statistics, 4 th edition – For AP* STARNES, YATES, MOORE Chapter 8: Estimating with Confidence Section 8.1 Confidence Intervals: The.
Instructor: Chris Trenkov Hands-on Course Python for Absolute Beginners (Spring 2015) Class #003 (February 14, 2015)
Division Brought to you by powerpointpros.com. Lesson Menu Click on the links below to start with a specific topic. What is Division? Using Division Practice.
DSMA 0399 Comments of Past Students. DSMA 0399 Student Comments “Before this class as you probably remember I would not even accept that x or y could.
The Best Prepared Wins Tips For Better Presentations.
Writing & Graphing Inequalities Learning Target: Today I am learning how to write and graph inequalities on the number line because I want to be able.
Lesson 8: Basic Monte Carlo integration
Lesson 16: Functions with Return Values
Theory of Computation Turing Machines.
Chapter 8: Estimating with Confidence
Chapter 8: Estimating with Confidence
Chapter 8: Estimating with Confidence
Chapter 8: Estimating with Confidence
Validity and Soundness, Again
Presentation transcript:

CS 1321

CS1321: Introduction to Programming Georgia Institute of Technology College of Computing Lecture 6 Sept 6th, 2001 Fall Semester

Today’s Menu I.Review of Structures II.Structures and your Design Recipe a. The Data Definition (the beginning) b. The Template III. Working it Through

Last Time… We explored the concept of a Structure. Let’s review a little…

What is the purpose of a Structure? How do we define a Structure? They group data that belongs together (such as the X & Y coordinates of a point) into a single unit. We use the Scheme function (define-struct …) What’s the format of (define-struct …)? (define-struct ( … ))

When I define a structure, have I created a Structure? When I define a structure, what does Scheme create for me? NO! A Constructor Multiple Accessors (or called Selectors) A Predicate

So let’s go back to our previous example….

BAD PHOTOGRAPHS!

What functions are generated for the following Definition?

1. make-badphoto 2. badphoto-first 3. badphoto-last 4. badphoto-date 5. badphoto-level 6. badphoto? 1 is the constructor, 2-5 are all selectors, 6 is a predicate function

How this changes your Design Recipe (Part I) Several of you probably have the thought: “Well, couldn’t I just stick anything in my posn or badphoto structures? What’s to prevent me from saying: (make-posn ‘George ‘Burdell) (make-badphoto ‘Bubba)?”

Absolutely nothing… say it again… It’s up to the user to insert the correct data in the correct places. So how do you communicate with the user about what you’re expecting to be stored in your structures?

So this changes my Design Recipe, right? YES! As an example, let’s change our old familiar posn structure into a dot structure. Dots are little filled-in circles with varying colors but uniform size. Each dot should have it’s own location represented by an x & y position. X y

Further… We want a function that consumes two dots and resolves to the distance between the two dots.

Most of what we’re doing here is a definition Here, we tell the user what should go inside a dot!

This is a constant for all dots!

One last note… Something to think about for future lectures: IS THERE A BETTER WAY TO DO THIS? CAN I DO THIS WITHOUT DUPLICATING EFFORT?

Continuing We’re back to normality for a second…

Another Difference… We’ve now introduced the idea of a Template. But what’s the idea of a Template?

The Template is an example of what can be done with our data definition. It shows the form that MOST functions that use a particular data definition will follow… A couple of things to note…

It is NOT the solution to whatever problem we’re solving We’re writing “distance”, remember? It shows everything that could be done with our data definition These are the functions associated with our data definition, remember?

Finishing up… This is ugly. You should use better abstraction to make this easier to read. (Do as I say, not as I do)

Now, let me predict your questions… Starting with Data Definitions: 1)Do Data Definitions deal with JUST structures? No, but more on that in the next chapter… 2)Do I have to put my structure definition in my data definition section? Yes

3)If I create a data definition for problem X, and I use the same data definition in problem X+1, do I have to retype the data definition? Do I have to re- declare the struct? No, you do NOT have to re-declare the data definition or re-declare the struct. It is sufficient to say: ;; I’m using data definition from ;; Problem X

Template questions… 1)The function in the template isn’t the same as the one I’m writing… The function in the template will NOT be exactly like the one you’re writing. The template is an example what is possible, given your Data Definition. It is NOT etched in stone that you will call the functions exactly as shown. In the distance example, we never even called “dot-color”. It wasn’t necessary to work the problem. However, the Template did show that when you take in a value that follows the definition of a structure, you could call “dot-color”

2)If I’m using the same data definition in problem X+1 as I did in problem X, do I have to repeat the template? Yes. 3)But you just told me I didn’t have to do that for the Data Definition. What gives? The purpose of the Template is different from the Data Analysis and Definition section. The Template serves as a reminder of your possible choices when using a particular Data Definition. There’s a reason that it appears right above the Definitions section. Believe it or not, it will keep you from making mistakes. As you work with Templates more, you’ll find that the solutions to your problems fall right out from the Template.

How ‘bout one more example? So for those of you who follow (American) football, you might recall that each game is divided into four quarters. During the course of each quarter, both teams involved do their darnedest to score points on the opposing team, with the goal of having more points at the end of the game than the opposing team. I happen to just be mad about statistics, and I want to be able to group together information about how my team did over the course of the game.

I want to be able to store the following information: The points my team scored during the first quarter The points my team scored during the second quarter The points my team scored during the third quarter The points my team scored during the fourth quarter The total number of points scored Furthermore…

I want a function that will consume one of these structures I just defined and calculate the average number of points scored by my team over the course of a game. Let’s get started!

First, DA&D ;; Data Analysis & Definition (define-struct game (first second third fourth total)) ;; A game is a structure: (make-game a b c d e) ;; where a, b, c, d, e are numbers

Then, the usual stuff ;; Contract: game-average : game -> number ;; Purpose: This function calculates the average ;; number of points scored by my team ;; over the course of a game ;; Example: (game-average (make-game )) ;; should produce 6

The Template ;; Template: ;; (define (process-game in-game) ;; … (game-first in-game)… ;; … (game-second in-game)… ;; … (game-third in-game)… ;; … (game-fourth in-game)… ;; … (game-total in-game)…)

Definition & Testing ;; Definition: (define (game-average in-game) (/ (+ (game-first in-game) (game-second in-game) (game-third in-game) (game-fourth in-game)) 4)) ;; Tests: (= (game-average (make-game )) 6)