Programming Process n The programmers job can be

Programming Process n The programmer’s job can be broken down into six programming steps: 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

Understand the Problem n Programmers must first understand what it is the user wants n To understand the problem, you must analyze it n Really understanding the problem may be one of the most difficult aspects of programming o The description of what the user needs may be vague o The user may not even really know what he or she wants o Users who think they know what they want frequently change their minds after seeing sample output

Understand the Problem n Analysis & Really Understanding n Example o To invite some people, I need the list of people who work during five more years. o Definite problem or ambiguous problem ?

Understand the Problem n Analysis & Really Understanding n Example o To invite some people, I need the list of people who work during five more years. o Definite problem or ambiguous problem ? n Ambiguous problem o Full-time or part-time worker or both of them ? o Regular employee or contract employee ? o Which type of list ? n A good programmer is often part counselor, part detective

Programming Process n The programmer’s job can be broken down into six programming steps: 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

Plan the Logic n Programmer plans the steps to the program, deciding what steps to include and how to order them n Example o Planning tour o Planning party n The two most common tools o flowcharts : pictorial representation o Pseudocode : English-like representation

Plan the Logic n Flowcharts n 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

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

Sequence, Selection, Repetition sequence selection entrance repetition entrance exit

Plan the Logic n Pseudocode n An English-like representation of the logical steps it takes to solve a problem o pseudo – a prefix that means false o Short English-Like Statements o Not Standardized o Proper use of indentation n Example start get Input. Number compute calculated. Answer as Input. Number times 2 print calculated. Answer stop

Programming Process n The programmer’s job can be broken down into six programming steps: 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

Code the program n Writing the program in one of more than 400 programming languages o Pascal, Fortran, C, C++, Java…. . n Concentrate on the syntax of the language o Exact instruction, symbol, …. ? n 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

Code the program n Which is harder: Planning the Logic or Coding the Program? n Example o 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 ?

Programming Process n The programmer’s job can be broken down into programming steps: 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 six

Translate the Program n Objective o Each computer knows only one language, Machine Language. o High-level Languages must be translated into Machine Language n Need to compiler or interpreter o Compiler catches every syntax error. o When writing a program, a programmer might need to recompile the code several times o An executable program is created only when the code is free of syntax errors

Translate the Program n Creating an executable program

Programming Process n The programmer’s job can be broken down into six programming steps: 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

Test the Program n Why does it need to be tested ? o Syntax Errors : by compile o Logical Errors : by test n Test o 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 n Example Logically incorrect start get Input. Number compute calculated. Answer as Input. Number times 20 print calculated. Answer stop

Programming Process n The programmer’s job can be broken down into six programming steps: 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

Put the program into the production n Once the program is tested adequately, it is ready for the organization to use. n 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.

Flowchart & Pseudocode n Flowcharts (pictorial representations) and pseudocode (English-like representations) are used by programmers to plan the logical steps for solving a programming problem n Some professional programmers prefer writing pseudocode to drawing flowcharts, because using pseudocode is more similar to writing final statements in programming language

Flowchart & Pseudocode n Almost every program involves the steps of input, processing, and output, necessitating some graphical way to separate them n Arithmetic operation statements are examples of processing in a flowchart, where you use a rectangle as the processing symbol containing a processing statement

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

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

Flowchart & Pseudocode n Complete flowchart for the program that doubles a number, and the pseudocode for the same problem start get Input. Number compute calculated. Answer as Input. Number times 2 print calculated. Answer stop

Naming Variables n Variables o memory locations, whose contents can vary or differ over time. o reasonable and descriptive variable names n Example o Input. Number o caluculated. Answer start get Input. Number compute calculated. Answer as Input. Number times 2 print calculated. Answer stop

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

Naming Variables n Textbook Conventions – two rules: (1) Variable names must be one word o can contain letters, digits, hyphens, underscores, with the exception of spaces. (2) Variable names should have some appropriate meaning o Undesirable : G, u 84, fred, mike, richard, pink, o Desirable : rate, name, age, count, score, index, last. Name employee. Last. Name, 5 employee. Last. Name, employee. Last, emp. Last, emlstnam, last. Nameof. The. Employee. In. Question, last name (x), employeelastname,

Naming Variables n 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 calculated. Answer as Input. Number times 2 is the same as calculated. Answer = Input. Number * 2

Naming Variables n Constant o A memory location, similar to a variable, except its value never changes during a program. o tax. Rate =. 0825 o Pi = 3. 141592 n Variables o memory locations, whose contents can vary or differ over time.

Naming Variables n Data Types – two basic types n Character o Character : ‘a’ ‘b’ ‘c’ ‘d’ ‘e’ o Character string : “Richard” “Michale” n Numeric o Integer : …, -3, -2, -1, 0, 1, 2, 3, …. o Floating-Point : …, -2. 0, -1. 5, -1, -0. 5, 0, 0. 5, 1. 0, ….

Ending a Program n Infinite loop start get Input. Number calculated. Answer=In put. Number*2 Print calculated. Answer start get Input. Number compute calculated. Answer as Input. Number times 2 print calculated. Answer ……… stop

Ending a Program n An infinite loop is a repeating flow of logic with no end n To end the program, o set a predetermined value for input. Number that means “Stop the program!” o The program can then test any incoming value for input. Number and, if it is a 0, stop the program n Testing a value is also called making a decision o Represented in flowchart by diamond shape called a decision symbol

Ending a Program n Decision symbol start get Input. Number calculated. Answer=In put. Number*2 Print calculated. Answer input. Number =0? Yes No calculated. Answer=In put. Number*2 Print calculated. Answer stop

Ending a Program n 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

Using a Connector n 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 symbol o Off-page connector symbol

Evolution of Programming Technique n Currently, there are two 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

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

Summary n Testing a value involves making a decision n Most programming languages use the equal sign to assign values to variables n Procedural and object-oriented programmers approach program problems differently
- Slides: 39