Presentation is loading. Please wait.

Presentation is loading. Please wait.

PROGRAMMING: What’s It All About?

Similar presentations


Presentation on theme: "PROGRAMMING: What’s It All About?"— Presentation transcript:

1 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

2 INPUT Ingredients: sugar, flour recipe OUTPUT Software Hardware
Oven/baker (mixing, pouring, heating etc.) 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

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

5 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

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

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

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

9 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".

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

11 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

12 CONTROL STRUCTURES A A A
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

13 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

14 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

15 Diagrams for algorithms
Flowcharts

16 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

17 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

18 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

19 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 INDEX returns 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


Download ppt "PROGRAMMING: What’s It All About?"

Similar presentations


Ads by Google