GE6151 - COMPUTER PROGRAMMING -...

68
GE6151 - COMPUTER PROGRAMMING

Transcript of GE6151 - COMPUTER PROGRAMMING -...

GE6151 -

COMPUTER

PROGRAMMING

UNIT – I

INTRODUCTION

What is Computer?

Definition

Computer System is an electronic data processing device which does the following:

1. Accept and store an input data.

2. Process the data input.

3. And output the processed data in required format.

Functionalities of a computer

Any digital computer carries out five functions in gross terms:

1. Takes data as input.

2. Stores the data/instructions in its memory and can use them when required.

3. Process the data and convert it into useful information.

Output the information.

Control all the above four steps.

Advantages

High Speed

1. Computer is a very fast device.

2. It is capable of performing addition of very big data.

3. The computer has units of speed in microsecond, nanosecond and even the

picosecond.

4. It can perform millions of calculations in a few seconds as compared to man who can

spend many months for doing the same task.

Accuracy

1. In addition to being very fast, computer are very accurate.

2. The computer has performed calculations 100% error free.

3. Computers perform all jobs with 100% accuracy.

Storage Capability

1. Memory is a very important characteristic of computers.

2. The computer has much more storage capacity than human beings.

3. It can store large amount of data.

4. It can store any type of data such as images, videos, text, audio and any other type.

Diligence

1. Unlike human beings, a computer is free from monotony, tiredness and lack of

concentration.

2. It can work continuously without creating any error and boredom.

3. It can do repeated work with same speed and accuracy.

Versatility

1. A computer is a very versatile machine.

2. A computer is very flexible in performing the jobs to be done.

3. This machine can be used to solve the problems relating to various different fields.

4. At one instant, it may be solving a complex scientific problem and the very next

moment it may be playing a card game.

Reliability

1. A computer is a reliable machine.

2. Modern electronic components have failure free long lives.

3. Computers are designed to make maintenance easy.

Automation

1. Computer is a automatic machine.

2. Automation means ability to perform the task automatically.

3. Once a program is given to computer i.e stored in computer memory, the program

and instruction can control the program execution without human interaction.

Reduction in Paper Work

1. The use of computers for data processing in an organization leads to reduction in

paper work and speeds up the process.

2. As data in electronic files can be retrieved as and when required,the problem of

maintenance of large number of files gets reduced.

Reduction in Cost

1. Though the initial investment for installing a computer is high but it substantially

reduces the cost of each of its transaction.

Disadvantages

Following list demonstrates the disadvantages of Computers in today's arena.

No I.Q

1. A computer is a machine and has no intelligence of its own to perform any task.

2. Each and every instruction has to be given to computer.

3. A computer can not take any decision on its own.

Dependency

1. It can perform function as instructed by user.So it is fully dependent on human being.

Environment

2. The operating environment of computer should be dust free and suitable to it.

No Feeling

1. Computer has no feeling or emotions.

2. It cannot make Judgement based on feeling, taste, experience and knowledge unlike

a human being.

Computer - Applications

Business

The computer's characteristic as high speed of calculation, diligence,accuracy,

reliability, or versatility has made it an integerated part in all business organisations.

Computer used in business organisation for:

1. Payroll Calculations

2. Budgeting

3. Sales Analysis

4. Financial forcasting

5. Managing employees database

6. Maintenance of stocks etc. Banking

1. Today Banking is almost totally dependent on computer.

2. Banks provide following facilities:

3. Banks on-line accounting facility, which include current balances, deposits,

overdrafts, interest charges, shares and trustee records.

4. ATM machines are making it even easier for customers to deal with banks.

Insurance

Insurance companies are keeping all records up to date with the help of computer.The

Insurance Companies, Finance houses and Stock broking firms are widely using computers for

their concerns.

Insurance Companies are maintaining a database of all clients with information

showing

1. how to continue with policies

2. starting date of the policies

3. next due installment of a policy

4. maturity date

5. interests due

6. survival benefits

7. bonus

Education

1. The computer has provided a lot of facilities in the Education System.

2. The uses of computer provide a tool in the Education system is known as CBE

(Computer Based Education).

3. CBE involves Control, Delivery and Evaluation of learning.

4. The computer education is very familiar and rapidly increasing the graph of

computer students.

5. There are number of methods in which educational institutions can use computer to

educate the students.

6. It is used for prepare a database about student performance and analysis are carried

out.

Marketing

Advertising: With computers, advertising professionals create art and graphics, write

and revise copy, and print and disseminate ads with the goal of selling more products.

At Home Shopping: At home shopping has been made possible through use of

computerised catalogues that provide access to product information and permit direct

entry of orders to be filled by the customers.

Health Care

Computers have become important part in all Medical Systems. The computers are

being used in hospitals to keep the record of patients and medicines. It is also used in scanning

and diagnosing different diseases. ECG, EEG, Ultrasounds and CT Scans etc. are also done by

computerised machines.

Some of major fields of health care in which computer are used:

1. Diagnostic System: Computers are used to collect data and identify cause of illness.

2. Lab-diagnostic System:All tests can be done and reports are prepared by computer.

3. Patient Monitoring System:These are used to check patient's signs for abnormality

such as in Cardiac Arrest, ECG etc.

4. Pharma Information System:Computer checks Drug-Labels, Expiry dates, harmful

drug side effects etc.

Nowadays, computers are also used in performing surgery.

Military

Computers are largely used in defence.Modern tanks, missiles, weapons etc.employ computerised

control systems.Some military areas where a computer has been used are:

1. Missile Control

2. Military Communication

3. Military operation and planning

4. Smart Weapons

Communication

Communication means to convey a message, an idea, a picture or speech that is

received and understood clearly and correctly by the person for whom it is meant.Some main

areas in this category are:

1. E-mail

2. Chatting

3. Usenet

4. FTP

5. Telnet

5. Video-conferencing

Government Applications

Computers play an important role in government applications. Some major fields in this

category are:

1. Budgets 2. Sales tax department

3. Income tax department 4. Male/Female ratio

5. Computerization of voters lists

6. Computerization of Driving Licensing system

7. Computerization of PAN card 8. Weather Forecasting.

Computer Generations

Generation in computer terminology is a change in technology a computer is/was

being used. Initially, the generation term was used to distinguish between varying hardware

technologies. But nowadays, generation includes both hardware and software, which together

make up an entire computer system.

There are totally five computer generations known till date. Each generation has been

discussed in detail along with their time period, characteristics. We've used approximate dates

against each generations which are normally accepted.

S.N. Generation & Description

1 First Generation

The period of first generation : 1946-1959. Vaccum tube based.

2 Second Generation

The period of second generation : 1959-1965. Transistor based.

3 Third Generation

The period of third generation : 1965-1971. Integrated Circuit based.

4 Fourth Generation

The period of fourth generation : 1971-1980. VLSI microprocessor based.

5 Fifth Generation

The period of fifth generation : 1980-onwards.ULSI microprocessor based

First Generation 1946-1959

The period of first generation was 1946-1959.

First generation of computer started with using vacuum tubes as the basic components

for memory and circuitry for CPU(Central Processing Unit). These tubes like electric bulbs

produced a lot of heat and were prone to frequent fusing of the installations, therefore, were very

expensive and could be afforded only by very large organisations.

In this generation mainly batch processing operating system were used. In this generation

Punched cards, Paper tape, Magnetic tape Input & Output device were used.

There were Machine code and electric wired board languages used.

The main features of First Generation are:

1. Vacuum tube technology 2. Unreliable

3. Supported Machine language only 4. Very costly

5. Generate lot of heat 6. Slow Input/Output device

7. Huge size 8. Need of A.C.

9.Non portable 10. Consumed lot of electricity

Some computer of this generation were:

1. ENIAC (ELECTRONIC NUMERICAL INTEGRATOR AND COMPUTER)

2. EDVAC (ELECTRONIC DISCRETE VARIABLE AUTOMATIC COMPUTER)

3. UNIVAC (UNIVERSAL AUTOMATIC COMPUTER)

4. IBM-701 (INTERNATION BUSINESS MACHINE – 701)

5. IBM-650 (INTERNATION BUSINESS MACHINE – 650)

Second Generation

The period of second generation was 1959-1965.

This generation using the transistor were cheaper, consumed less power, more compact

in size, more reliable and faster than the first generation machines made of vaccum tubes.In this

generation, magnetic cores were used as primary memory and magnetic tape and magnetic disks

as secondary storage devices.

In this generation assembly language and high level programming language like

FORTRAN, COBOL were used.

There were Batch processing and Multiprogramming Operating system used.

The main features of Second Generation are:

1. Use of transistors

2. Reliable as compared to First generation computers

3. Smaller size as compared to First generation computers

4. Generate less heat as compared to First generation computers

5. Consumed less electricity as compared to First generation computers

6. Faster than first generation computers 7. Still very costly

7. A.C. needed 8. Support machine and assembly languages

Some computer of this generation were:

1. IBM 1620 (INTERNATION BUSINESS MACHINE – 1620)

2. IBM 7094 (INTERNATION BUSINESS MACHINE – 7094)

3. CDC 1604 (CONTROL DATA CORPORATION – 1604)

4. CDC 3600 (CONTROL DATA CORPORATION – 3600)

5. UNIVAC 1108 (UNIVERSAL AUTOMATIC COMPUTER - 1108)

Third Generation

The period of third generation was 1965-1971.

The third generation of computer is marked by the use of Integrated Circuits (IC's) in

place of transistors.A single I.C has many transistors, resistors and capacitors along with the

associated circuitry.The I.C was invented by Jack Kilby. This development made computers

smaller in size, reliable and efficient.

In this generation Remote processing, Time-sharing, Real-time, Multi-programming

Operating System were used.

High level language (FORTRAN-II TO IV, COBOL, PASCAL PL/1, BASIC, ALGOL-

68 etc.) were used during this generation.

The main features of Third Generation are:

1. IC used 2. More reliable

3. Smaller size 4. Generate less heat

5. Faster 6. Lesser maintenance

7. Still costly 8. A.C needed

9. Consumed lesser electricity 10. Support high level language

Some computer of this generation were:

1. IBM-360 series - (INTERNATIONAL BUSINESS MACHINE – 360 SERIES)

2. Honeywell-6000 series

3. PDP - (PERSONAL DATA PROCESSOR)

4. IBM-370/168 - (INTERNATIONAL BUSINESS MACHINE – 370/168)

5. TDC-316 – (TORPEDO DATA COMPUTER – 316)

Fourth Generation

The period of Fourth Generation was 1971-1980.

The fourth generation of computers is marked by the use of Very Large Scale Integrated

(VLSI) circuits.VLSI circuits having about 5000 transistors and other circuit elements and their

associated circuits on a single chip made it possible to have microcomputers of fourth generation.

Fourth Generation computers became more powerful, compact, reliable, and affordable. As a

result, it gave rise to personal computer (PC) revolution.

In this generation Time sharing, Real time, Networks, Distributed Operating System

were used.

All the Higher level languages like C and C++, DBASE etc. were used in this

generation. The main features of Fourth Generation are:

1. VLSI technology used 2. Very cheap

3. Portable and reliable 4. Use of PC's

5. Very small size 6. Pipeline processing

7. No A.C. needed 8. Concept of internet was introduced

9. Great developments in the fields of networks 10.Computers became easily available

Some computer of this generation were:

1. DEC 10 - (DIGITAL EQUIPMENT CORPORATION – 10) 2. STAR 1000

3. PDP 11 – (PROGRAMMED DATA PROCESSOR 11) 4. CRAY-1(Super Computer)

5. CRAY-X-MP(Super Computer)

Fifth Generation

The period of Fifth Generation is 1980-till date.

In the fifth generation, the VLSI technology became ULSI (Ultra Large Scale

Integration) technology, resulting in the production of microprocessor chips having ten million

electronic components.

This generation is based on parallel processing hardware and AI (Artificial

Intelligence) software.

AI is an emerging branch in computer science, which interprets means and method of

making computers think like human beings.

All the Higher level languages like C and C++, Java, .Net etc. are used in this

generation. AI includes:

1.Robotics

2. Neural networks

3. Game Playing

4. Development of expert systems to make decisions in real life situations.

5. Natural language understanding and generation.

The main features of Fifth Generation are:

1. ULSI technology

2. Development of true artificial intelligence

3. Development of Natural language processing

4. Advancement in Parallel Processing

5. Advancement in Superconductor technology

6. More user friendly interfaces with multimedia features

7. Availability of very powerful and compact computers at cheaper rates

Some computer types of this generation are:

1. Desktop

2. Laptop

3. NoteBook

4. UltraBook

5. ChromeBook

CLASSIFICATION OF COMPUTER Computer can be broadly classified by their speed and computing power.

Sr.

No. Type Specifications

1 PC (Personal

Computer) Single user computer system. Moderately powerful microprocessor.

2 WorkStation Single user computer system. Similar to Personal Computer but have more

powerful microprocessor.

3 Mini Computer Multi-user computer system. Capable of supporting hundreds of users

simultaneously.

4 Main Frame Multi-user computer system. Capable of supporting hundreds of users

simultaneously. Software technology is different from minicomputer.

5 Supercomputer An extremely fast computer which can perform hundreds of millions of

instructions per second.

PC (Personal Computer)

A PC can be defined as a small, relatively inexpensive computer designed for an

individual user. PCs are based on the microprocessor technology that enables manufacturers to

put an entire CPU on one chip. Businesses use personal computers for word processing,

accounting, desktop publishing, and for running spreadsheet and database management

applications. At home, the most popular use for personal computers is for playing games and

surfing the Internet.

Although personal computers are designed as single-user systems, these systems are

normally linked together to form a network. In terms of power, now-a-days High-end models of

the Macintosh and PC offer the same computing power and graphics capability as low-end

workstations by Sun Microsystems, Hewlett-Packard, and DELL.

WorkStation

Workstation is a computer used for engineering applications (CAD/CAM), desktop

publishing, software development, and other such types of applications which require a moderate

amount of computing power and relatively high quality graphics capabilities.

Workstations generally come with a large, high-resolution graphics screen, large

amount of RAM, inbuilt network support, and a graphical user interface. Most workstations also

have a mass storage device such as a disk drive, but a special type of workstation, called a

diskless workstation, comes without a disk drive.

Common operating systems for workstations are UNIX and Windows NT. Like PC,

Workstations are also single-user computers. However, workstations are typically linked together

to form a local-area network, although they can also be used as stand-alone systems.

Minicomputer

It is a midsize computer. A minicomputer is a multi-processing system capable of

supporting from up to 250 users simultaneously.

Mainframe

Mainframe is a very large in size and is an expensive computer capable of supporting hundreds,

or even thousands, of users simultaneously. Mainframe executes many programs concurrently.

Mainframes support many simultaneous programs execution.

Supercomputer

Supercomputers are one of the fastest computers currently available. Supercomputers are very

expensive and are employed for specialized applications that require immense amounts of

mathematical calculations (number crunching). For example, weather forecasting , scientific

simulations, (animated) graphics, fluid dynamic calculations, nuclear energy research, electronic

design, and analysis of geological data (e.g. in petrochemical prospecting).

Comparison between different types Computers

BASIC ORGANIZATION OF COMPUTER

All types of computer follows a same basic logical structure and perform the following five basic

operations for converting raw input data into information useful to their users

Sr.

No. Operation Description

1 Take Input The process of entering data and instructions into the computer system.

2 Store Data Saving data and instructions so that they are available for processing as and when required.

3 Processing Data Performing arithmetic , logical operations on data in order to convert them into useful

information.

4 Output Information The process of producing useful information or results for the user,such as a printed report or

visual display.

5 Control the

workflow Direct the manner and sequence in which all of the above operations are performed.

Input Unit

This unit contains devices with the help of which we enter data into computer. This unit

makes link between user and computer.

The input devices translate the human being information into the form understandable

by computer.

Following are few of the important input devices which are used in Computer Systems

1. Keyboard 2. Mouse 3. Joy Stick

4. Light pen 5. Track Ball 6. Scanner

7. Graphic Tablet 8. Microphone 9. Magnetic Ink

10. Card Reader(MICR) 11. Optical Character Reader(OCR)

12. Bar Code Reader 13. Optical Mark Reader

CPU Unit

1. Memory Or Storage Unit:

2. Control Unit

3. ALU(Arithmetic Logic Unit)

Memory Or Storage Unit:

1. This unit can store instruction, data and intermediate results. This unit supplies

information to the other units of the computer when needed. It is also known as internal storage

unit or main memory or primary storage or Random access memory(RAM).

2. Its size affects speed, power and capability. There are primary memory and

secondary memory two types of memories in the computer. Function of Memory Unit are:

3. It stores all the data to be processed and the instructions required for processing.

4. It stores intermediate results of processing.

5. It stores final results of processing before these results are released to an output

device.

6. All inputs and outputs are transmitted through main memory.

Control Unit

This unit controls the operations of all parts of computer. It does not carry out any

actual data processing operations.

Functions of this unit are

1. It is responsible for controlling the transfer of data and instructions among

other units of a computer.

2. It manages and coordinates all the units of the computer.

3. It obtains the instructions from the memory, interprets them and directs the

operation of the computer.

4. It communicates with Input/Output devices for transfer of data or results

from storage.

5. It does not process or store data.

ALU(Arithmetic Logic Unit)

This unit consists of two subsection namely

1. Arithmetic section

2. Logic Section

1. Arithmetic section

Function of Arithmetic section is to perform arithmetic operations like addition, subtraction,

multiplication and division. All complex operations are done by making repetitive use of above

operations.

2. Logic Section

Function of logic section is to perform logic operations such as comparing, selecting, matching

and merging of data.

Output Unit

Output unit consists of devices with the help of which we get the information from

computer. This unit is a link between computer and users.

Output devices translate the computer's output into the form understandable by users.

Following are few of the important output devices which are used in Computer Systems

1. Monitors 2. Graphic Plotter 3. Printer

NUMBER SYSTEM

When we type some letters or words, the computer translates them in numbers as

computers can understand only numbers.

A computer can understand positional number system where there are only a few

symbols called digits and these symbols represent different values depending on the position they

occupy in the number.

A value of each digit in a number can be determined using The digit

1. The position of the digit in the number

2. The base of the number system (where base is defined as the total number

of digits available in the number system).

Common Number Systems

System Base Symbols Used by humans? Used in computers?

Decimal 10 0, 1, … 9 Yes No

Binary 2 0, 1 No Yes

Octal 8 0, 1, … 7 No No

Hexa-

decimal

16 0, 1, … 9,

A, B, … F

No No

Quantities/Counting

Decimal Binary Octal Hexa-

decimal

0 0 0 0

1 1 1 1

2 10 2 2

3 11 3 3

4 100 4 4

5 101 5 5

6 110 6 6

7 111 7 7

Decimal Binary Octal Hexa-

decimal

8 1000 10 8

9 1001 11 9

10 1010 12 A

11 1011 13 B

12 1100 14 C

13 1101 15 D

14 1110 16 E

15 1111 17 F

Decimal Binary Octal Hexa-

decimal

16 10000 20 10

17 10001 21 11

18 10010 22 12

19 10011 23 13

20 10100 24 14

21 10101 25 15

22 10110 26 16

23 10111 27 17

Conversion Among Bases

Decimal to Decimal

Decimal

Weight

12510 => 5 x 100 = 5

2 x 101 = 20

1 x 102 = 100

125

Base

Binary to Decimal

Hexadecimal

Decimal Octal

Binary

Technique

1. Multiply each bit by 2n, where n is the

“weight” of the bit

2. The weight is the position of the bit,

starting from 0 on the right

3. Add the results

1010112 => 1 x 20 = 1

1 x 21 = 2

0 x 22 = 0

1 x 23 = 8

0 x 24 = 0

1 x 25 = 32

4310

Bit “0”

Example

Sum – of – Weights Methods

Octal to Decimal

Hexadecimal

Decimal Octal

Binary

Technique

1. Multiply each bit by 8n

, where

n is the “weight” of the bit

2. The weight is the position of

the bit, starting from 0 on the

right

3. Add the results Example

7248 => 4 x 80 = 4

2 x 81 = 16

7 x 82 = 448

46810

Hexadecimal

Decimal Octal

Binary

Hexa – Decimal to Decimal Technique

1. Multiply each bit by 16n, where

n is the “weight” of the bit

2. The weight is the position of the

bit, starting from 0 on the right

3. Add the results

Sum – of – Weights Methods

Example

ABC16 => C x 160 = 12 x 1 = 12

B x 161 = 11 x 16 = 176

A x 162 = 10 x 256= 2560

274810

Decimal to Binary

Hexadecimal

Decimal Octal

Binary

Technique

1. Divide by two, keep track of the

remainder

2. First remainder is bit 0 (LSB, least-

significant bit)

3. Second remainder is bit 1

4. Etc.

Example

Sum – of – Weights Methods

Repeated Division –

by – 2 method

Hexadecimal

Decimal Octal

Binary

Example

Octal to Binary

Technique

1. Convert each octal digit to a 3-bit

equivalent binary representation

7058 = ?2 7 0 5

111 000 101 7058 = 1110001012

Hexa – decimal to Binary

Hexadecimal

Decimal Octal

Binary

Technique

1. Convert each hexadecimal digit to a

4-bit equivalent binary representation

10AF16 = ?2 1 0 A F

0001 0000 1010 1111 10AF16 = 00010000101011112

Example

Decimal to Octal

Hexadecimal

Decimal Octal

Binary

Technique

1. Divide by 8

2. Keep track of the remainder

Example

Repeated Division –

by – 8 method

Decimal to Hexa - decimal

Hexadecimal

Decimal Octal

Binary

Technique

1. Divide by 16

2. Keep track of the remainder

Example

Repeated Division –

by – 16 method

Hexadecimal

Decimal Octal

Binary

Binary to Octal

Technique

1. Group bits in threes, starting on

right

2. Convert to octal digits

10110101112 = ?8 1 011 010 111

1 3 2 7 10110101112 = 13278

Example

Binary to Hexa - Decimal

Hexadecimal

Decimal Octal

Binary

Technique

1. Group bits in fours, starting on

right

2. Convert to hexadecimal digits

10101110112 = ?16 10 1011 1011

2 B B 10101110112 = 2BB16

Example

Hexadecimal

Decimal Octal

Binary

Octal to Hexa - Decimal

Technique

Use binary as an intermediary

Example

Hexa – Decimal to Octal

Hexadecimal

Decimal Octal

Binary

Technique

Use binary as an intermediary

Example

PROBLEM SOLVING TECHNIQUES

1. ALGORITHM

2. FLOWCHART

3. PSEUDO CODE

ALGORITHM a step-by-step method for solving a problem or doing a task.

THREE CONSTRUCTS

Computer scientists have defined three constructs for a structured program or

algorithm. The idea is that a program must be made of a combination of only these three

constructs: sequence, decision (selection) and repetition. It has been proven there is no need for

any other constructs. Using only these constructs makes a program or an algorithm easy to

understand, debug or change.

Sequence

The first construct is called the sequence. An algorithm, and eventually a program, is

a sequence of instructions, which can be a simple instruction or either of the other two

constructs.

Decision

Some problems cannot be solved with only a sequence of simple instructions.

Sometimes we need to test a condition. If the result of testing is true, we follow a sequence of

instructions: if it is false, we follow a different sequence of instructions. This is called the

decision (selection) construct.

Repetition

In some problems, the same sequence of instructions must be repeated. We handle this with the

repetition or loop construct. Finding the largest integer among a set of integers can use a

construct of this kind.

Algorithm Examples

Example : 1 (Sequence)

To write a algorithm to find the area and circumference of the circle.

ALGORITHM:

Step-1 Start the program.

Step-2 Input the radius of the circle.

Step-3 Find the area and circumference of the circle using the

formula

Area=3.14*r*r

Circumference=2*3.14*r

Step-4 Print the area and the circumference of the circle

Step-5 Stop

Example : 2 (Decision)

To write a program to find the roots of the quadratic equation.

ALGORITHM:

Step-1 Start the program

Step-2 Enter the value of a, b, c

Step-3 Find the value of d by using the formula D=b*b-4*a*c

Step-4 If D is greater then or equal to zero then find the two roots as

root1=(-b+sqrt(d))/(2*a);

root2=(-b-sqrt(d))/(2*a);

Print the two roots

Step-5 If the D is not greater then or equal to zero then print the

statement the roots are imaginary.

Step-6 Stop

Example : 3 (Iterative)

To write a program to find the factorial of the given number

ALGORITHM:

Step-1 Start the program

Step-2 Enter a number

Step-3 Set a loop to find the factorial of the given

number using the formula Fact=Fact*I

Step-4 Print the factorial of the given number

Step-5 Stop

FLOWCHART

1. The flowchart is a diagram which visually presents the flow of data through

processing systems.

2. This means by seeing a flow chart one can know the operations performed and the

sequence of these operations in a system.

3. Algorithms are nothing but sequence of steps for solving problems. So a flow chart

can be used for representing an algorithm.

4. A flowchart, will describe the operations (and in what sequence) are required to solve

a given problem.

5. You can see a flow chart as a blueprint of a design you have made for solving a

problem.

For example, Suppose you are going for a picnic with your friends then you plan for the

activities you will do there. If you have a plan of activities then you know clearly when you will

do what activity. Similarly when you have a problem to solve using computer or in other word

you need to write a computer program for a problem then it will be good to draw a flowchart

prior to writing a computer program. Flowchart is drawn according to defined rules.

Flowchart Symbols

There are 6 basic symbols commonly used in flowcharting of assembly language

Programs: Terminal, Process, input/output, Decision, Connector and Predefined Process. This is

not a complete list of all the possible flowcharting symbols, it is the ones used most often in the

structure of Assembly language programming.

General Rules for flowcharting

1. All boxes of the flowchart are connected with Arrows. (Not lines)

2. Flowchart symbols have an entry point on the top of the symbol with no other entry points.

3. The Decision symbol has two exit points; these can be on the sides or the bottom and one side.

4. Generally a flowchart will flow from top to bottom. However, an upward flow can be shown as

long as it does not exceed 3 symbols.

5. Connectors are used to connect breaks in the flowchart. Examples are:

• From one page to another page.

• From the bottom of the page to the top of the same page.

• An upward flow of more then 3 symbols

6. Subroutines and Interrupt programs have their own and independent flowcharts.

7. All flow charts start with a Terminal or Predefined Process (for interrupt programs or

subroutines) symbol.

8. All flowcharts end with a terminal or a contentious loop.

Some examples of Flowcharts

Example 1: Find the area of a circle of radius r.

Example 2: Convert temperature Fahrenheit to Celsius.

Example 4: Algorithm for find the greater number between two numbers.

Example 5: Flowchart for the problem of printing even numbers between 9 and 100:

Advantages of using Flowcharts

1) Communication:

A Flowchart can be used as a better way of communication of the logic of a

system and steps involve in the solution, to all concerned particularly to the

client of system.

2) Effective analysis:

A flowchart of a problem can be used for effective analysis of the problem.

3) Documentation of Program/System:

Program flowcharts are a vital part of a good program documentation.

Program document is used for various purposes like knowing the

components in the program, complexity of the program etc.

4) Efficient Program Maintenance:

Once a program is developed and becomes operational it needs time to time

maintenance. With help of flowchart maintenance become easier.

5) Coding of the Program:

Any design of solution of a problem is finally converted into computer

program. Writing code referring the flowchart of the solution become easy.

Flowchart Disadvantages:

Hard to modify

Structured design elements not implemented

Special software required

Flowchart Advantages

Standardized

Visual

PSEUDO CODE

INTRODUCTION

1. Flowcharts were the first design tool to be widely used, but unfortunately they do not

reflect some of the concepts of structured programming very well.

2. Pseudo code, on the other hand, is a newer tool and has features that make it more

reflective of the structured concepts.

3. The drawback is that the narrative presentation is not as easy to understand and/or

follow.

Rules for Pseudo Code

1. Write only one statement per line

2. Capitalize initial keyword

3. Indent to show hierarchy

4. End multiline structures

5. Keep statements language independent

1. One Statement Per Line

Each statement in pseudocode should express just one action for the computer. If the task list is

properly drawn, then in most cases each task will correspond to one line of pseudocode.

Task List

Read name, hours worked, rate of pay

Perform calculations

gross = hours worked * rate of pay

Write name, hours worked, gross

Pseudocode

READ name, hoursWorked, payRate

gross = hoursWorked * payRate

WRITE name, hoursWorked, gross

2. Capitalize Initial Keyword

In the example below note the words: READ and WRITE. These are just a few of the keywords

to use, others include:

READ, WRITE, IF, ELSE, ENDIF, WHILE, ENDWHILE

Pseudocode

READ name, hoursWorked, payRate

gross = hoursWorked * payRate

WRITE name, hoursWorked, gross

3. Indent to Show Hierarchy

Each design structure uses a particular indentation pattern

Sequence:

Keep statements in sequence all starting in the same column

Selection:

Indent statements that fall inside selection structure, but not the keywords

that form the selection

Loop:

Indent statements that fall inside the loop but not keywords that form the loop

READ name, grossPay, taxes

IF taxes > 0

net = grossPay – taxes

ELSE

net = grossPay

ENDIF

WRITE name, net

4. End Multiline Structures

READ name, grossPay, taxes

IF taxes > 0

net = grossPay – taxes

ELSE

net = grossPay

ENDIF

WRITE name, net

See the IF/ELSE/ENDIF as constructed above, the ENDIF is in line with the IF.

The same applies for WHILE/ENDWHILE etc…

5. Language Independence

Resist the urge to write in whatever language you are most comfortable with, in the

long run you will save time. Remember you are describing a logic plan to develop a program,

you are not programming!

The Selection Structure

amount < 100

interestRate = .06 interestRate = .10

yes no

IF amount < 100

interestRate = .06

ELSE

Interest Rate = .10

ENDIF

Pseudocode

The Looping Structure

In flowcharting one of the more confusing things is to separate selection from looping.

This is because each structure use the diamond as their control symbol. In pseudo code we

avoid this by using specific keywords to designate looping

WHILE/ENDWHILE

REPEAT/UNTIL

WHILE / ENDWHILE

count = 0

WHILE count < 10

ADD 1 to count

WRITE count

ENDWHILE

WRITE “The End”

Start

count = 0

count

<10

add 1 to

count

write count

Write

“The End”

Stop

REPEAT / UNTIL

count = 0

REPEAT

ADD 1 to count

WRITE count

UNTIL count >= 10

WRITE “The End”

Start

count = 0

count <10

add 1 to count

write count

Write “The End”

Stop

Rules for Variable Names

1. Begin with lowercase letter

2. Contain no spaces

3. Additional words begin with capital

4. Unique names within code

5. Consistent use of names

Working with Fields

Calculations

+ add

- subtract

* multiply

/ divide

** or ^ exponentiation

( ) grouping

Selection

> greater than

< less than

= equal to

>= greater than or equal to

<= less than or equal to

<> not equal to

Advantages and Disadvantages

Pseudo code Advantages

Easily modified

Implements structured concepts

Done easily on Word Processor

Pseudo code Disadvantages:

Not visual

No accepted standard, varies from company to company