0% found this document useful (0 votes)
2 views

Introduction to Programming

The document provides an introduction to programming, emphasizing the definition of a program, its essential features, and the skills needed for effective programming. It outlines the evolution of programming languages from machine languages to high-level languages, detailing their advantages and disadvantages, as well as the role of language translators. Additionally, it discusses programming tasks, algorithms, and basic coding structures, highlighting methods for problem-solving and implementation.

Uploaded by

Extra Test
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Introduction to Programming

The document provides an introduction to programming, emphasizing the definition of a program, its essential features, and the skills needed for effective programming. It outlines the evolution of programming languages from machine languages to high-level languages, detailing their advantages and disadvantages, as well as the role of language translators. Additionally, it discusses programming tasks, algorithms, and basic coding structures, highlighting methods for problem-solving and implementation.

Uploaded by

Extra Test
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Introduction to Programming

BS Chemistry 1st Semester

Program

"A program is a precise sequence of steps to solve a particular problem.”

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.

Features of a good computer program

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.

Meeting Users Needs:

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

Development on time within Budgets:

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:

i) Proper control and management of time and cost required.

ii) Increased programmer productivity

iii) More accurate estimates.

Error-Free Set of Instruction

If a program is designed and developed in a disciplined structured approach, it minimizes the


errors and facilitate detection/correction of such errors during program testing.

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.

What skills are needed

Programming is an important activity as people life and living depends on the programs one make.

Hence while programming one should

Think about the reusability.

Think about user interface

Understand the fact the computers are stupid

Comment the code liberally

Paying attention to detail

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.

The following is the summary of computer languages

1940‘s -- Machine Languages

1950‘s -- Symbolic Languages

1960‘s -- High Level 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:

1) High speed execution

2) The computer can understood instructions immediately

3) No translation is needed.

Disadvantages:

1) Machine dependent

2) Programming is very difficult

3) Difficult to understand

4) Difficult to write bug free programs

5) Difficult to isolate an error

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:

1) Easy to understand and use

2) Easy to modify and isolate error

3) More control on hardware

Disadvantages:

1) Machine Dependent Language

2) Requires translator

3) Difficult to learn and write programs

4) Slow development time

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

Characteristics of high level language

✓ Easy to learn
✓ Easy error detection
✓ Standardized syntax
✓ Deep hardware knowledge not required
✓ Machine independence
✓ More programmers
✓ Short programs

Advantages:

1) Easy to write and understand

2) Easy to isolate an error

3) Machine independent language


4) Easy to maintain

5) Better readability

6) Low Development cost

7) Easier to document

8) Portable

Disadvantages:

1) Needs translator

2) Requires high execution time

3) Poor control on hardware

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

A typical programming task can be divided into two phases:

✓ Problem solving phase


▪ In this stage an ordered sequence of steps that describe solution of the problem is
produced. Their sequence of steps can be called anti-Algorithm
✓ Implementation Phase

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 following methods could be used to represent an algorithm.

❖ Methods of English like form


❖ Methods of Flowchart
❖ Methods of Pseudo code
❖ Methods of Decision table
❖ Methods of Data flow Diagram (DFD)

Methods of English like form

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

1. Start from the classroom


2. Climb the stairs to the 4th floor and reach the library

3. Search a book on computer

4. Have the book issued

5. Return to your classroom

6. Stop.

Method of Pseudo Code

✓ A pseudo code is the English-like representation of the program logic.


✓ It is the detailed form of algorithm.
✓ It does not make use of standard symbols like the flowchart.
✓ It is a step by step arrangement of the instructions to be performed to complete a task.
✓ It is an informal and artificial language that helps programmers develops algorithms.

Example 1

Write a pseudo code for findings the area of a room. Solution:

• Begin process

• Input room length

• Input room width

• Multiply length by width to get area

• Print area

• End process

Flowchart
flowchart is actually a graphical representation of a computer program

Advantages:

1. It is a convenient method of communication.


2. It indicates very clearly just what is being done, where a program has logical
complexities.
3. A key to correct programming.
4. It is an important tool for planning and designing a new system.
5. It clearly indicates the role-played at each level.
6. It provides an overview of the system.
7. Facilitates troubleshooting.
8. It promotes logical accuracy.
9. It makes sure that no logical path is left incomplete without any action being taken.
Disadvantages

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

The condition entries

i Y is an indication that the condition is present

ii N is an indication that the condition is not present

iii - or blank is an indication that the condition was not tested.

The action entries

i X is an indication that the listed action to be taken.

ii blank is an indication that the action is not to be taken.


Advantages

❖ 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

Rules and Interpretations for correct data flow diagrams.

• Each process should have at least one input and an output.

• Each data store should have at least one data flow in and one data flow out.

• Data stored in a system must go through a process.

• All processes in a DFD go to another process or a data store.

Basic Coding Structures

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.

Different types of selection structures in C are as follows

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

Different types of loops available are as follows

✓ while-loop
✓ do-while loop
✓ for loop

You might also like