PROGRAMMING LANGUAGES Prof. Lani Cantonjos. PROGRAM - set of step-by-step instructions that tells or...

Post on 12-Jan-2016

214 views 0 download

Tags:

transcript

PROGRAMMING LANGUAGES

Prof. Lani Cantonjos

• PROGRAM - set of step-by-step instructions that tells or directs the computer what to do.

• PROGRAMMING LANGUAGE - Set of rules or instructions that tells the computer what to perform

PROGRAM LIFE CYCLE

• I. IDENTIFYING THE PROBLEM

This is the first step. it involves determining the requirement of the program.

ex. you are the programmer and somebody seeks your services in creating a program, As the client gives the desired output requirements, you are to analyze the need to be able to come up with a suitable programming solution.

• 2. PLANNING THE SOLUTION -

There are two ways of planning the solution to a problem, they are: 1. draw a flowchart and 2) write a pseudo code.

• FLOWCHART - is a graphical representation of the step-by-step instruction to be done in a program while

• PSEUDO CODE - is listing down the set of instructions to be used in the program.

• note: this 2 approaches are not executable in a programming language; you are just planning the solution.

• 3. CODING THE PROGRAM - as you designed the solution the next step is to code the program with the use of a chosen programming language.

• note:• SYNTAX - Programming languages have their

own set of rules to follow.

• SYNTAX ERROR - Violation of the rule set by programming language used in a certain program will produce an error.

• MISSPELLING - One of the common causes of syntax error.

• 4. TESTING THE PROGRAM -

• After coding the program, it is important to test if it is running. If it runs properly, then it is free from syntax error.

TESTING THE PROGRAM

• DESK CHECKING - In this phase the programmer just mentally traces or checks the logic of the program to make sure that its error free.

• TRANSLATION - In this phase the programming language uses a translator to ensure that the programmer did not violate any language rules by the chosen programming language. This program translates the program line by line to locate the syntax error.

• DEBUGGING - this means detecting, locating and correcting bugs. In programming, error or mistakes are called bugs. In debugging phase you run the program and use the dummy data or test data. Then, the programmer checks the flow of the program. If it is logic is error free and if it meets the requirements of the specified program.

• DOCUMENTATION- The programmer makes a detailed description on how the program was created. It contains a brief narrative process undergone by the program, from the identification of the problem, planning of the solution through flowcharting and pseudo code, coding of the program up to the testing results.

LEVELS OF PROGRAMMING LANGUAGES

• 1. MACHINE LANGUAGE OR FIRST GENERATION PROGRAMMING LANGUAGE - This is considered to be the lowest level of programming language. The program is considered by 1s and 0s. We all know the 1s and 0s or binary number is the only language the computer understands.

• ASSEMBLY LANGUAGES OR SECOND GENERATION PROGRAMMING LANGUAGE -

This is also considered as low level language. However, programmers would find this language easier to use than machine language. Instead of using 1s and 0s, assembly language uses mnemonic codes.

• HIGH LEVEL LANGUAGE OR THIRD GENERATION PROGRAMMING LANGUAGE 3GL

• This language transformed programming in the early 1960s. it makes programming easier since the language is now written in English like manner. If assembler is used by assembly language, third generation languages used translator to convert the program into a machine language.

• VERY HIGH LEVEL LANGUAGES OR 4TH GENERATION LANGUAGES (4GL)

• Fourth generation languages (4GL) simplifies further the third level generation languages 3GL because there is a reduction in the number of instructional statements. 100 lines of instructions in 3GLs can be reduced to 5 to 20 lines of instructions in 4GLs

• NATURAL LANGUAGES

• These languages are considered to be that 5th generation languages. These programming languages are called natural languages because of their resemblance to English language.

2nd Lecture

• PROCEDURAL AND NON PROCEDURAL LANGUAGES

• PROCEDURAL LANGUAGES – Programming languages which are considered procedural uses a series of instructions or statements which are sequential from the beginning to the end. This means that execution of instructions is line by line and it is terminated after the last instructions

Examples of Procedural Languages:

• BASIC (Beginner’s All-Purpose Symbolic Instruction Code)

• COBOL (Common Business Oriented Language)

• PASCAL

• FORTRAN (Formula Translator)

• C

• PL1 (Programming Language 1)

Non-Procedural Languages

• These programming languages are considered object-oriented programming languages. Statements are not executed line per line instead a series of instructions are executed as a whole when an event occurs.

Examples of Non-Procedural Languages

• VISUAL BASIC

• C++

• JAVA

• DELPHI

Flowcharting

• Flowchart is one of the processes used in designing or planning the solution to a problem. It is a graphical representation to the solution of a problem. It uses shapes to show instructions and arrow lines and heads to display the flow.

SYMBOLS

• Oval – Terminal Symbol – Represents start and end of program

• Parallelogram – Input/Output – Indicates input and output

• Rectangle – Process – This represents processing of action, e.g. mathematical operator

• Diamond – Decision – Since computer only answer the question yes/no, this is used to represent logical test for the program.

• Hexagon – Initialization / Preparation – This is used to prepare memory for repetition of an action.

• Arrow Lines & Arrow Heads – Direction – This shows the flow of the program

• Annotation – This is used to describe action or variables

• Circle – On Page Connector – This is used to show connector or part of program to another part.

• Pentagon – Off-Page connector – This is used to connect part of a program to another part on the other page or paper.

Structure of a Flowchart

Problem No. 1

• Draw a flowchart that will display the sum of 2 entered integers

• Requirement of the Problem No. 1– Ask the user to enter 2 integers

– Process it with Sum

– Display Result

Answer

• A =

Represent

The 1st

Integer

• B =

Represent

The 2nd integer

ENTER A, B

SUM=A+B

DISPLAY SUM

END

Exercise # 1

• Draw a flowchart that will compute for the average of 3 input quizzes. Then display the result.

Requirement of Assignment No. 1

1.Ask the user to input 3 quiz scores

2.Get the average of the 3 quizzes. Average is getting the sum of 3 scores divided by 3.

3.Display result.

Assignment #2

• Draw a flowchart that will display “Access Granted” If the password entered is equal to “Computer” else will display Access denied. Explain the action inside the flowchart and write it inside the box.

• Requirement of Assignment #2

1.Ask the user to enter the password

2.Display “Access Granted” if the password entered is equal to “Computer”, on the false side display “Access Denied”.

3rd lecture

• Use of Decision Symbol– One of the symbols used in flowcharting is the

decision symbol or the diamond. This symbol requires logical test that could be determined by using conditional statements or characters which are listed below. Through logical test, this symbol provides true answers, if the value evaluated by the decision symbol produces a “true” result or if it did not meet the value on the conditional statement it renders a “false” value.

Mathematical Notation Flowchart Notation Meaning

= = Equal

≠ ≠ Unequal

< < Less than

> > Greater than

≤ <= Less than or equal to

≥ >= More than or equal to

Equal

• The operator is used to compare two values for similarity. Syntax of the operator is:

– Is value 1=value2

• If value 1 and value 2 have the same value then they will move to the true side of the decision symbol. If both values hold different values, on the decision symbol it will move to the false side. This is illustrated as:

START

ENTER V1 and V2

V1 – represents value 1V2 – represents value 2

IS V1=V2

PROCESS FOR TRUE VALUE

PROCESS FOR FALSE VALUE

STOP

YES NO

ANSWER TO ASSIGNMENT #1START

ENTER PASSWORD

IS PASSWORD

= COMPUTER

DISPLAY ACCESS

DISPLAY ACCESS

STOP

YESNO

NOT EQUAL

• The operator is used to compare if the two values are not equal or show inequality. This is the inverse of equal operator.

• Syntax of the operator is:

– Is Value1 <> Value2

Exercise #1

• Draw a flowchart that will compare if 2 values are not equal (Use variables). If value1 and value2 are not equal or not alike, the flow of the flowchart will move to the “true” side of the decision symbol. If both values hold the same value then it will move or flow to the “false” side.

Quiz #2

• Draw a flowchart that will display “A Foreigner” if the country entered is not equal to Philippines else flowchart should display “A Filipino”. Explain the action inside the flowchart.

• Requirement of Program:– Ask user to enter country.– Use decision symbol and use logical test: if country <> Philippines– True side of the symbol is, country is not equal to Philippines display

“A Foreigner”– False side of the symbol is, if country is equal to Philippines then

display “A Filipino”.– End of Program.

Assignment #2

• Draw a flowchart that will display the higher number between two entered integers.– REQUIREMENT OF THE PROGRAM

• ASK USER TO ENTER TWO NUMBERS

• USE DECISION SYMBOL TO DETERMINE WHICH HAS THE HIGHER INTEGER.

– A. if N1 holds a value that is greater or higher than N2