programming process six programming steps the programmer ’ s job can be broken down into six...

39
Programming Process The programmer’s job can be broken down into six programming steps six programming steps: 1. Understand the problem 2. Plan the logic 3. Code the program 4. Translate the program into machine language 5. Test the program 6. Put the program into production

Upload: preston-wheeler

Post on 16-Dec-2015

217 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Programming Process six programming steps The programmer ’ s job can be broken down into six programming steps: 1.Understand the problem 2.Plan the logic

Programming Process

The programmer’s job can be broken down into six programming stepssix programming steps:

1. Understand the problem

2. Plan the logic

3. Code the program

4. Translate the program into machine language

5. Test the program

6. Put the program into production

Page 2: Programming Process six programming steps The programmer ’ s job can be broken down into six programming steps: 1.Understand the problem 2.Plan the logic

Understand the Problem

Programmers must first understand what it is the user wants

To understand the problem, you must analyze it

Really understanding the problem may be one of the most difficult aspects of programmingo The description of what the user needs may be vagueo The user may not even really know what he or she wantso Users who think they know what they want frequently

change their minds after seeing sample output

Page 3: Programming Process six programming steps The programmer ’ s job can be broken down into six programming steps: 1.Understand the problem 2.Plan the logic

Understand the Problem

Analysis & Really Understanding

Exampleo To invite some people, I need the list of people who work

during five more years.o Definite problem or ambiguous problem ?

Page 4: Programming Process six programming steps The programmer ’ s job can be broken down into six programming steps: 1.Understand the problem 2.Plan the logic

Understand the Problem

Analysis & Really Understanding

Exampleo To invite some people, I need the list of people who work

during five more years.o Definite problem or ambiguous problem ?

Ambiguous problemo Full-time or part-time worker or both of them ?o Regular employee or contract employee ?o Which type of list ?

A good programmer is often part counselor, part detective

Page 5: Programming Process six programming steps The programmer ’ s job can be broken down into six programming steps: 1.Understand the problem 2.Plan the logic

Programming Process

The programmer’s job can be broken down into six programming stepssix programming steps:

1. Understand the problem

2. Plan the logic

3. Code the program

4. Translate the program into machine language

5. Test the program

6. Put the program into production

Page 6: Programming Process six programming steps The programmer ’ s job can be broken down into six programming steps: 1.Understand the problem 2.Plan the logic

Plan the Logic

Programmer plans the steps to the program, deciding what steps to include and how to order them

Exampleo Planning touro Planning party

The two most common tools o flowchartsflowcharts : pictorial representationo Pseudocode Pseudocode : English-like representation

Page 7: Programming Process six programming steps The programmer ’ s job can be broken down into six programming steps: 1.Understand the problem 2.Plan the logic

Plan the Logic

FlowchartsFlowcharts

A pictorial representation of the logical steps it takes to solve a problem.

o Uses Standardized Symbols

o Utilize Formula Notation

o Typically Read from Top to Bottom or from

o Left to Right on a Page

start

getInputNumber

calculatedAnswer =InputNumber * 2

printcalculatedAnswer

stop

Page 8: Programming Process six programming steps The programmer ’ s job can be broken down into six programming steps: 1.Understand the problem 2.Plan the logic

Plan the Logic

Basic flowchart symbolsBasic flowchart symbols

Process(Rectangle)

Start/Stop(Terminator)

Input/Output(Parallelogram)

Decision(Diamond)

Connector(Circle)

Flowlines(Arrows)

Predefined Process(Rectangle)

Page 9: Programming Process six programming steps The programmer ’ s job can be broken down into six programming steps: 1.Understand the problem 2.Plan the logic

Sequence, Selection, Repetition

sequence selection repetition

entrance

exit

entrance

exit

entrance

exit

Page 10: Programming Process six programming steps The programmer ’ s job can be broken down into six programming steps: 1.Understand the problem 2.Plan the logic

Plan the Logic

Pseudocode

An English-like representation of the logical steps it takes to solve a problemo pseudo – a prefix that means false

o Short English-Like Statements

o Not Standardized

o Proper use of indentation

Example start get InputNumber compute calculatedAnswer as InputNumber times 2 print calculatedAnswerstop

Page 11: Programming Process six programming steps The programmer ’ s job can be broken down into six programming steps: 1.Understand the problem 2.Plan the logic

Programming Process

The programmer’s job can be broken down into six programming stepssix programming steps:

1. Understand the problem

2. Plan the logic

3. Code the program

4. Translate the program into machine language

5. Test the program

6. Put the program into production

Page 12: Programming Process six programming steps The programmer ’ s job can be broken down into six programming steps: 1.Understand the problem 2.Plan the logic

Code the program

Writing the program in one of more than 400 programming languages

o Pascal, Fortran, C, C++, Java…..

Concentrate on the syntax of the language

o Exact instruction, symbol, …. ?

Some very experienced programmers o successfully combining the logic planning and the actual

instruction writing, or coding of the program, in one step

o Writing a post card

o Writing a cinema scenario

Page 13: Programming Process six programming steps The programmer ’ s job can be broken down into six programming steps: 1.Understand the problem 2.Plan the logic

Code the program

Which is harder: Planning the Logic or Coding the Program?

Exampleo Planning the logic :Planning mystery novel

o Coding the program : Writing English or Spanish based on the original scenario.

o Who gets more annual salary ?

Page 14: Programming Process six programming steps The programmer ’ s job can be broken down into six programming steps: 1.Understand the problem 2.Plan the logic

Programming Process

The programmer’s job can be broken down into six programming stepssix programming steps:

1. Understand the problem

2. Plan the logic

3. Code the program

4. Translate the program into machine language

5. Test the program

6. Put the program into production

Page 15: Programming Process six programming steps The programmer ’ s job can be broken down into six programming steps: 1.Understand the problem 2.Plan the logic

Translate the Program

Objective

o Each computer knows only one language, Machine Language.

o High-level Languages must be translated into Machine Language

Need to compiler or interpretero Compiler catches every syntax error.o When writing a program, a programmer might need to

recompile the code several timeso An executable program is created only when the code is

free of syntax errors

Page 16: Programming Process six programming steps The programmer ’ s job can be broken down into six programming steps: 1.Understand the problem 2.Plan the logic

Translate the Program

Creating an executable program

Page 17: Programming Process six programming steps The programmer ’ s job can be broken down into six programming steps: 1.Understand the problem 2.Plan the logic

Programming Process

The programmer’s job can be broken down into six programming stepssix programming steps:

1. Understand the problem

2. Plan the logic

3. Code the program

4. Translate the program into machine language

5. Test the program

6. Put the program into production

Page 18: Programming Process six programming steps The programmer ’ s job can be broken down into six programming steps: 1.Understand the problem 2.Plan the logic

Test the Program

Why does it need to be tested ?

o Syntax Errors : by compile

o Logical Errors : by test

Testo Executing the program with some sample data o Seeing whether or not the results are logically correct.o being tested with many sets of data carefully

Examplestart get InputNumber compute calculatedAnswer as InputNumber times 20 print calculatedAnswerstop

Logically incorrect

Page 19: Programming Process six programming steps The programmer ’ s job can be broken down into six programming steps: 1.Understand the problem 2.Plan the logic

Programming Process

The programmer’s job can be broken down into six programming stepssix programming steps:

1. Understand the problem

2. Plan the logic

3. Code the program

4. Translate the program into machine language

5. Test the program

6. Put the program into production

Page 20: Programming Process six programming steps The programmer ’ s job can be broken down into six programming steps: 1.Understand the problem 2.Plan the logic

Put the program into the production

Once the program is tested adequately, it is ready for the organization to use.

Putting the program into production might mean simply running the program once if it was written to satisfy a user’s request for a special list.

Page 21: Programming Process six programming steps The programmer ’ s job can be broken down into six programming steps: 1.Understand the problem 2.Plan the logic

Flowchart & Pseudocode

Flowcharts (pictorial representations) and pseudocode (English-like representations) are used by programmers to plan the logical steps for solving a programming problem

Some professional programmers prefer writing pseudocode to drawing flowcharts, because using pseudocode is more similar to writing final statements in programming language

Page 22: Programming Process six programming steps The programmer ’ s job can be broken down into six programming steps: 1.Understand the problem 2.Plan the logic

Flowchart & Pseudocode

Almost every program involves the steps of input, processing, and output, necessitating some graphical way to separate them

Arithmetic operation statements are examples of processing in a flowchart, where you use a rectangle as the processing symbol containing a processing statement

Page 23: Programming Process six programming steps The programmer ’ s job can be broken down into six programming steps: 1.Understand the problem 2.Plan the logic

Flowchart & Pseudocode

To represent an output statement, you use the parallelogram, which is also the same symbol used for input statements

Page 24: Programming Process six programming steps The programmer ’ s job can be broken down into six programming steps: 1.Understand the problem 2.Plan the logic

Flowchart & Pseudocode

In flowcharts:o Arrows, or flowlines, connect and show the appropriate sequen

ce of stepso A terminal symbol, or start/stop symbol, should be included at

each endo Often, “start” or “begin” is used as the first terminal symbol an

d “end” or “stop” is used in the othero The standard terminal symbol is shaped like a racetrack; often

called a lozenge, because it resembles the shape of a medicated candy lozenge you might use to soothe a sore throat

Flowlines(Arrows)

Start/Stop(Terminator)

Page 25: Programming Process six programming steps The programmer ’ s job can be broken down into six programming steps: 1.Understand the problem 2.Plan the logic

Flowchart & Pseudocode

Complete flowchart for the program that doubles a number, and the pseudocode for the same problem

start

getInputNumber

calculatedAnswer =InputNumber * 2

printcalculatedAnswer

stop

start get InputNumber compute calculatedAnswer

as InputNumber times 2 print calculatedAnswerstop

Page 26: Programming Process six programming steps The programmer ’ s job can be broken down into six programming steps: 1.Understand the problem 2.Plan the logic

Naming Variables

Variableso memory locations, whose contents can vary or differ over time.

o reasonable and descriptive variable names

Exampleo InputNumber

o caluculatedAnswer

start get InputNumber compute calculatedAnswer as InputNumber times 2 print calculatedAnswerstop

Page 27: Programming Process six programming steps The programmer ’ s job can be broken down into six programming steps: 1.Understand the problem 2.Plan the logic

Naming Variables

Naming Rules o Every programming language has its own set of rules for

naming variables.

o most languages allow both letters and digits : a,b,c, 1,2,3o some languages allow hyphens and/or underscores : - _o some allow dollar signs or other special characters : $, #, @o some allow for foreign characters : Japanese, Spanisho different languages put different limits on lengthso some languages are case sensitive, others are not : name,

Nameo in general, variable names may not begin with a digit :

name1

Page 28: Programming Process six programming steps The programmer ’ s job can be broken down into six programming steps: 1.Understand the problem 2.Plan the logic

Naming Variables

Textbook Conventions – two rules:

(1) Variable names must be one wordo can contain letters, digits, hyphens, underscores, with the exception

of spaces.

(2) Variable names should have some appropriate meaningo Undesirable : G, u84, fred, mike, richard, pink,

o Desirable : rate, name, age, count, score, index, lastName

employeeLastName, 5employeeLastName, employeeLast, empLast,emlstnam, lastNameofTheEmployeeInQuestion, last name (x), employeelastname,

Page 29: Programming Process six programming steps The programmer ’ s job can be broken down into six programming steps: 1.Understand the problem 2.Plan the logic

Naming Variables

Assignment values to variables

o Whatever operation is performed to the right of the equal sign results in a value that is placed in the memory location to the left of the equal sign.

compute calculatedAnswer

as InputNumber times 2

is the same as

calculatedAnswer = InputNumber * 2

Page 30: Programming Process six programming steps The programmer ’ s job can be broken down into six programming steps: 1.Understand the problem 2.Plan the logic

Naming Variables

Constanto A memory location, similar to a variable, except its value never chang

es during a program.

o taxRate = .0825

o Pi = 3.141592

Variableso memory locations, whose contents can vary or differ over time.

Page 31: Programming Process six programming steps The programmer ’ s job can be broken down into six programming steps: 1.Understand the problem 2.Plan the logic

Naming Variables

Data TypesData Types – two basic types

Charactero Character : ‘a’ ‘b’ ‘c’ ‘d’ ‘e’

o Character string : “Richard” “Michale”

Numerico Integer : …, -3, -2, -1, 0, 1, 2, 3, ….

o Floating-Point : …, -2.0, -1.5, -1, -0.5, 0, 0.5, 1.0, ….

Page 32: Programming Process six programming steps The programmer ’ s job can be broken down into six programming steps: 1.Understand the problem 2.Plan the logic

Ending a Program

Infinite loopstart

getInputNumber

calculatedAnswer=InputNumber*2

PrintcalculatedAnswer

start get InputNumber compute calculatedAnswer as InputNumber times 2 print calculatedAnswer

get InputNumber compute calculatedAnswer as InputNumber times 2 print calculatedAnswer

get InputNumber compute calculatedAnswer as InputNumber times 2 print calculatedAnswer ………stop

Page 33: Programming Process six programming steps The programmer ’ s job can be broken down into six programming steps: 1.Understand the problem 2.Plan the logic

Ending a Program

An infinite loop is a repeating flow of logic with no end

To end the program, o set a predetermined value for inputNumber that means “Stop the pro

gram!”

o The program can then test any incoming value for inputNumber and, if it is a 0, stop the program

Testing a value is also called making a decision

o Represented in flowchart by diamond shape called a decision symbol

Page 34: Programming Process six programming steps The programmer ’ s job can be broken down into six programming steps: 1.Understand the problem 2.Plan the logic

Ending a Program

Decision symbol

start

getInputNumber

calculatedAnswer=InputNumber*2

PrintcalculatedAnswer

inputNumber= 0 ?

stop

start

getInputNumber

calculatedAnswer=InputNumber*2

PrintcalculatedAnswer

No

YesinputNumber

= 0 ?

Page 35: Programming Process six programming steps The programmer ’ s job can be broken down into six programming steps: 1.Understand the problem 2.Plan the logic

Ending a Program

Dummy value

o A pre-selected value that stops the execution of a program is often called a dummy value since it does not represent real data, but just a signal to stop

o Sometimes, such a value is called a sentinel value because it represents an entry or exit point, like a sentinel who guards a fortress

Page 36: Programming Process six programming steps The programmer ’ s job can be broken down into six programming steps: 1.Understand the problem 2.Plan the logic

Using a Connector

If a flowchart has six processing steps and a page provides room for only three, you might represent the logic as shown below:o On-page connector symbolo Off-page connector symbol

Page 37: Programming Process six programming steps The programmer ’ s job can be broken down into six programming steps: 1.Understand the problem 2.Plan the logic

Evolution of Programming Technique

Currently, there are two major techniquestwo major techniques used to develop programs and their procedures

o Procedural programming focuses on the procedures that programmers create

o Object-oriented programming, focuses on objects, or “things”, and describes their features, or attributes, and their behaviors

Page 38: Programming Process six programming steps The programmer ’ s job can be broken down into six programming steps: 1.Understand the problem 2.Plan the logic

Summary

A programmer’s job involves six steps:

o Understanding the problemo Planning the logic o Coding the problemo Translating the program into machine language o Testing the programo Putting the program into production

When programmers plan the logic for a solution to a programming problem, they often use flowcharts or pseudocode

Page 39: Programming Process six programming steps The programmer ’ s job can be broken down into six programming steps: 1.Understand the problem 2.Plan the logic

Summary

Testing a value involves making a decision

Most programming languages use the equal sign to assign values to variables

Procedural and object-oriented programmers approach program problems differently