FOC-unit 2
FOC-unit 2
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: 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
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.
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.
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: