Introduction to Computer Programming
Programming languages
Translators : Compilers and Interpreters
Algorithm
Flowchart
[Link]
Associate Professor(Computer Science)
Agricultural College and Research Institute
Madurai
PROGRAMMING LANGUAGE
Language can be defined as means of communication.
To communicate any
idea, thought, instruction or information, humans make use of spoken language.
Spoken languages are not understood by machines.
To communicate instructions to a computer, humans need a language
which we call a programming language.
Types of Language
Machine Language
Computers understand the language of 0’s and 1’s.
To perform some specific task we have to put these 0’s and 1’s in a particular sequence.
This kind of a programming language is called Machine Language.
Assembly language
Use mnemonic code and instruction
High level Language
Easily understand by the human
Ex. C , C++, Java,Python
Machine independent
statements are written using English words and a set of familiar mathematical symbols
Difference between Machine and Assembly Language
Translator
Compiler
A compiler is a computer program that translates computer code written in one programming
language (the source language) into another language (the target language).
Interpreter
An assembler is a translator used to translate assembly language into machine language
Compiler
Computer Program
Computers work on a set of instructions called computer program,
specify the ways to carry out a task.
Computer programs are developed using computer or programming languages.
Programming involves many stages
task analysis
algorithm
flowchart
coding
program testing
implementation
documentation and maintenance
Algorithm
Algorithm is a precise rule which specifies how to solve a
problem.
An algorithm, is defined as a “well-ordered collection of
unambiguous and effectively computable operations,
that when executed, produces a result and halts in a
finite amount of time.”
It provides a logical structure to plan the solution.
Once the solution is properly designed, the only job left
is to code that logic into the respective programming
language.
Characteristics / Properties of an Algorithm
Each and every instruction should be precise and clear
Each instruction should be performed a finite number of times
The algorithm should ultimately terminate
When the algorithm terminates the desired result should be obtained.
Example 1: Write an algorithm to find the largest number out of three numbers
Step 1 : Start
Step 2 : Read three numbers say A, B and C
Step 3: Find the largest number between A and B and store it in MAX_AB
Step 4: Find the largest number between MAX_AB and C and store it in MAX
Step 5: Display MAX
Step 6: Stop
Flowchart
A flowchart is a pictorial representation of an algorithm
The steps are drawn in the form of different shapes of boxes and the logical flow is indicated by
interconnecting arrows.
The boxes represent operations and the arrows represent the sequence in which the operations
are implemented.
Flowchart is to help the programmer in understanding the logic of the program.
FLOWCHART
FLOWCHART
FLOWCHART (PROGRAM CONTROL)
STRUCTURES
Program statements that affect the order in which statements are executed are called control
structures.
1. Sequence, where information flows in a straight line.
2. Selection, Where the decisions are made according to some predefined condition.
3. Repetition, where the logic is repeated in a loop until the desired output is obtained.
Selection:
A selection structure allows the program to make a choice between two alternate paths, whether
it is true or false.
Thus the selection structure has a only a single entry and a single exit.
Repetition
Repetition or loop pattern causes an interruption in the normal sequence of processing.
It directs the system to loop back to a previous statement in the program, repeating the same
sequence over and again, usually with new data.
Using looping, the programmer avoids writing the same set of instructions again.
Example : Draw a flowchart to calculate the Crop Growth Rate (CGR)