• No results found

Propedéutico de Programación

N/A
N/A
Protected

Academic year: 2021

Share "Propedéutico de Programación"

Copied!
30
0
0

Loading.... (view fulltext now)

Full text

(1)

Propedéutico de

Programación

Coordinación de Ciencias

Computacionales

9/13

Material preparado por:

Dra. Pilar Gómez Gil

(2)

Chapter 4

(3)

ADT Sorted List

Remember the difference between an unsorted list and a

sorted list?

Remember the definition of a key?

If the list is a sorted list

of names, what would be the key?

of bank balances, what would be the key?

of grades, what would be the key?

(4)

ADT Unsorted List Operations

Transformers

MakeEmpty

InsertItem

DeleteItem

Observers

IsFull

GetLength

RetrieveItem

Iterators

ResetList

GetNextItem

change state

observe state

process all

(5)

ADT Sorted List

Which member function specifications and

implementations must change to ensure

that any instance of the Sorted List ADT

remains sorted at all times?

InsertItem

DeleteItem

(6)

La inserción tendrá que ser de tal manera que

(7)

Linked Implementation

What about passing spot where item

would be if there?

(8)

Linked Implementation

Is Inserting as easy? Let's see

Set location to listData

Set moreToSearch to (location != NULL)

while moreToSearch

switch (item.ComparedTo(location->info))

case GREATER

:

Set location to location->next

Set moreToSearch to (location != NULL)

case LESS : Set moreToSearch to false

See

the

problem

(9)

Linked Implementation

(10)

Inserting ‘S’ into a Sorted List

‘C’ ‘L’ ‘X’

Private data:

length

3

listData

currentPos ?

predLoc location

moreToSearch

(11)

Finding proper position for ‘S’

‘C’ ‘L’ ‘X’

Private data:

length

3

listData

currentPos ?

predLoc location

NULL

moreToSearch true

(12)

Finding proper position for

S

‘C’ ‘L’ ‘X’

Private data:

length

3

listData

currentPos ?

predLoc location

moreToSearch true

(13)

Finding Proper Position for

S

‘C’ ‘L’ ‘X’

Private data:

length

3

listData

currentPos ?

predLoc location

moreToSearch

false

(14)

Inserting

S

into Proper Position

‘C’ ‘L’ ‘X’

Private data:

length

4

listData

currentPos

predLoc location

moreToSearch false

‘S’

(15)

Ver

sorted.h

(16)

Linked Implementation

Does DeleteItem have to be changed?

(17)

Object-Oriented Design Methodology

Object-oriented design decomposes a problem into classes

Four stages to the decomposition process

Brainstorming

Filtering

Scenarios

(18)

Object-Oriented Design Methodology

Brainstorming

A group problem-solving technique that involves the

spontaneous contribution of ideas from all members of the

group

All ideas are potential good ideas

Think fast and furiously first, and ponder later

A little humor can be a powerful force

(19)

Object-Oriented Design Methodology

Filtering

Determine which are the core classes in the problem

solution

There may be two classes in the list that have many

common attributes and behaviors

There may be classes that really don’t belong in the

(20)

Object-Oriented Design Methodology

Scenarios

Sequences of steps that describe an interaction between a

client and an application or program

Simulate class interactions

Ask “What if?” questions

Assign responsibilities to each class

There are two types of responsibilities

What a class must know about itself (knowledge)

What a class must be able to do (behavior)

Use case

(21)

Object-Oriented Design Methodology

Role

playing

(22)

Object-Oriented Design Methodology

Responsibility Algorithms

The algorithms must be written for the

responsibilities

Knowledge responsibilities usually just return

the contents of one of an object’s variables

Action responsibilities are a little more

complicated, often involving calculations

Responsibilities algorithms are often

decomposed using top-down design

(23)

Relationships Between Classes

Containment

“part-of”

An address class may be part of the definition of a student

class

Inheritance

Classes can inherit data and behavior from other classes

“is-a”

(24)

Computer Example

Let’s work through this problem-solving process by

creating an address list

Brainstorming and filtering

Circling the nouns and underlining the verbs is a good way

(25)

Computer Example

First pass at a list of classes

list

name

telephone number

email address

list

order

names

list

scraps

paper

cards

Filtered List

(26)

CRC Cards

(27)

CRC Cards

(28)

CRC Cards

(29)

Responsibility Algorithms

Person Class

Initialize

name.initialize()

Write "Enter phone number; press return."

Get telephone number

Write "Enter email address; press return."

Get email address

Print

name.print()

Write "Telephone number: " + telephoneNumber

Write "Email address: " + emailAddress

Tells name to initialize itself

(30)

Responsibility Algorithms

Name Class

Initialize

"Enter the first name; press return."

Read firstName

"Enter the last name; press return."

Read lastName

Print

Print "First name: " + firstName

Print "Last name: " + lastName

r sorted.h r sorted.cpp

References

Related documents