Presentation is loading. Please wait.

Presentation is loading. Please wait.

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.

Similar presentations


Presentation on theme: "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."— Presentation transcript:

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 3.Code the program 4.Translate the program into machine language 5.Test the program 6.Put the program into production

2 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 programming oThe description of what the user needs may be vague oThe user may not even really know what he or she wants oUsers who think they know what they want frequently change their minds after seeing sample output

3 Understand the Problem Analysis & Really Understanding Example oTo invite some people, I need the list of people who work during five more years. oDefinite problem or ambiguous problem ?

4 Understand the Problem Analysis & Really Understanding Example oTo invite some people, I need the list of people who work during five more years. oDefinite problem or ambiguous problem ? Ambiguous problem oFull-time or part-time worker or both of them ? oRegular employee or contract employee ? oWhich type of list ? A good programmer is often part counselor, part detective

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 3.Code the program 4.Translate the program into machine language 5.Test the program 6.Put the program into production

6 Plan the Logic Programmer plans the steps to the program, deciding what steps to include and how to order them Example oPlanning tour oPlanning party The two most common tools oflowcharts oflowcharts : pictorial representation oPseudocode oPseudocode : English-like representation

7 Plan the Logic Flowcharts Flowcharts A pictorial representation of the logical steps it takes to solve a problem. oUses Standardized Symbols oUtilize Formula Notation oTypically Read from Top to Bottom or from oLeft to Right on a Page

8 Plan the Logic Basic flowchart symbols Basic flowchart symbols Process (Rectangle) Start/Stop (Terminator) Input/Output (Parallelogram) Decision (Diamond) Connector (Circle) Flowlines (Arrows) Predefined Process (Rectangle)

9 Sequence, Selection, Repetition sequenceselectionrepetition entrance exit entrance exit entrance exit

10 Plan the Logic Pseudocode An English-like representation of the logical steps it takes to solve a problem opseudo – a prefix that means false oShort English-Like Statements oNot Standardized oProper use of indentation Example start get InputNumber compute calculatedAnswer as InputNumber times 2 print calculatedAnswer stop

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 3.Code the program 4.Translate the program into machine language 5.Test the program 6.Put the program into production

12 Code the program Writing the program in one of more than 400 programming languages oPascal, Fortran, C, C++, Java ….. Concentrate on the syntax of the language oExact instruction, symbol, …. ? Some very experienced programmers osuccessfully combining the logic planning and the actual instruction writing, or coding of the program, in one step oWriting a post card oWriting a cinema scenario

13 Code the program Which is harder: Planning the Logic or Coding the Program? Example oPlanning the logic :Planning mystery novel oCoding the program : Writing English or Spanish based on the original scenario. oWho gets more annual salary ?

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 3.Code the program 4.Translate the program into machine language 5.Test the program 6.Put the program into production

15 Translate the Program Objective oEach computer knows only one language, Machine Language. oHigh-level Languages must be translated into Machine Language Need to compiler or interpreter oCompiler catches every syntax error. oWhen writing a program, a programmer might need to recompile the code several times oAn executable program is created only when the code is free of syntax errors

16 Translate the Program Creating an executable program

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 3.Code the program 4.Translate the program into machine language 5.Test the program 6.Put the program into production

18 Test the Program Why does it need to be tested ? oSyntax Errors : by compile oLogical Errors : by test Test oExecuting the program with some sample data oSeeing whether or not the results are logically correct. obeing tested with many sets of data carefully Example start get InputNumber compute calculatedAnswer as InputNumber times 20 print calculatedAnswer stop Logically incorrect

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 3.Code the program 4.Translate the program into machine language 5.Test the program 6.Put the program into production

20 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.

21 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

22 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

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

24 Flowchart & Pseudocode In flowcharts: oArrows, or flowlines, connect and show the appropriate sequence of steps oA terminal symbol, or start/stop symbol, should be included at each end oOften, “ start ” or “ begin ” is used as the first terminal symbol and “ end ” or “ stop ” is used in the other oThe 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)

25 Flowchart & Pseudocode Complete flowchart for the program that doubles a number, and the pseudocode for the same problem start get InputNumber compute calculatedAnswer as InputNumber times 2 print calculatedAnswer stop

26 Naming Variables Variables omemory locations, whose contents can vary or differ over time. oreasonable and descriptive variable names Example oInputNumber ocaluculatedAnswer start get InputNumber compute calculatedAnswer as InputNumber times 2 print calculatedAnswer stop

27 Naming Variables Naming Rules oEvery programming language has its own set of rules for naming variables. omost languages allow both letters and digits : a,b,c, 1,2,3 osome languages allow hyphens and/or underscores : - _ osome allow dollar signs or other special characters : $, osome allow for foreign characters : Japanese, Spanish odifferent languages put different limits on lengths osome languages are case sensitive, others are not : name, Name oin general, variable names may not begin with a digit : name1

28 Naming Variables Textbook Conventions – two rules: (1)Variable names must be one word ocan contain letters, digits, hyphens, underscores, with the exception of spaces. (2)Variable names should have some appropriate meaning oUndesirable : G, u84, fred, mike, richard, pink, oDesirable : rate, name, age, count, score, index, lastName employeeLastName, 5employeeLastName, employeeLast, empLast, emlstnam, lastNameofTheEmployeeInQuestion, last name (x), employeelastname,

29 Naming Variables Assignment values to variables oWhatever 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

30 Naming Variables Constant oA memory location, similar to a variable, except its value never changes during a program. otaxRate =.0825 oPi = Variables omemory locations, whose contents can vary or differ over time.

31 Naming Variables Data Types Data Types – two basic types Character oCharacter : ‘a’ ‘b’ ‘c’ ‘d’ ‘e’ oCharacter string : “Richard” “Michale” Numeric oInteger : …, -3, -2, -1, 0, 1, 2, 3, …. oFloating-Point : …, -2.0, -1.5, -1, -0.5, 0, 0.5, 1.0, ….

32 Ending a Program Infinite loop start get InputNumber calculatedAnswer=In putNumber*2 Print calculatedAnswer 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

33 Ending a Program An infinite loop is a repeating flow of logic with no end To end the program, oset a predetermined value for inputNumber that means “Stop the program!” oThe 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 oRepresented in flowchart by diamond shape called a decision symbol

34 Ending a Program Decision symbol start get InputNumber calculatedAnswer=In putNumber*2 Print calculatedAnswer inputNumber = 0 ? stop start get InputNumber calculatedAnswer=In putNumber*2 Print calculatedAnswer No Yes inputNumber = 0 ?

35 Ending a Program Dummy value oA 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 oSometimes, such a value is called a sentinel value because it represents an entry or exit point, like a sentinel who guards a fortress

36 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: oOn-page connector symbol oOff-page connector symbol

37 Evolution of Programming Technique two major techniques Currently, there are two major techniques used to develop programs and their procedures oProcedural programming focuses on the procedures that programmers create oObject-oriented programming, focuses on objects, or “ things ”, and describes their features, or attributes, and their behaviors

38 Summary A programmer ’ s job involves six steps: o Understanding the problem o Planning the logic o Coding the problem o Translating the program into machine language o Testing the program o Putting the program into production When programmers plan the logic for a solution to a programming problem, they often use flowcharts or pseudocode

39 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


Download ppt "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."

Similar presentations


Ads by Google