Great Programming Ideas - PowerPoint PPT Presentation

About This Presentation
Title:

Great Programming Ideas

Description:

Great Programming Ideas John C. Ramirez Link to Learn Workshop University of Pittsburgh – PowerPoint PPT presentation

Number of Views:88
Avg rating:3.0/5.0
Slides: 31
Provided by: John1553
Category:

less

Transcript and Presenter's Notes

Title: Great Programming Ideas


1
Great Programming Ideas
John C. Ramirez Link to Learn Workshop University
of Pittsburgh
2
Tentative Workshop Outline
  • Week 1) Introduction Computer Hardware and
    Software and Programming Languages
  • Week 2) Using Procedures, Functions and Objects
    to Improve Our Programs
  • Week 3) Creating a User-Interface with Graphical
    Components and Event-Driven Programming
  • Week 4) Using Multi-Threading to Do Many Things
    "at the Same Time"
  • Week 5) Servers and Clients How Computers
    Interact with Each Other
  • Week 6) Programming for the Internet

3
Week 1 Introduction to Computers
  • What is a Computer?
  • A bunch of (very fragile) circuits
  • A machine capable of performing millions of
    computations every second
  • A device consisting of hardware (the physical
    part) and software (the programs)
  • The "brain" of most electronics you buy
  • That "thing" that sits in the den and
    occasionally makes strange noises
  • The person next to you in 7th period class

4
Week 1 Introduction to Computers
  • Let's look at a typical PC (personal computer)

TOWER
MONITOR
KEYBOARD
MOUSE
5
Week 1 Introduction to Computers
  • Of course, the tower (or desktop) contains many
    components itself
  • CPU
  • "Brain" of computer
  • Executes instructions and performs calculations
  • Main Memory (MM)
  • Stores instructions and data (in binary)
  • Hard Drive, Floppy Drive, DVD (or CD-ROM)
  • Secondary memory
  • Store information on a semi-permanent basis
  • Also (HD and DVD) have much higher capacity than
    MM

6
Week 1 Introduction to Computers
  • Zip Drive
  • Gradually replacing floppy drive
  • Much higher capacity
  • Modem
  • Allows communication with other computers over
    phone lines
  • Sound Card, Video Card
  • Enable advanced digital sound and graphics
  • Ethernet Card
  • Allows communication with other computers over a
    dedicated network
  • Let's look at some of these

7
Week 1 Computer Hardware
  • Components we have seen are the computer HARDWARE
  • Can you think of any other components of computer
    hardware?
  • Printer
  • Scanner
  • Image scanner
  • Barcode reader
  • Digital camera
  • Sensors
  • Anti-lock brakes
  • Motion detectors

8
Week 1 Computer Software
  • Also essential to a computer is its SOFTWARE
  • The programs that enable a computer to work
  • We can put software into different groups
  • System software
  • Allows your computer itself to work correctly and
    allows you to use it
  • Application software
  • Programs to do specific tasks for you

9
Week 1 Computer Software
  • Some well-known examples
  • System software
  • Application software
  • MS Windows (variations)
  • Mac OS
  • Unix
  • Linux
  • Corel WordPerfect, MS Word (word processing)
  • Lotus 123, MS Excel (spreadsheet)
  • Oracle, MS Access (database)
  • Intuit QuickBooks, MS Money (accounting)
  • Thousands of (games)

10
Week 1 Programming Languages
  • We must write computer software using some kind
    of PROGRAMMING LANGUAGE
  • Some PL history
  • Computer "speaks" binary, so this is the way
    early programs were written Machine Language
  • Each instruction to the computer must be written
    as a binary code
  • Programmer had to know all of the codes
  • Each different type of machine had is own codes
  • Very tedious to write and debug!

11
Week 1 Programming Languages
Where is that stupid error? I'm almost out of
coffee!
1000010110011100 1001001000100110 1010110011000110
1101101010101100 1100100110110010
Oh of course! NOT 1100100110110010! It's
CLEARLY 1100100110110011!
12
Week 1 Programming Languages
  • So programming evolved to ASSEMBLY CODE
  • Short, simple commands that correspond to machine
    language instructions
  • Easier for programmer to remember and use
  • ADD
  • LOAD
  • STORE
  • But still low-level and still specific to a given
    type of machine

13
Week 1 High-Level Languages
  • The next step of improvement was HIGH-LEVEL
    LANGUAGES (HLLs)
  • More English-like in syntax
  • Platform-independent
  • I can write the program and it will work on any
    machine
  • Easier to debug
  • How is this possible?
  • Computer only understands binary!
  • We need to use a COMPILER
  • Program whose job is to translate a program from
    HLL code into machine code
  • Each machine needs its own compiler

14
Week 1 High-Level Languages
input
output
source code (ex. C, Pascal, Java)
compiler
executable code (ex. .exe)
Programmer understands and is independent of any
computer
Only understood by type of computer that it was
compiled for
15
Week 1 High-Level Languages
  • HLLs have also evolved over the years
  • Added different control structures
  • Allows looping, conditional execution
  • We can do in one statement what would take many
    machine code instructions
  • Subprograms and recursion
  • Subprograms allow us to break our programs into
    smaller pieces
  • Recursion allows us to write algorithms in a
    mathematical way
  • Objects and object-oriented programming
  • Associate data and operations together in one
    entity
  • Allows for inheritance and polymorphism
  • Graphical environments and event-driven
    programming
  • Much easier for users

16
Week 1 High-Level Languages
  • Run-time error handling
  • Keeps our programs from crashing
  • Important if program is running something
    critical
  • Parallel (and pseudo-parallel) execution
  • Do many things "at the same time"
  • Useful for servers, animations, etc.
  • Tools for programming over the internet
  • Clients and Servers can connect and interact
  • Web page forms can be processed
  • Lets computers work with each other remotely
  • We will be discussing and looking at many of
    these things in the next few weeks

17
Week 1 Basic Language Features
  • What do we need in a programming language?
  • A way to store data
  • Variables
  • Arrays for multiple values

scores
21499.99
price
223
age
18
Week 1 Basic Language Features
  • Program variables are not the same as math
    variables
  • We really can think of them as names for memory
    locations
  • We can change the data in those locations any
    time we want to
  • A way to manipulate data
  • Allow us to work with our data
  • Ex. for numbers we have our arithmetic operators
  • , , , / and others (ex. input, output,
    comparing)
  • price price - 1000 // rebate offered
  • age age 1 // coming on July 4
  • cin gtgt scores4 // read new value
  • // for score

19
Week 1 Basic Language Features
  • For more advanced data we can define our own
    operations
  • Modern programming languages require us to create
    our own data types
  • We must define the nature of the data
  • We must also define how the data can be
    manipulated
  • Ex. a Stack
  • Collection of data for which you can add and
    remove items ONLY on the top
  • Operations traditionally called Push and Pop
  • Push(data) add data to the top of the stack
  • Pop(data) remove data from the top of the stack
  • Data in the "middle" cannot be accessed
  • Let's see how this works

20
Week 1 Creating a Stack Data Type
  • How can we create our Stack?
  • Let's first see how it would operate
  • Download the files below from Exercises link of
    the Great Programming Ideas Web Site
    http//www.cs.pitt.edu/ramirez/L2L/
  • StackDemo1.class, StackDemo11.class,
    StackDemo1ShapePanel.class, StackDemo1ButtonHand
    ler.class, Stack1.class
  • Save them to C\temp or to your floppy disk if
    you have one
  • Start the program Command Prompt from your Start
    menu
  • Change the directory in your prompt to the one in
    which your files are located
  • Ex cd C\temp

21
Week 1 Creating a Stack Data Type
  • Execute the command
  • java StackDemo1
  • So how will the data for the Stack look?
  • We need an array of locations to store the data
  • We need a "marker" for the top of the stack
  • How will we implement push()?
  • Put the data into the next location of the array
  • Add one to our "marker" -- it has moved up
  • How will we implement pop()?
  • Think about thisall we really need to do is to
    move the "marker" back down
  • But often we like pop() to return the item that
    was removed, so we should do that as well

22
Week 1 Creating a Stack Data Type
  • Download the following files from the Exercises
    link of the Web site
  • StackDemo1.java, Stack1.java
  • Save them to the same directory
  • Start the Notepad program from your Start menu
  • In the File menu, select Open, and locate the
    Stack1.java program in your directory
  • Now let's try to fill in the missing code
  • To test, compile and run the program
  • javac StackDemo1.java
  • java StackDemo1

23
Week 1 Problems with the Stack
  • You probably noticed some problems with the Stack
  • Causes an error (notice Command Prompt) if you
    pop when it is empty
  • Causes an error if you push when it is full
  • We need to add more code so as to handle these
    problems
  • Note that the problems don't always occur
  • We need CONDITIONAL EXECUTION
  • Only execute when a condition occurs

24
Week 1 Control Statements
  • In our programs, we may want to
  • Maybe execute something and maybe not
  • Choose between different blocks to execute
  • Repeat execution of a block
  • HLLs provide us with many CONTROL STATEMENTS to
    accomplish this
  • Statements that alter/determine the flow of
    execution of our programs

25
Week 1 Control Statements
  • if (it_is_raining)
  • take_an_umbrella

if (i_am_in_AAA) cost 75.00 else cost
85.00
while (i_have_money_left) buy_an_item subtrac
t_price_from_my_money
26
Week 1 Improving the Stack
  • What does our Stack need?
  • A way to determine if it is empty or full
  • We'll add another operation for each of these
  • What condition indicates empty and full?
  • A way to test this condition prior to pop()ing or
    push()ing
  • Modify pop() and push()
  • Download StackDemo2.java, Stack2.java from the
    Exercises link of the Web site
  • In the same way as for previous files
  • Edit Stack2.java from Notepad

27
Week 1 Improving the Stack
  • Fill in the code for isEmpty() and isFull() and
    modify push() and pop() so that they can never
    cause the error we saw before
  • If you think you fixed it, compile and run the
    program as before
  • javac StackDemo2.java
  • java StackDemo2

28
Week 1 Improving the Stack
  • Do you still find any problems with it?
  • Notice what happens when you pop() an empty Stack
    or push() a full stack
  • Program does not crash, but your main still acts
    as if the command was successful
  • This is called a LOGIC ERROR
  • A program gives unexpected and/or incorrect
    results
  • Difficult to detect without previous knowledge of
    what the correct results should be
  • How can we fix this error?
  • Must modify StackDemo2.java to also test for the
    full and empty Stack conditions
  • Modify it, recompile and run to see if you have
    fixed it!

29
Week 1 Improving the Stack
  • In case you had trouble
  • You can download complete versions of the
    programs from the Solutions page of the Web Site
  • If you don't want them to overwrite your
    versions, rename your programs (ask me if you
    don't know how) or put the new ones into a
    different directory (again, ask if you need help)

30
Week 1 Conclusions
  • Today we learned
  • Basic components of a computer
  • Some history of programming languages
  • Reason for high-level languages
  • Fundamental features of high-level languages
  • Variables to store data
  • Operations to manipulate data
  • Control structures to alter execution
  • How a Stack works and how to implement it
Write a Comment
User Comments (0)
About PowerShow.com