Sie sind auf Seite 1von 43

Introduction to Programming

Information Technology Department

FEU EAST ASIA COLLEGE

A computer program (also a software program, or just


a program) is a sequence of instructions written to perform a specified task for a computer. A computer requires programs

to function, typically executing the program's instructions in


a central processor. The program has an executable form that the computer can use directly to execute the instructions.

Computer programs may be categorized along functional

lines: system software and application software.

Information Technology Department

FEU EAST ASIA COLLEGE

Source code is text written in a computer programming


language. Such a language is specially designed to facilitate the work of computer programmers, who specify the actions to be performed by a computer mostly by writing source code, which can then be automatically

translated to binary machine code that the computer can


directly read and execute.

Information Technology Department

FEU EAST ASIA COLLEGE

Computer programming (often shortened to programming


or coding) is the process of designing, writing, testing, debugging/ troubleshooting, and maintaining the source code of computer programs. This source code is written in a programming language. The purpose of programming is to create a program that exhibits a certain desired behavior. The process of writing source code often requires expertise in many different subjects, including knowledge of the

application domain, specialized algorithms and formal logic.


FEU EAST ASIA COLLEGE

Information Technology Department

Levels of Programming Languages


Machine Language Assembly Language High level Language

Low level language

Information Technology Department

FEU EAST ASIA COLLEGE

Machine Language
The fundamental language of the computers processor, also called Low Level Language. All programs are converted into machine language before they can be executed. Consists of combination of 0s and 1s that represent high and low electrical voltage.

Information Technology Department

FEU EAST ASIA COLLEGE

Assembly Language
A low level language that is similar to machine language. Uses symbolic operation code to represent the machine operation code.

Information Technology Department

FEU EAST ASIA COLLEGE

High Level Language


Computer (programming) languages that are easier to learn. Uses English like statements. Examples are C ++, Visual Basic, Pascal, Fortran and ....

Information Technology Department

FEU EAST ASIA COLLEGE

In addition to the distinction between high-level and low-level languages, there is a further distinction between compiler languages and interpreter languages. Let's take a look at the various levels.

Absolute Machine Code


The very lowest possible level at which you can program a computer is in its own native machine code, consisting of

strings of 1's and 0's and stored as binary numbers. The


main problems with using machine code directly are that it is very easy to make a mistake, and very hard to find it once you realize the mistake has been made.
Information Technology Department

FEU EAST ASIA COLLEGE

Assembly Language

No matter how close assembly language is to machine


code, the computer still cannot understand it. The assembly-language program must be translated into machine code by a separate program called an assembler. The assembler program recognizes the character strings that make up the symbolic names of the various machine operations, and substitutes the required machine code for each instruction.

Information Technology Department

FEU EAST ASIA COLLEGE

Compiler Language Compiler languages are the high-level equivalent of assembly language. Each instruction in the compiler language can correspond to many machine instructions. Once the program has been written, it is translated to the equivalent machine code by a program called a compiler.

Once the program has been compiled, the resulting machine


code is saved separately, and can be run on its own at any time.
FEU EAST ASIA COLLEGE

Information Technology Department

Interpreter Language
The interpreter program resides in memory, and directly executes the

high-level program without preliminary translation to machine code.


The primary advantage is that you can run the program to test its operation, make a few changes, and run it again directly. There is no need

to recompile because no new machine code is ever produced. This can


enormously speed up the development and testing process. On the down side, this arrangement requires that both the interpreter and

the user's program reside in memory at the same time. In addition,


because the interpreter has to scan the user's program one line at a time and execute internal portions of itself in response, execution of an interpreted program is much slower than for a compiled program.
Information Technology Department

FEU EAST ASIA COLLEGE

Program Development Cycle


1. Analyze: Define the problem 2. Design: Plan the solution to the problem 3. Choose the Interface: Select the objects 4. Code: Translate the algorithm into a programming language. 5. Debug and Test: Locate and remove any errors in the program. 6. Complete the Documentation: Organize all the materials that describe the program.
Information Technology Department

FEU EAST ASIA COLLEGE

Algorithm
A set of rules that precisely defines a sequence of operations.
Any set of detailed instructions which results in a predictable end-state from a known beginning.

Implementation
Most algorithms are intended to be implemented as computer program. However, algorithms are also implemented by other means, such as in a biological neural network (for example, the human brain implementing arithmetic or an insect looking for food), in an electrical circuit, or in a mechanical device.
Information Technology Department

FEU EAST ASIA COLLEGE

Expressing Algorithms
Algorithms can be expressed in many kinds of notation, including:

Natural Languages Pseudocode Flowcharts Programming Languages

Information Technology Department

FEU EAST ASIA COLLEGE

Pseudocode
A program design technique that uses English words. Has no formal syntactical rules. Pseudo means false, thus pseudocode means false code. It looks like (imitates) real code but it is NOT real code. Pseudocode cannot be compiled nor executed, and there are no real formatting or syntax rules. Pseudocode should not include keywords in any specific computer languages. The benefit of pseudocode is that it enables the programmer to concentrate on the algorithms without worrying about all the syntactic details of a particular programming language.
Information Technology Department

FEU EAST ASIA COLLEGE

How do I write Pseudocode?


First you may want to make a list of the main tasks that must be accomplished on a piece of scratch paper. Then, focus on each of those tasks. Generally, you should try to break each main task down into very small tasks that can each be explained with a short phrase. There may eventually be a one-to-one correlation between the lines of pseudocode and the lines of the code that you write after you have finished pseudocoding.

Information Technology Department

FEU EAST ASIA COLLEGE

It is not necessary in pseudocode to mention the need to declare variables. It is wise however to show the initialization of variables. All statements showing "dependency" are to be indented. These include while, do, for, if, switch.

Some Keywords That Should be Used


For looping and selection, the keywords that are to be used include: Do While...EndDo Call ... with (parameters) Do Until...Enddo Call Case...EndCase Return If...Endif When
Information Technology Department

FEU EAST ASIA COLLEGE

As verbs, use the words:


Generate, Compute, Process Set, Reset, Increment, Compute, Test Calculate, Add, Sum, Multiply, ... Print, Display, Input, Output, Edit

Information Technology Department

FEU EAST ASIA COLLEGE

Pseudocode Examples
Original Program Specification:

Write a program that obtains two integer numbers from the user. It will print out the sum of those numbers.
Pseudocode: Prompt the user to enter the first integer Prompt the user to enter a second integer Compute the sum of the two user inputs Display an output prompt that explains the answer as the sum Display the result
Information Technology Department

FEU EAST ASIA COLLEGE

Original Program Specification:


Write a program that will display if the entered students grade is passed of failed. Passing grade is 70. Pseudocode: Prompt the user to enter a student grade If student's grade is greater than or equal to 70 Print "passed" else Print "failed"

Information Technology Department

FEU EAST ASIA COLLEGE

Original Program Specification: Write a program that will allow the student to input the grade on his 5 subjects and will compute for his average grade.

Original Program Specification:


Set total to zero Set grade counter to one While grade counter is less than or equal to 5 Input the next grade Add the grade into the total Set the class average to the total divided by 5 Print the class average.
Information Technology Department

FEU EAST ASIA COLLEGE

Pseudocode example : If then Else

If age > 17 Display a message indicating you can vote. Else Display a message indicating you can't vote. Endif
Pseudocode example : Case

Case of age 0 to 17 Display "You can't vote." 18 to 64 Display "Your in your working years." 65 + Display "You should be retired." Endcase
Information Technology Department

FEU EAST ASIA COLLEGE

Pseudocode example : While loop

count assigned zero While count < 5 Display "I love computers!" Increment count Endwhile
Pseudocode example : For loop For x starts at 0, x < 5, increment x Display "Are we having fun?" Endfor

Information Technology Department

FEU EAST ASIA COLLEGE

Pseudocode example : Do While loop

count assigned five Do Display "Blast off is soon!" Decrement count While count > zero
Pseudocode example : Repeat Until loop

count assigned five Repeat Display "Blast off is soon!" Decrement count Until count < one
Information Technology Department

FEU EAST ASIA COLLEGE

Pseudocode example : Function with no parameter passing


Function clear monitor Pass In: nothing Direct the operating system to clear the monitor Pass Out: nothing Endfunction

Pseudocode example : Function with parameter passing


Function delay program so you can see the monitor Pass In: integer representing tenths of a second Using the operating system delay the program Pass Out: nothing Endfunction
Information Technology Department

FEU EAST ASIA COLLEGE

Pseudocode of : Function main calling the clear monitor function Function main Pass In: nothing Doing some lines of code Call: clear monitor Doing some lines of code Pass Out: value zero to the operating system Endfunction

Information Technology Department

FEU EAST ASIA COLLEGE

Flowchart
The flowchart is a means of visually presenting the flow of data through an information processing systems, the operations performed within the system and the sequence in which they are performed. In our lesson, we shall concern ourselves with the program flowchart, which describes what operations (and in what sequence) are required to solve a given problem. The program flowchart can be likened to the blueprint of a building. As we know a designer draws a blueprint before starting construction on a building. Similarly, a programmer prefers to draw a flowchart prior to writing a computer program. As in the case of the drawing of a blueprint, the flowchart is drawn according to defined rules and using standard flowchart symbols prescribed by the American National Standard Institute, Inc. (ANSI)
Information Technology Department

FEU EAST ASIA COLLEGE

Meaning of Flowchart
A flowchart is a diagrammatic representation that illustrates the sequence of operations to be performed to get the solution of a problem. Logic diagram to describe each step that the program must perform to arrive at the solution. A popular logic tool used for showing an algorithm in graphics form. Flowcharting software examples : microsoft visio, flowbreeze, RFFlow, SmartDraw
Information Technology Department

FEU EAST ASIA COLLEGE

Types of Flowcharts
Document Flowchart Data Flowchart System Flowchart Program Flowchart

Information Technology Department

FEU EAST ASIA COLLEGE

Flowcharting Symbols

Information Technology Department

FEU EAST ASIA COLLEGE

Information Technology Department

FEU EAST ASIA COLLEGE

Information Technology Department

FEU EAST ASIA COLLEGE

Guidelines for Drawing a Flowchart


In drawing a proper flowchart, all necessary requirements should be listed out in logical order. The flowchart should be clear, neat and easy to follow. There should not be any room for ambiguity in understanding the flowchart. The usual direction of the flow of a procedure or system is from left to right or top to bottom.

Information Technology Department

FEU EAST ASIA COLLEGE

Only one flow line should come out from a process symbol.

Only one flow line should enter a decision symbol, but two or three flow lines, one for each possible answer, should leave the decision symbol.

Information Technology Department

FEU EAST ASIA COLLEGE

Only one flow line is used in conjunction with terminal symbol.

Write within standard symbols briefly. As necessary, you can use the annotation symbol to describe data or computational steps more clearly.

Information Technology Department

FEU EAST ASIA COLLEGE

If the flowchart becomes complex, it is better to use connector symbols to reduce the number of flow lines. Avoid the intersection of flow lines if you want to make it more effective and better way of communication. Ensure that the flowchart has a logical start and finish.

It is useful to test the validity of the flowchart by passing through it with a simple test data.

Information Technology Department

FEU EAST ASIA COLLEGE

ADVANTAGES OF USING FLOWCHARTS


The benefits of flowcharts are as follows:

Communication: Flowcharts are better way of communicating the logic of a system to all concerned.
Effective analysis: With the help of flowchart, problem can be analyzed in more effective way. Proper documentation: Program flowcharts serve as a good program documentation, which is needed for various purposes.

Information Technology Department

FEU EAST ASIA COLLEGE

Efficient Coding: The flowcharts act as a guide or blueprint during the systems analysis and program development phase. Proper Debugging: The flowchart helps in debugging process. Efficient Program Maintenance: The maintenance of operating program becomes easy with the help of flowchart. It helps the programmer to put efforts more efficiently on that part

Information Technology Department

FEU EAST ASIA COLLEGE

LIMITATIONS OF USING FLOWCHARTS


Complex logic: Sometimes, the program logic is quite complicated. In that case, flowchart becomes complex and clumsy. Alterations and Modifications: If alterations are required the flowchart may require re-drawing completely. Reproduction: As the flowchart symbols cannot be typed, reproduction of flowchart becomes a problem.

Information Technology Department

FEU EAST ASIA COLLEGE

Flowcharting Examples
Example 1
Draw a flowchart to find the sum of first 50 natural numbers.

Information Technology Department

FEU EAST ASIA COLLEGE

Example 2 Draw a flowchart to find the largest of three numbers A,B, and C.

Information Technology Department

FEU EAST ASIA COLLEGE

Example 3 Draw a flowchart for computing factorial N (N!) Where N! = 1 2 3 N .

Information Technology Department

FEU EAST ASIA COLLEGE

Das könnte Ihnen auch gefallen