1 cs 106, winter 2009 class 4, section 4 slides by: dr. cynthia a. brown,...

26
1 CS 106, Winter 2009 Class 4, Section 4 Slides by: Dr. Cynthia A. Brown, [email protected] Instructor section 4: Dr. Herbert G. Mayer, [email protected]

Post on 19-Dec-2015

220 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: 1 CS 106, Winter 2009 Class 4, Section 4 Slides by: Dr. Cynthia A. Brown, cbrown@cs.pdx.educbrown@cs.pdx.edu Instructor section 4: Dr. Herbert G. Mayer,

1

CS 106, Winter 2009Class 4, Section 4

Slides by: Dr. Cynthia A. Brown, [email protected] section 4: Dr. Herbert G. Mayer, [email protected]

Page 2: 1 CS 106, Winter 2009 Class 4, Section 4 Slides by: Dr. Cynthia A. Brown, cbrown@cs.pdx.educbrown@cs.pdx.edu Instructor section 4: Dr. Herbert G. Mayer,

2

Analysis -> Design

• Determining what a process should do is called analysis or requirements gathering.

• We begin by describing the interface (perhaps with a picture), and writing our use cases and tests

• We determine what our objects and events are, and what internal state the process needs to keep track of.

• At that point we are ready to design our process using flowcharts.

Page 3: 1 CS 106, Winter 2009 Class 4, Section 4 Slides by: Dr. Cynthia A. Brown, cbrown@cs.pdx.educbrown@cs.pdx.edu Instructor section 4: Dr. Herbert G. Mayer,

3

Flowchart process

• Start with a list of objects and their events, along with the internal state you need to keep track of. Be flexible… you may discover the need for more events or state variables as you design the process

• Make a flowchart for each event• Using the flowcharts, walk through the use

case tests and make sure everything works properly

Page 4: 1 CS 106, Winter 2009 Class 4, Section 4 Slides by: Dr. Cynthia A. Brown, cbrown@cs.pdx.educbrown@cs.pdx.edu Instructor section 4: Dr. Herbert G. Mayer,

4

Flowchart Symbols

Flowline: Connects symbols and indicates the flow of logic.

Input/Output: Data to be read or displayed are described inside.

Terminal: Represents the beginning or end of a task.

Processing: The process description is includedinside the symbol.

Decision: Used for logic/comparison operations. Hasone entry and two exits.

Page 5: 1 CS 106, Winter 2009 Class 4, Section 4 Slides by: Dr. Cynthia A. Brown, cbrown@cs.pdx.educbrown@cs.pdx.edu Instructor section 4: Dr. Herbert G. Mayer,

5

One more…

Continuation

Page 6: 1 CS 106, Winter 2009 Class 4, Section 4 Slides by: Dr. Cynthia A. Brown, cbrown@cs.pdx.educbrown@cs.pdx.edu Instructor section 4: Dr. Herbert G. Mayer,

6

Money Input Slot: Version 2 User Inserts Coin

end

Nickel?

MonEnt<- MonEnt + .05 Dime?

MonEnt<- MonEnt + .10 Quarter?

MonEnt<- MonEnt + .25

yes no

yes

end

no

yes

end

no

Return coin

end

Page 7: 1 CS 106, Winter 2009 Class 4, Section 4 Slides by: Dr. Cynthia A. Brown, cbrown@cs.pdx.educbrown@cs.pdx.edu Instructor section 4: Dr. Herbert G. Mayer,

7

Selection Button AEvent Flowchart

Page 8: 1 CS 106, Winter 2009 Class 4, Section 4 Slides by: Dr. Cynthia A. Brown, cbrown@cs.pdx.educbrown@cs.pdx.edu Instructor section 4: Dr. Herbert G. Mayer,

8

Your Assignment

• For the parking meter, list the objects and their events, and create variables for the internal state.

• Choose 4 non-trivial events, and create flowcharts for them.

• Due next Thursday, Oct. 16.

Page 9: 1 CS 106, Winter 2009 Class 4, Section 4 Slides by: Dr. Cynthia A. Brown, cbrown@cs.pdx.educbrown@cs.pdx.edu Instructor section 4: Dr. Herbert G. Mayer,

9

The Next Step

• First we gather requirements and organize them in use cases, with tests. This is the look and see phase.

• Then we design a process that will do what the requirements specify. This is the imagine step.

• Finally we implement our design in a program, machine, manual, etc. This is the show step.

• We can then test it to see if we have accurately implemented the requirements.

Page 10: 1 CS 106, Winter 2009 Class 4, Section 4 Slides by: Dr. Cynthia A. Brown, cbrown@cs.pdx.educbrown@cs.pdx.edu Instructor section 4: Dr. Herbert G. Mayer,

10

Specification -> Implementation

• We will learn how to implement a process on a computer, using Visual Basic

• The great thing about this is that we can play with it and test it to make sure it meets our specifications and passes all our tests

• Implementing a process for the computer also forces us to be extremely clear and thorough

Page 11: 1 CS 106, Winter 2009 Class 4, Section 4 Slides by: Dr. Cynthia A. Brown, cbrown@cs.pdx.educbrown@cs.pdx.edu Instructor section 4: Dr. Herbert G. Mayer,

11

A Little About Computers

• A computer consists of hardware: the physical machine.

• The hardware is not useful until we install software: the programs that make the computer do what we want.

Page 12: 1 CS 106, Winter 2009 Class 4, Section 4 Slides by: Dr. Cynthia A. Brown, cbrown@cs.pdx.educbrown@cs.pdx.edu Instructor section 4: Dr. Herbert G. Mayer,

12

CPU (where processing takes place) can:· compare 2 numbers· add/subtract/mult./divide 2 numbers· copy/load number from memory to CPU· store a number from CPU to memory· …

Central Processing Unit (CPU)

MemoryMemory (simply):Holds numbers/text/music/pictures/video,all in digital form.

Input/Output/Storage devices:Hold numbers/text/music/pictures/videoDisplay numbers/text/music/pictures/videoAllow numbers/text/music/pictures/video to be input

Data must move fromexternal storage (e.g., disks) into memory.

The CPU can’t see the datauntil it is inside the CPU.

A Simplified View of Hardware

Page 13: 1 CS 106, Winter 2009 Class 4, Section 4 Slides by: Dr. Cynthia A. Brown, cbrown@cs.pdx.educbrown@cs.pdx.edu Instructor section 4: Dr. Herbert G. Mayer,

13

Software: Operating System

• The most basic software on your computer is the operating system

• Common operating systems are Windows (various flavors), Linux (again available in many versions), and Mac OS (ditto).

• Windows and Mac OS are proprietary.• Linux is open source, and some versions are

free.

Page 14: 1 CS 106, Winter 2009 Class 4, Section 4 Slides by: Dr. Cynthia A. Brown, cbrown@cs.pdx.educbrown@cs.pdx.edu Instructor section 4: Dr. Herbert G. Mayer,

14

Operating System

• The operating system runs your computer and orchestrates the rest of the software

• It makes sure, for example, that the information that a key has been pressed gets sent to the right piece of software

• It makes sure that information gets sent to and retrieved from external devices as needed

• It keeps all the windows organized• It controls access to your files

Page 15: 1 CS 106, Winter 2009 Class 4, Section 4 Slides by: Dr. Cynthia A. Brown, cbrown@cs.pdx.educbrown@cs.pdx.edu Instructor section 4: Dr. Herbert G. Mayer,

15

Application Programs

• An application is a program you use to complete some task

• Examples include web browsers, word processors, games

• Using an application makes you a software user

Page 16: 1 CS 106, Winter 2009 Class 4, Section 4 Slides by: Dr. Cynthia A. Brown, cbrown@cs.pdx.educbrown@cs.pdx.edu Instructor section 4: Dr. Herbert G. Mayer,

16

Software Developer

• All the programs that run on your computer, including the operating system and the application programs, were written by someone (often by a big team of people) called software developers

• They were written using a programming language such as Visual Basic (other examples include Java, Perl, C++)

Page 17: 1 CS 106, Winter 2009 Class 4, Section 4 Slides by: Dr. Cynthia A. Brown, cbrown@cs.pdx.educbrown@cs.pdx.edu Instructor section 4: Dr. Herbert G. Mayer,

17

Computer Programs

• Programs contain instructions for the computer that tell it how to perform some process

• Actual computer instructions at the hardware level are digital like everything else, and stored in memory just like data. In fact the ability to store a program distinguishes a computer from other sophisticated machines

Page 18: 1 CS 106, Winter 2009 Class 4, Section 4 Slides by: Dr. Cynthia A. Brown, cbrown@cs.pdx.educbrown@cs.pdx.edu Instructor section 4: Dr. Herbert G. Mayer,

18

Writing a Program

• Programmers usually write in “high level” languages

• You write using an editor and other tools, possibly a programming environment. Just as with a word processor, which helps you write documents, the programming environment helps you write programs

Page 19: 1 CS 106, Winter 2009 Class 4, Section 4 Slides by: Dr. Cynthia A. Brown, cbrown@cs.pdx.educbrown@cs.pdx.edu Instructor section 4: Dr. Herbert G. Mayer,

19

A Program is a Special Kind of Document

• A program is a document (or set of documents) that contains instructions for the computer

• Running a program makes the computer do something

• There are two ways to run a program: interpreted and compiled

Page 20: 1 CS 106, Winter 2009 Class 4, Section 4 Slides by: Dr. Cynthia A. Brown, cbrown@cs.pdx.educbrown@cs.pdx.edu Instructor section 4: Dr. Herbert G. Mayer,

20

Compiled Programs

• A compiler translates a program into a form that the operating system can run on a computer.

• Once a program is compiled, it is independent of the source code and the development environment

• On Windows, .exe files are compiled programs

Page 21: 1 CS 106, Winter 2009 Class 4, Section 4 Slides by: Dr. Cynthia A. Brown, cbrown@cs.pdx.educbrown@cs.pdx.edu Instructor section 4: Dr. Herbert G. Mayer,

21

Interpreted Programs

• When an application program is interpreted, an interpreter (which is also a program) reads the application program line by line and interacts with the operating system to run the program

• The interpreter uses the source code• In the development environment, using the

interpreter lets us look at what the program is doing internally while it is running

Page 22: 1 CS 106, Winter 2009 Class 4, Section 4 Slides by: Dr. Cynthia A. Brown, cbrown@cs.pdx.educbrown@cs.pdx.edu Instructor section 4: Dr. Herbert G. Mayer,

22

VB Can Do Both

• Interpretation is great while we are developing the program since it lets us examine what is going on

• After the program is finished, we can compile it to get something that runs faster and is independent of the source code and the development environment

Page 23: 1 CS 106, Winter 2009 Class 4, Section 4 Slides by: Dr. Cynthia A. Brown, cbrown@cs.pdx.educbrown@cs.pdx.edu Instructor section 4: Dr. Herbert G. Mayer,

23

VB Projects

• A VB project is more than just a single file of code

• VB has many great features that assist us in easily creating nice user interfaces that interact well with the Windows environment

• It automatically creates components that the operating system will need to run the program properly

Page 24: 1 CS 106, Winter 2009 Class 4, Section 4 Slides by: Dr. Cynthia A. Brown, cbrown@cs.pdx.educbrown@cs.pdx.edu Instructor section 4: Dr. Herbert G. Mayer,

24

Controls

• Controls are what VB calls the objects that can appear in the user interface

• Chapter 2.2 has a nice tutorial on the most common controls– Text box– Button– Label– List box

• We’ll walk through an intro to these after the break

Page 25: 1 CS 106, Winter 2009 Class 4, Section 4 Slides by: Dr. Cynthia A. Brown, cbrown@cs.pdx.educbrown@cs.pdx.edu Instructor section 4: Dr. Herbert G. Mayer,

25

BREAK

10 min

Page 26: 1 CS 106, Winter 2009 Class 4, Section 4 Slides by: Dr. Cynthia A. Brown, cbrown@cs.pdx.educbrown@cs.pdx.edu Instructor section 4: Dr. Herbert G. Mayer,

26

DEMONSTRATION

Getting started with Visual Basic