Introduction to Programming
Introduction to Programming
Program
It means that when we say that we have a program, it actually means that we know about a complete set
activities to be performed in a particular order.
Reliability:
Any developed program for a particular application can be depended upon to do what it is
supposed to accomplish. How often the results of a program are correct. This depends on prevention of
resulting from data conversion and prevention of errors resulting from buffer overflows, underflows and zero
division.
Any developed system has a purpose for which it is developed. A developed program is a failure
if it cannot meet the objectives for which it is proposed and designed
Estimates of time and cost for writing computer programs have frequently been under or over
estimated. The components of a structured disciplined approach to programming are:
Error-Resistant Operations:
A good program should be designed in such a way that it can perform validation run on each
input data to determine whether or not they meet the criteria set for them.
Maintainable Code:
A good program design will always be easy to change or modify when the need arises.
Portable Code:
A good program design will be transferable to a different computer having a language translator
for that language without changes or modification
Readability:
The program codes will be easy for a programmer to read and understand the logic involved in
the programming.
Storage Saving:
A good program design will not be allowed to be unnecessary long, thereby consuming much
storage that will be required for processing data.
Efficiency:
The amount of system resources a program consumes (processor time, memory space, slow
devices, network bandwidth and to some extent even user interaction), the less the better.
Usability:
The clarity of a programs output can make or break it’s success. This involves a wide range of
textual and graphical elements that makes a program easy and comfortable to use.
Programming is an important activity as people life and living depends on the programs one make.
Programming Language
To write a program (tells what to do) for a computer, we must use a computer language. Over the years
computer languages have evolved from machine languages to natural languages.
Machine Language
❖ In the earliest days of computers, the only programming languages available were machine languages.
❖ Each computer has its own machine language which is made of streams of 0‘s and 1‘s.
❖ The instructions in machine language must be in streams of 0‘s and 1‘s. This is also referred as binary
digits.
❖ These are so named as the machine can directly understood the programs
Advantages:
3) No translation is needed.
Disadvantages:
1) Machine dependent
3) Difficult to understand
Assembly Language
❖ In the early 1950‘s Admiral Grace Hopper, a mathematician and naval officer, developed the concept
of a special computer program.
❖ These languages were known as symbolic languages. Because a computer does not understand
symbolic language it must be translated into the machine language.
Advantages:
Disadvantages:
2) Requires translator
5) Less efficient
High-Level Language
✓ A type of language that is close to human languages is called high level languages.
✓ The instructions in these languages are similar to English language such as input and output.
• C
• C++
• Pascal
• Basic
✓ Easy to learn
✓ Easy error detection
✓ Standardized syntax
✓ Deep hardware knowledge not required
✓ Machine independence
✓ More programmers
✓ Short programs
Advantages:
5) Better readability
7) Easier to document
8) Portable
Disadvantages:
1) Needs translator
4) Less efficient
Language Translator
These are the programs which are used for converting the programs in one language into machine language
instructions, so that they can be executed by the computer.
Compiler: It is a program which is used to convert the high level language programs into machine language
as a whole.
Assembler: It is a program which is used to convert the assembly level language programs into machine
language
Interpreter: It is a program which is used to convert the high level language programs into machine language
statement by statement.
Programming Tasks
In this phase, the program is implemented in some programming languages. Algorithm may be
set up for any type of problems, mathematical/scientific or business. Normally algorithms for mathematical
and scientific problems involve mathematical formulas.
Algorithm
✓ Algorithms are statements of steps involved in solving a particular problem. The steps to the solutions
are broken into series of logical steps in English related form.
✓ Programs are written to solve real life problems.
✓ There can’t be a solution if there is no recognized problem and once a problem exist, one must take
certain step in order to get a desired solution.
✓ The English form of representing as algorithm breaking down the solution steps of the problem into
single and sequential English words.
✓ The steps are represented in English to say what action should be taken in such a step.
Example 1
Develop an algorithm to obtain a book on computer from your school library located on the fourth floor
of the building. You are to proceed to the library from your ground floor classroom.
6. Stop.
Example 1
• Begin process
• Print area
• End process
Flowchart
flowchart is actually a graphical representation of a computer program
Advantages:
1.The flowchart is a waste of time and slows down the process of software development.
2.The flowchart is quite costly to produce and difficult to use and manage.
3.Flowcharts are not meant for man to computer communication.
4.If you need to modify or alternate the process then it will be very hard to do in the
flowchart.
Decision Table
✓ A decision table is a form of truth table that structures the logic of a problem into simple YES and
No form.
✓ It is easily adapted to the needs of business data processing. It is a rectangle divided into four sections
called quadrants.
✓ It provides a structure for showing logical relationships between conditions that exist and actions to
be taken as a result of these conditions.
Condition stub:- This gives a list of all the conditions that are relevant to the system.
Condition entry: - Shows a YES or NO entry (abbreviated to Y for YES and N for NO) whether listed
that condition is present or absent.
Action stubs: - This quadrant gives a list of all the actions that could be taken by the system, based on the
conditions.
Action entry: - This quadrant indicates whether a specific action will be taken or will not be taken
❖ All that is regarded to developed a decision table is a piece of paper and a pencil
❖ It makes the system designer to express the logic of the problem in direct and concise terms
❖ Decision tables provide a quick and easily understood over view of the system.
❖ Decision tables are easy to update.
❖ It is easy to learn how to use decision table.
DFD
A data flow diagram (DFD) maps out the flow of information for any process or system. It uses defined
symbols like rectangles, circles and arrows, plus short text labels, to show data inputs, outputs, storage points
and the routes between each destination
• Each data store should have at least one data flow in and one data flow out.
All computer programs can be coded using only three logic structures (or programs) or combinations of these
structures:
1. Simple sequence
2. Selection
3. Repetition
Sequence Structure
➢ The sequential structure executes the statements in the same order in which they are written in the
program. The statement is executed one after the other. All statements of the program are executed.
Selection Structure
➢ The selection structure executes a statement or set of statements based on a condition.
➢ It executes a statement if the given condition is true and ignore if the condition is false.
➢ It is also called decision-making structure or conditional Structure.
✓ if
✓ if-else
✓ if-else-if
✓ switch
Repetition Structure
➢ The repetition structure executes a statement or set of statements repeatedly for a specific number of
times. It is also called iteration structure or loop.
✓ while-loop
✓ do-while loop
✓ for loop