1 / 19

PROGRAMMING: What’s It All About?

Hele-Mai Haav: February 2002. PROGRAMMING: What’s It All About?. Though, thy beginning was small, yet thy end will be very great. JOB 8:7. Software. Hardware. Ingredients: sugar, flour. INPUT. Oven/baker (mixing, pouring, heating etc.). recipe. ALGORITHM is the formal

angelinac
Download Presentation

PROGRAMMING: What’s It All About?

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Hele-Mai Haav: February 2002 PROGRAMMING: What’s It All About? Though, thy beginning was small,yet thy end will be very great.JOB 8:7

  2. Software Hardware Ingredients: sugar, flour INPUT Oven/baker (mixing, pouring, heating etc.) recipe ALGORITHM is the formal written version of recipe Program is precise representations of algorithms written in special computer-readable language like Basic, C, C++, Pascal, Cobol… OUTPUT

  3. Algorithm A formula or set of steps for solving a particular problem. To be an algorithm, a set of rules must be unambiguous and have a clear stopping point. Algorithms can be expressed in any language, from natural languages like English or French to programming language like FORTRAN. We use algorithms every day. For example, a recipe for baking a cake is an algorithm. Most programs, with the exception of some artificial intelligence applications, consist of algorithms. Inventing elegant algorithms -- algorithms that are simple and require the fewest steps possible -- is one of the principal challenges in programming.

  4. Summing problem • Step 1. make a note of the number 0 • Step 2. proceed through the list, adding each employee's salary to the noted number • Step 3. having reached the end of the list, produce the noted number as output

  5. Does this algorithm do the job? • Text of the algorithm is short and fixed in length. • The process it describes and controls depends on the length of the employee list and can be very long.

  6. Does this algorithm do the job? Let us have two companies: with 1 empl. with 1 million empl. They both can use the same algorithm for solving salary summation problem. Only a single noted number is required for both.

  7. What we have? 1. fixed algorithm 2. a variety of possible inputs the precise duration and nature of the process depends on inputs .

  8. Algorithm- precise order of the actions to be performed. The order in which the basic actions are carried out is crucial. The algorithm must contain control instructions to "push" the processor in this or that direction, telling it what to do at each step and when to stop and say "I'm done".

  9. CONTROL STRUCTURES Sequence control - one process occurs immediately after another "do A followed by B" "do A and then B" A B

  10. CONTROL STRUCTURES Selection structure, or if-then-else structure represents conditional program logic "if Q then do A" "if Q then do A otherwise do B" Q is some condition Can be true or false False True Q? A B C

  11. CONTROL STRUCTURES Iteration structure or looping structure describes occurrence of one or more processes one or more times. - Bounded iteration "do A exactly N times" N is a number - Conditional iteration do-while "while Q do A" do-until "repeat A until Q" No >N A Yes True Q? A False True A Q? False

  12. Summing problem Let us assume the following input: 1. list of employees and their salaries 2. total number of the employees in the list, designated by letter N

  13. Summing problem algorithm 1.Make a note of 0 Point to the first salary on the list 2. Do N-1 times the following 2.1. add the salary pointed at to the noted number 2.2. point to the next salary 3.Add the salary pointed at to the noted number 4.Produce the noted number as output

  14. Diagrams for algorithms Flowcharts

  15. Programs are written in some programming languages which allow the use of only special combinations of selected symbols and keywords. "please read the value X from the input" "how about getting me a value of X" • INPUT X • READ X

  16. A typical programming language includes : rules for writing control structures ways of defining various types of data (numeric, textual, etc) formats for the basic instructions

  17. Summing algorithm for summing the numbers from 1 to N might be written in Basic as follows: REM Summing INPUT N SUM = 0 FOR INDEX = 1 TO N SUM = SUM + INDEX NEXT INDEX PRINT "Sum of the first N digits is"; SUM END RUN

  18. SUM = 0 sets variable SUM to value 0 FOR INDEX = 1 TO N FOR-NEXT loop repeats the loop fixed number of times At the top of the loop index variable INDEX is given the value 1 NEXT INDEXreturns control to the top of the loop and variable INDEX is automatically incremented by 1, and looping continues until INDEX value exceeds the final limit N. Then the control goes to the statement following the NEXT statement PRINT "Sum of the first N digits is"; SUM prints the value of the variable SUM

More Related