Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
124 views

Chapter 1 C Programming

This document introduces flowcharting and its importance for programming. It discusses the key components of a flowchart including symbols, types of flowcharts, and the steps for developing a flowchart. Specifically: - Flowcharts provide a graphical representation of the logic and steps of a computer program before coding. Standard symbols like boxes, arrows and terminals are used to visually depict program flow, inputs/outputs, processes and decisions. - There are two main types of flowcharts - program flowcharts focused on program logic for programmers, and system flowcharts showing broader system processes. - Common flowchart symbols include terminals for start and stop, input/output boxes, and process boxes for arithmetic operations. Flowcharts help plan

Uploaded by

Gajanan Kumbhar
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
124 views

Chapter 1 C Programming

This document introduces flowcharting and its importance for programming. It discusses the key components of a flowchart including symbols, types of flowcharts, and the steps for developing a flowchart. Specifically: - Flowcharts provide a graphical representation of the logic and steps of a computer program before coding. Standard symbols like boxes, arrows and terminals are used to visually depict program flow, inputs/outputs, processes and decisions. - There are two main types of flowcharts - program flowcharts focused on program logic for programmers, and system flowcharts showing broader system processes. - Common flowchart symbols include terminals for start and stop, input/output boxes, and process boxes for arithmetic operations. Flowcharts help plan

Uploaded by

Gajanan Kumbhar
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 27

Chapter 1 : Introduction to Flowcharting

C
Programming

1.1 Introduction
1.2 Flowcharts
1.3 Types of Flowcharts
1.3.1 Types of flowchart
1.3.2 System flowcharts
1.4 Flowchart Symbols
1.5 Advantages of Flowcharts
1.6 Developing Flowcharts
1.7 Techniques
1.7.1 Flowcharts for computations
1.7.2 Flowcharts for decision making
1.7.3 Flowcharts for loops
1.7.4 Predefined process
Chapter 1 : Introduction to Flowcharting
1.1 Introduction
C
Programming

 Computers are capable of handling various complex problems which are


tedious and routine in nature.
 In order that a computer solve a problem, a method for the solution and a
detailed procedure has to be prepared by the programmer.
 The problem solving Involves :
- Detailed study of the problem
- Problem redefinition
- Identification of input data, output requirements and conditions and
limitations
- Alternative methods of solution
- Selection of the most suitable method
- Preparation of a list of procedures and steps to obtain the solution
- Generating the output
Chapter 1 : Introduction to Flowcharting
1.1 Introduction
C
Programming

 The preparation of lists of procedures and steps to obtain the result introduces
the algorithmic approach to problem solving.
 The algorithm is a sequence of instructions designed in such a way that if the
instructions are executed in a specific sequence the desired results will be
obtained.
 The instructions should be precise and concise and the result should be
obtained after a finite execution of steps.
 This means that the algorithm should not repeat one or more instructions
infinitely.
 It should terminate at some point and result in the desired output.
 An algorithm should possess the following characteristics :
- 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.
Chapter 1 : Introduction to Flowcharting
1.2 Flowcharts
C
Programming

 Before you start coding a program it is necessary to plan the step by step
solution to the task your program will carry out.
 Such a plan can be symbolically developed using a diagram. This diagram is
then called a flowchart.
 Hence a flowchart is a symbolic representation of a solution to a given task.
 A flowchart can be developed for practically any job.
 Flowcharting is a tool that can help us to develop and represent graphically
program logic sequence.
 It also enables us to trace and detect any logical or other errors before the
programs are written.
Chapter 1 : Introduction to Flowcharting
1.3 Types of Flowcharts
C
Programming

Computer professionals use two types of flowcharts viz :


- Program Flowcharts.
- System Flowcharts
1.3.1 Program Flowcharts :
These are used by programmers. A program flowchart shows the program structure, logic
flow and operations performed. It also forms an important part of the documentation of the
system. It broadly includes the following:
- Program Structure.
- Program Logic.
- Data Inputs at various stages.
- Data Processing
- Computations and Calculations.
- Conditions on which decisions are based.
- Branching & Looping Sequences.
- Results.
- Various Outputs.
The emphasis in a program flowchart is on the logic.
Chapter 1 : Introduction to Flowcharting
1.3 Types of Flowcharts
C
Programming

1.3.2 System Flowcharts :


System flowcharts are used by system analyst to show various processes, sub
systems, outputs and operations on data in a system.

we will be discussing program flowcharts only.


Chapter 1 : Introduction to Flowcharting
1.4 Flowchart Symbols
C
Programming

 Normally, an algorithm is expressed as a flowchart and then the flowchart is converted into
a program with the programming language.
 Flowcharts are independent of the programming language being used. Hence one can fully
concentrate on the logic of the problem solving at this stage.
 A large number of programmers use flowcharts to assist them in the development of
computer programs.
 Once the flowchart is fully ready, the programmer then write it in the programming
language.
 At this stage he need not concentrate on the logic but can give more attention to coding
each instruction in the box of the flowchart in terms of the statements of the programming
language selected.
 A flowchart can thus be described as the picture of the logic to be included in the computer
program.
 It is always recommended for a beginner, to draw flowcharts prior to writing programs in the
selected language. Flowcharts are very helpful during the testing of the program as well as
incorporating further modifications.
Chapter 1 : Introduction to Flowcharting
1.4 Flowchart Symbols
C
Programming

 Flowcharting has many standard symbols.


 Flowcharts use boxes of different shapes to denote different types of instructions.
 The actual instruction is written in the box. These boxes are connected with solid
lines which have arrowheads to indicate the direction of flow of the flowchart.
 The boxes which are used in flowcharts are standardized to have specific
meanings.
 These flowchart symbols have been standardized by the American National
Standards Institute. (ANSI).
 While using the flowchart symbols following points have to be kept in mind:
- The shape of the symbol is important and must not be changed.
- The size can be changed as required.
- The symbol must be immediately recognizable.
- The details inside the symbol must be clearly readable.
- The flow lines, as far as possible, must not cross.
Chapter 1 : Introduction to Flowcharting
1.4 Flowchart Symbols
C
Programming

Terminal Symbol:
 Every flowchart has a unique starting point and an ending point.
 The flowchart begins at the start terminator and ends at the stop terminator.
 The Starting Point is indicated with the word START inside the terminator
symbol.
 The Ending Point is indicated with the word STOP inside the terminator symbol.
 There can be only one START and one STOP terminator in you entire flowchart.
 In case a program logic involves a pause, it is also indicated with the terminal
symbol.
Chapter 1 : Introduction to Flowcharting
1.4 Flowchart Symbols
C
Programming

Input/Output Symbol :
• This symbol is used to denote any input/output function in the program.
• Thus if there is any input to the program via an input device, like a keyboard,
tape, card reader etc. it will be indicated in the flowchart with the help of the
Input/Output symbol.
• Similarly, all output instructions, for output to devices like printers, plotters,
magnetic tapes, disk, monitors etc. are indicated in the Input/Output symbol.
Chapter 1 : Introduction to Flowcharting
1.4 Flowchart Symbols
C
Programming

Process Symbol :
o A process symbol is used to represent arithmetic and data movement
instructions in the flowchart.
o All arithmetic processes of addition, subtraction, multiplication and division are
indicated in the process symbol.
o The logical process of data movement form one memory location to another is
also represented in the process box.
o If there are more than one process instructions to be executed sequentially, they
can be placed in the same process box, one below the other in the sequence in
which they are to be executed.
Chapter 1 : Introduction to Flowcharting
1.4 Flowchart Symbols
C
Programming

Decision Symbol :
 The decision symbol is used in a flowchart to indicate the point where a decision
is to be made and branching done upon the result of the decision to one or more
alternative paths.
 The criteria for decision making is written in the decision box.
 All the possible paths should be accounted for.
 During execution, the appropriate path will be followed depending upon the result
of the decision.
Chapter 1 : Introduction to Flowcharting
1.4 Flowchart Symbols
C
Programming

Flowlines :
 Flowlines are solid lines with arrowheads which indicate the flow of operation.
 They show the exact sequence in which the instructions are to be executed.
 The normal flow of the flowchart is depicted from top to bottom and left to right.
Chapter 1 : Introduction to Flowcharting
1.4 Flowchart Symbols
C
Programming

Connectors :
 In situations, where the flowcharts becomes big, it may so happen that the
flowlines start crossing each other at many places causing confusion.
 This will also result in making the flowchart difficult to understand. Also, the
flowchart may not fit in a single page for big programs.
 Thus whenever the flowchart becomes complex and spreads over a number of
pages connectors are used.
 The connector represents entry from or exit to another part of the flowchart.
 A connector symbol is indicated by a circle and a letter or a digit is placed in the
circle.
 This letter or digit indicates a link. A pair of such identically labelled connectors
are used to indicate a continued flow in situations where flowcharts are complex
or spread over more than one page.
Chapter 1 : Introduction to Flowcharting
1.4 Flowchart Symbols
C
Programming

Connectors :
 Thus a connector indicates an exit from some section in the flowchart and an
entry into another section of the flowchart.
 If an arrow enters a flowchart but does not leave it, it means that it is an exit
point in the flowchart and program control is transferred to an identically labelled
connector which has an outlet.
 This connector will be connected to the further program flow from the point where
it has exited.
 Connectors do not represent any operation in the flowchart.
 Their use is only for the purpose of increased convenience and clarity.
Chapter 1 : Introduction to Flowcharting
1.4 Flowchart Symbols
C
Programming
Chapter 1 : Introduction to Flowcharting
1.5 Advantages of Flowcharts
C
Programming

1. A flowchart being a pictorial representation of a program, makes it easier for the programmer to
explain the logic of the program to others rather than a program
2. It shows the execution of logical steps without the syntax and language complexities of a program.
3. In real life programming situations a number of programmers are associated with the development
of a system and each programmer is assigned a specific task of the entire system.
4. Hence, each programmer can develop his own flowchart and later on all the flowcharts can be
combined for depicting the overall system.
5. Any problems related to linking of different modules can be detected at this stage itself and suitable
modifications carried out. Flowcharts can thus be used as working models in design of new software
systems.
6. Flowcharts provide a strong documentation in the overall documentation of the software system.
7. Once the flowchart is complete, it becomes very easy for programmers to write the program from the
starting point to the ending point. Since the flowchart is a detailed representation of the program
logic no step is missed during the actual program writing resulting in error free programs. Such
programs can also be developed faster.
8. A flowchart is very helpful in the process of debugging a program. The bugs can be detected and
corrected with the help of a flowchart in a systematic manner.-
Chapter 1 : Introduction to Flowcharting
1.6 Developing Flowcharts
C
Programming

In developing the flowcharts following points have to be considered:


- Defining the problem.
- Identify the various steps required to form a solution.
- Determine the required input and output parameters.
- Get expected input data values and output result.
- Determine the various computations and decisions involved.
With this background of flowcharts and flowchart symbols let us now draw some sample
flowcharts.

Example : To prepare a flowchart to add two numbers. (Fig. 2a.)


The steps are :
1. Start.
2. Get two numbers N1 and N2.
3. Add them.
4. Print the result.
5. Stop.
Chapter 1 : Introduction to Flowcharting
1.6 Developing Flowcharts
C
Programming

Example : To prepare a flowchart


to determine the greatest of two
numbers. Here we use the decision
symbol. We also combine the two
reads for numbers A and B in one
box.
Chapter 1 : Introduction to Flowcharting
1.7 Techniques
C
Programming

1.7.1 Flowcharts for Computations :


Computers are used to perform many calculations at high speed. When you develop
a program it also involves several calculations.
The general format of the flowcharting steps for computations is :
- Create memvars used in calculations and read operation.
- Get required data input using memvars.
- Perform the necessary calculations.
- Print the result.
Programming considerations while using computation techniques : Most
languages have provision for creating memvars. The exact syntax depends on the
language used. In most cases (but not all) your programs have to create and
initialize the memvars before you can use them.
Chapter 1 : Introduction to Flowcharting
1.7 Techniques
C
Programming

Example : Flowchart for a program that converts temperature in degrees Celsius


to degrees Fahrenheit. First let us write the steps involved in this computation
technique.
1. Start.
2. Create memvars F and C (for temperature in Fahrenheit and Celsius).
2. Read degrees Celsius into C.
3. Compute the degrees Fahrenheit into F.
4. Print result (F).
5. Stop.
Chapter 1 : Introduction to Flowcharting
1.7 Techniques
C
Programming
1.7.2 Flowcharts for decision making :
Computers are used extensively for performing various types of analysis. The decision symbol is used in
flowcharts to indicate it.
The general format of steps for flowcharting is as follows:
- Perform the test of the condition.
- If condition evaluates true branch to Yes steps.
- If condition evaluates false branch to No steps.
Programming Considerations :
Most programming languages have commands for performing test and branching. The exact commands
and syntax depends on the language used. Some of the conditional constructs available in programming
languages for implementing decision making in programs are as follows:
1. If
2. If - else - endif
3. If - elseif – endif
4. Do case - endcase.
5. Switch.
All languages do not support all of the above constructs. The operators available for implementing the
decision test are as follows:
- Relational Operators (which determine equality or inequality)
- Logical Operators, (useful for combining expressions)
Chapter 1 : Introduction to Flowcharting
1.7 Techniques
C
Programming
Chapter 1 : Introduction to Flowcharting
1.7 Techniques
C
Programming

1.7.3 Flowcharts for loops


 Looping refers to the repeated use of one or more steps. i.e. the statement or block of
statements within the loop are executed repeatedly.
 There are two types of loops. One is known as the fixed loop where the operations are
repeated a fixed number of times.
 In the other type which is known as the variable loop, the operations are repeated until a
specific condition is met. Here,the number of times the loop is repeated can vary.
 The loop process in general includes :
- Setting and initialising a counter
- execution of operations
- testing the completion of operations
- incrementing the counter
The test could either be to determine whether the loop has executed the specified number of
times, or whether a specified condition has been met.
Chapter 1 : Introduction to Flowcharting
1.7 Techniques
C
Programming

Programming considerations :
Most of the programming languages have a number of loop constructs for efficiently
handling repetitive statements in a program. These include :
1. do-while loop
2. while loop
3. for loop
4. for-next loop
Chapter 1 : Introduction to Flowcharting
1.7 Techniques
C
Programming

Example : To find the sum of first N numbers. This


example illustrates the use of a loop for a specific
number of times.
The steps are :
1. Start
2. Create memvars S , N, I
3. Read N
4. Set S (sum) to 0
5. Set counter (I) to 1.
6. S = S + I
7. Increment I by 1.
8. Check if I is less than or equal to N. If no, go to step
9. Print S
10. Stop
Chapter 1 : Introduction to Flowcharting
C
Programming

You might also like