0% found this document useful (0 votes)
71 views13 pages

FOC-unit 2

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
71 views13 pages

FOC-unit 2

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 13

UNIT - II

Data
Data is an array of facts that can be modified by computer into useful form for human.
Users deal with data in ways that let them know what kind of information they are managed.
Data is managed by the instructions in computer language. Examples of data are number, text,
currency and others.
Data Types
A data type is a classification of the type of data that a variable or object can hold in
computer programming. A data storage format that can contain a specific type or range of
values. When computer programs store data in variables, each variable must be assigned a
specific data type. Examples of data types include integers, floating point numbers, characters,
strings, and arrays.

Input , Processing of data


A computer is an electronic device that
1. accepts data,
2. processes data,
3. generates output, and
4. stores data.
The concept of generating output information from the input data is also referred to as input-
process-output concept.

Input: The computer accepts input data from the user via an input device like keyboard. The
input data can be characters, word, text, sound, images, document, etc.
§ Process: The computer processes the input data. For this, it performs some actions on the data
by using the instructions or program given by the user of the data. The action could be an
arithmetic or logic calculation, editing, modifying a document, etc. During processing, the data,
instructions and the output are stored temporarily in the computer’s main memory.
§ Output: The output is the result generated after the processing of data. The output may be in
the form of text, sound, image, document, etc. The computer may display the output on a
monitor, send output to the printer for printing, play the output, etc.
§ Storage: The input data, instructions and output are stored permanently in the secondary
storage devices like disk or tape. The stored data can be retrieved later, whenever needed.

Arithmetic operators:
Hierarchy of Operations
Operators, we may have some problems as to how exactly does it get executed. For
example, does the expression 2 * x - 3 * y correspond to (2x)-(3y) or to 2(x-3y)? Similarly, does
A / B * C correspond to A / (B * C) or to (A / B) * C? To answer these questions satisfactorily
one has to understand the ‘hierarchy’ of operations. The priority or precedence in which the
operations in an arithmetic statement are performed is called the hierarchy of operations. The
hierarchy of commonly used operators

PROGRAMMING DEVELOPMENT CYCLE


 Specify the problem
 Analyze the problem
 Design algorithm
 Implement algorithm
 Test and verify
 Maintain and update
 Documentation
1. Specify the problem To specify the inputs and outputs, processing requirements,
system constraints, and error handling methods
2. Analyze the problem To review program specifications, meeting with the analyst and
users and identifying program components. Precisely define the problem to be solved
and write program specifications
3. Design algorithm to solve problem Develop a detailed logic plan using a tool such as
pseudocode, flowcharts, object structure diagrams, or event diagrams to group the
program’s activities into modules.
4. Plan a method of solution or algorithm for each module; and test the solution
algorithms. 1. Implement the algorithm
2. Translate the design into an application using a programming language or
application development tool by creating the user interface and writing code
5. Test and verify the completed program Test the program, finding and correcting errors
(debugging) until it is error free.
There are three (3) types of error occur during this phase which are syntax error,
logic error and runtime error. Maintain and update the program Provide education and
support to end users. Correct any unanticipated errors that emerge and identify user-
requested modifications (enhancements). Documentation Review and if necessary, revise
internal documentation; formalize and complete end-user (external) documentation
 Input Process of entering data and programs in to the computer system
 Process Task of performing operations like arithmetic and logical
operations
 Output Process of producing results from the data for getting
useful information.
Algorithm
 A sequence of instructions to solve a problem, written in human language
 A step-by-step procedure to solve a given problem.
 Programmer writes the problem solving in the form of an algorithm before coding it into
computer language.
 An algorithm should always have a clear stopping point.
 Algorithms for making things will divided into sections; The parts/ components
/Ingredients (inputs) required to accomplish the task actions/steps/methods (processing)
to produce the required outcome(output).
 Algorithm can be developed using: Pseudo code (Similar to programming language)
Flow chart
Qualities of good algorithm
01.Inputs and outputs should be defined precisely.
02 Each steps in algorithm should be clear.
03 Algorithm should be most effective among many different ways to solve a problem.
04 An algorithm shouldn't have computer code.
05 Algorithm should be written in such a way that, it can be used in similar programming
languages.
Advantages of Algorithms:
1. It is a step-wise representation of a solution to a given problem, which makes it easy to
understand.
2. An algorithm uses a definite procedure.
3. It is not dependent on any programming language, so it is easy to understand for anyone even
without programming knowledge.
4. Every step in an algorithm has its own logical sequence so it is easy to debug.
5. By using algorithm, the problem is broken down into smaller pieces or steps hence, it is easier
for programmer to convert it into an actual program.
Disadvantages of Algorithms:
1. Algorithms is Time consuming.
2. Difficult to show Branching and Looping in Algorithms.
3. Big tasks are difficult to put in Algorithms.
Flow chart
Flowchart is a graphical representation of data, information and workflow using certain symbols
that are connected to flow lines to describe the instructions done in problem solving.
Using flowchart, programmer can test the solution for bugs and go on to code the solution to the
problem into a computer language for entry into the computer.
Flowchart is a tool developed in the computer industry, for showing the steps involved in a
process.

Rules for drawing a flowchart


1. The flowchart should be clear, neat and easy to follow.
2. The flowchart must have a logical start and finish.
3. Only one flow line should come out from a process symbol.
4. Only one flow line should enter a decision symbol. However, two or three flow lines may
leave the decision symbol.
5. Only one flow line is used with a terminal symbol.
6. Within standard symbols, write briefly and precisely.
7. Intersection of flow lines should be avoided.
Limitations of Using Flowcharts:
Although a flowchart is a very useful tool, there are a few limitations in using flowcharts which
are listed below:
Complex logic: Sometimes, the program logic is quite complicated. In that case, flowchart
becomes complex and clumsy.
Alterations and Modifications: If alterations are required the flowchart may require re-drawing
completely.

Advantages of flowchart:
1. Communication: - Flowcharts are better way of communicating the logic of a system to all
concerned.
2. Effective analysis: - With the help of flowchart, problem can be analyzed in more effective
way.
3. Proper documentation: - Program flowcharts serve as a good program documentation,
which is needed for various purposes.
4. Efficient Coding: - The flowcharts act as a guide or blueprint during the systems analysis and
program development phase.
5. Proper Debugging: - The flowchart helps in debugging process.
6. Efficient Program Maintenance: - The maintenance of operating program becomes easy
with the help of flowchart. It helps the programmer to put efforts more efficiently on that part.

Disadvantages of flow chart:


1. Complex logic: - Sometimes, the program logic is quite complicated. In that case, flowchart
becomes complex and clumsy.
2. Alterations and Modifications: - If alterations are required the flowchart may require re-
drawing completely.
3. Reproduction: - As the flowchart symbols cannot be typed, reproduction of flowchart
becomes a problem.
4. Cost: For large application the time and cost of flowchart drawing becomes costly.

Types of Flowcharts:
1.High-Level Flowchart:
A high-level (also called first-level or top-down) flowchart shows the major steps in a
process. It illustrates a "birds-eye view" of a process. It can also include the intermediate outputs
of each step (the product or service produced), and the sub-steps involved.
Such a flowchart offers a basic picture of the process and identifies the changes taking
place within the process. It is significantly useful for identifying appropriate team members
(those who are involved in the process) and for developing indicators for monitoring the process
because of its focus on intermediate outputs.
Most processes can be adequately portrayed in four or five boxes that represent the major
steps or activities of the process. In fact, it is a good idea to use only a few boxes, because doing
so forces one to consider the most important steps. Other steps are usually sub-steps of the more
important ones.
2. Detailed Flowchart
The detailed flowchart provides a detailed picture of a process by mapping all of the steps
and activities that occur in the process. This type of flowchart indicates the steps or activities of a
process and includes such things as decision points, waiting periods, tasks that frequently must
be redone (rework), and feedback loops. This type of flowchart is useful for examining areas of
the process in detail and for looking for problems or areas of inefficiency.

PSEUDO CODE:

 Pseudo code consists of short, readable and formally styled English languages used for
explain an algorithm.
 Steps in problem solving, written half in programming code and half in human language.
 Semi-formal, English-like description of logic of the algorithm. For example, some parts
uses C language code and some parts use Malay or English language.
 Helps programmer to “think out” the program. Advantage: Simple and easy to understand
 Criteria of good pseudo code
 Easy to understand, precise and clear
 Give correct solution to all cases
 Eventually end
 It does not include details like variable declaration, subroutines.
 It is easier to understand for the programmer or non programmer to understand the
general working of the program, because it is not based on any programming language.
 It gives us the sketch of the program before actual coding.
 It is not a machine readable
 Pseudo code can’t be compiled and executed.
 There is no standard syntax for pseudo code.

Guidelines for writing pseudo code:

 Write one statement per line


 Capitalize initial keyword
 Indent to hierarchy
 End multiline structure
 Keep statements language independent

Common keywords used in pseudocode

The following gives common keywords used in pseudocodes.


1. //: This keyword used to represent a comment.
2. BEGIN,END: Begin is the first statement and end is the last statement.
3. INPUT, GET, READ: The keyword is used to inputting data.
4. COMPUTE, CALCULATE: used for calculation of the result of the given expression. 5.
ADD, SUBTRACT, INITIALIZE used for addition, subtraction and initialization.

6. OUTPUT, PRINT, DISPLAY: It is used to display the output of the program.


7. IF, ELSE, ENDIF: used to make decision.
8. WHILE, ENDWHILE: used for iterative statements.
9. FOR, ENDFOR: Another iterative incremented/decremented tested automatically.
Syntax for if else:
IF (condition)THEN
statement
...
ELSE
statement
...
ENDIF
Example: Greates of two numbers
BEGIN
READ a,b
IF (a>b) THEN
DISPLAY a is greater
ELSE
DISPLAY b is greater
END IF
END

Syntax for For:


FOR( start-value to end-value) DO
statement
...
ENDFOR
Example: Print n natural numbers
BEGIN
GET n
INITIALIZE i=1
FOR (i<=n) DO
PRINT i
i=i+1
ENDFOR
END
Syntax for While:
WHILE (condition) DO
statement
...
ENDWHILE

Example: Print n natural numbers


BEGIN
GET n
INITIALIZE i=1
WHILE(i<=n) DO
PRINT i
i=i+1
ENDWHILE
END
Advantages:
1. Pseudo is independent of any language; it can be used by most programmers.
2. It is easy to translate pseudo code into a programming language.
3. It can be easily modified as compared to flowchart.
4. Converting a pseudo code to programming language is very easy as compared with
converting a flowchart to programming language.
Disadvantages:
1. It does not provide visual representation of the program’s logic.
2. There are no accepted standards for writing pseudo codes.
3. It cannot be compiled nor executed.
4. For a beginner, It is more difficult to follow the logic or write pseudo code as compared
to flowchart.

Example:
Addition of two numbers:
BEGIN
GET a,b
ADD c=a+b
PRINT c
END

Commenting lines
A comment is a note or explanation in the source code of a computer program. They are added
with the purpose of making the code easier for ourselves or other developers to understand in the
future, and they are generally ignored by compilers and interpreters.
Comments are typically formatted as either:
 Single-line comments, which start with a comment delimiter and continue until the end of
the line.
 Multi-line comments, which start with a start delimiter and end with an end delimiter and
can span multiple lines.
Some programming languages support only one type of comment. For example, Python
comments are single-line comments: They start with # and continue to the end of the line.
Other languages employ both single-line and multi-line comments. For example, C and C++
have single-line comments that start with // and multi-line comments between /* and */ that can
span multiple lines.
Types of Errors in Programming
1.Syntax Errors
 Syntax is the structure of statements in a program.
 A syntax error is an error in the syntax of a programming language, i.e., an error in
the source code of a program.
 If syntax errors are present in the program then the compilation of the program
fails and is terminated after showing the list of errors and the line number where
the errors have occurred.
 In some cases the line number may not exactly indicate the correct place of the
error.
 In some other cases, a single syntax error can result in a long list of errors.
 Correction of one or two errors in the program may remove the entire list of errors.
E.g. print(“Hello World)
2.Semantic Errors
 A semantic occurs due to the wrong use of the variables.
 The syntax of the programming language would be correct but the problem may be
caused due to the use of wrong variables, wrong operations or in a wrong order.
 Semantics errors are not traced by the compiler, as a result of which the program
executes but does not return the desired result.
 Semantic errors occur during the execution of the code.
 To track a semantic error, the programmer must check the output of the program.
e.g. Subscript out of range, forgetting to divide by 100 when calculating a
percentage amount.
3. Logical Errors
 As the name itself implies, these errors are related to the logic of the program.
 Logical error is a mistake in a program's source code.
 Logical errors are also not detected by compiler and cause incorrect results.
 To trace a logical error, the programmer must check the logic / algorithm of the program.
E.g. Infinite loop
a=10
while (a>0)
{
……
……
}
4.Compile Time and Runtime Errors
 An error that occurs during the compilation of a program is known as a compile
time error. E.g. Syntax Error
  An error that occurs during the execution of a program is known as runtime error.
E.g. Dynamic Semantic Errors, Logical Errors.

PROGRAM DESIGN - It is a framework or flow that shows the steps in problem solving.
some organizational tools to help us solve problems on the computer.
Modular Programming
 Decomposing large or complex programs into modules.
 Each module is a part of the larger program.
 A program becomes a set of modules.
 Each module can be easily understood, designed, implemented, and maintained by
different programmers, or teams of programmers.
A major advantage of the modular approach is that modules can be reused (shared) within and
between programs.
 Modules are sometimes called subroutines, procedures, or even functions.
 A module can be seen as a part of a program which performs a particular logical task.
Some characteristics and rules
1. Modular programs are hierarchical. That is to say, there are higher and the lower level
modules.
2. The top-level Control Module makes all major decisions regarding flow of control
through the program.
3. Modules have only one entry point and one exit point A module can only be invoked
(called) from a high level modules.
4. On exiting a module control is returned to the statement immediately following the invocation.

Pseudocode
Start Program
Start Control Module
Do Initialise
Do Program Body
Do Terminate
End control module.
Procedure Initialise
statements .....
End Procedure
Procedure Program Body
statements .....
End Procedure
Procedure Terminate
statements .....
End Procedure
etc.
etc.
End Program
Reason for using Modular programming
1. Modular programming allows breaking a large program in a number of smaller modules each
one of more manageable size.
2. Modular programming makes possible to link source code written in two separate languages.
A hybrid program written partly in assembly language and partly in higher level language
necessarily involves at least one module for each language involved.
3. Modular programming enables for creation, maintenance as well as reuse of a library of
generally used modules.
4. Modules are easier to grasp.
5. Different modules may be assigned to different programs.
6. Debugging and testing may be done in a more orderly fashion.
7. Document action can be easily understood.
8. Modifications can be localized to a module.
A modular program can be signified using hierarchical diagram:

The main advantages of modular programming are:


1. Easier, smaller modules to manage
2. Code repetition can be avoided by reusing modules.
We can split a program into subroutines or procedures. We need to CALL the procedure
whenever needed. A subroutine calls handovers the control to subroutine instructions and brings
the control back to calling program.

You might also like