FDT 801 Updated Note
FDT 801 Updated Note
MIC 701
[Computer Appreciation]
Materials used to develop this note were gathered from books, journals and web resources.
CONTENTS
PRINCIPLES AND PRACTICE OF COMPUTER PROGRAMMING TOOLS .......................... 4
TYPES OF PROGRAMMING METHODOLOGIES ................................................................ 4
PROCEDURAL PROGRAMMING ....................................................................................... 4
OBJECT ORIENTED PROGRAMMING .............................................................................. 7
FUNCTIONAL PROGRAMMING ........................................................................................ 8
ALGORITHM ............................................................................................................................. 9
WRITING ALGORITHM ..................................................................................................... 11
CHARACTERISTICS OF ALGORITHMS ......................................................................... 11
ADVANTAGES OF ALGORITHMS................................................................................... 12
FLOWCHART .......................................................................................................................... 12
TYPES OF FLOWCHARTS ................................................................................................. 13
FLOWCHART SYMBOLS .................................................................................................. 14
ADVANTAGES OF FLOWCHARTS .................................................................................. 16
DISADVANTAGES OF FLOWCHARTS ........................................................................... 17
DEVELOPING A FLOWCHART ........................................................................................ 17
DATA FLOW DIAGRAM ....................................................................................................... 19
KEY CONCEPTS OF DATA FLOW DIAGRAM ............................................................... 20
PSEUDOCODE ........................................................................................................................ 21
INPUT-PROCESS-OUTPUT (IPO) MODEL .......................................................................... 22
STEPS TO COMPLETE AN IPO MODEL .......................................................................... 24
DECISION TABLE .................................................................................................................. 24
SOFTWARE DEVELOPMENT PROCESS ................................................................................ 27
REQUIREMENT GATHERING .............................................................................................. 27
PROBLEM DEFINITION ........................................................................................................ 28
SYSTEM DESIGN ................................................................................................................... 28
IMPLEMENTATION ............................................................................................................... 29
DEBUGGING AND TESTING ................................................................................................ 29
DOCUMENTATION AND MAINTENANCE ........................................................................ 30
EFFICIENCY OF A PROGRAM CODE ..................................................................................... 31
COMPUTER PROGRAMMING ................................................................................................. 32
INTRODUCTION TO C PROGRAMMING LANGUAGE ........................................................ 35
HISTORY OF C LANGUAGE ................................................................................................ 35
WHERE IS C USED? KEY APPLICATIONS ........................................................................ 37
WHY LEARN 'C'? .................................................................................................................... 38
HOW 'C' WORKS? ................................................................................................................... 38
APPLICATIONS OF C PROGRAMMING ............................................................................. 39
INSTALLATION ON UNIX/LINUX ................................................................................... 40
INSTALLATION ON MAC OS ........................................................................................... 40
INSTALLATION ON WINDOWS....................................................................................... 40
C KEYWORDS ..................................................................................................................... 41
C IDENTIFIER...................................................................................................................... 41
RULES FOR NAMING IDENTIFIERS ............................................................................... 42
BASIC STRUCTURE OF A C PROGRAM ............................................................................ 42
DIFFERENCES BETWEEN A COMPLIER AND AN INTERPRETER ............................... 46
PRACTICE QUESTIONS ........................................................................................................ 46
PRINCIPLES AND PRACTICE OF COMPUTER PROGRAMMING
TOOLS
The principles and practice of computer programming is the process of writing, testing,
troubleshooting, debugging and maintaining of a computer program. Good programming practice
is mix of the art of computer programming discipline.
A Methodology is a system of methods with its orderly and integrated collection of various
methods, tools and notations. A computer program is a series of instructions written in the
language of the computer which specifies processing operations that the computer is to carry out
on data. It is a coded list of instructions that tell" a computer how to perform a set of calculations
or operations.
A program is a set of instructions written / given to solve a problem. Programs are developed to
solve real-life problems like inventory management, payroll processing, student admissions,
examination result processing, etc., they tend to be huge and complex.
Programming is an act of writing instructions (that is programs) to solve a problem. It is also the
process of producing a computer program, which involves the following activities; writing a
program, compiling the program, running the program, debugging the programs. The whole
process is repeated until the program is finished.
Programming Methodology is the approach to analyzing such complex problems by planning the
software development and controlling the development process
The aim of the course is to teach you the basic process to program efficiently. In this course we
will cover modular programming, requirement gathering, problem identification, flow chart,
decision table, and system analysis.
1. Procedural Programming
2. Object-Oriented Programming
3. Functional Programming
PROCEDURAL PROGRAMMING
This is a programming paradigm, derived from structured programming, based on the concept of
the procedure call. Procedures, also known as routines, subroutines, or functions, simply contain
a series of computational steps to be carried out. Any given procedure might be called at any
point during a program's execution, including by other procedures or itself.
A procedural programming language is a type of imperative language. That means that execution
is based on statements. The alternative programming paradigm is declarative programming, in
which execution is based on expressions. The first major procedural programming languages
appeared circa 1957–1964, including FORTRAN, ALGOL, COBOL, PL/I and BASIC. Pascal
and C were published circa 1970–1972.
Executing a series of statements or expressions can be very limiting in itself. There needs to be a
way to organize those statements/expressions. This led to the development of subroutines, which
appear in both imperative and declarative languages.
The declarative counterpart to the procedure is the function, which forms the basis
of functional programming. A pure function is like the mathematical concept of a function. You
call it with arguments and it returns a value. There are no side effects, such as database reads, file
system writes, or global state changes. Just a simple return value that is entirely based on its
input. Haskell and Scala are both functional languages.
Historically, procedural programming arose out of the concept of structured programming. The
idea is that programs can be written with only three things:
3. Iteration (loops)
You can also write an imperative program with nothing but GOTO statements for controlling the
flow of execution. Language developers built things like nested if statements, for loops, and
procedures. A procedure in basic term is a control structure.
In procedural programming, a problem is broken down into procedures, or blocks of code that
perform one task each. All procedures taken together form the whole program. It is suitable only
for small programs that have low level of complexity.
Example − For a calculator program that does addition, subtraction, multiplication, division,
square root and comparison, each of these operations can be developed as separate procedures. In
the main program each procedure would be invoked on the basis of user’s choice.
Local Variable: A local variable is a variable that is declared in the main structure of a
method and is limited to the local scope it is given. The local variable can only be used in
the method it is defined in, and if it were to be used outside the defined method, the code
will cease to work.
Global Variable: A global variable is a variable which is declared outside every other
function defined in the code. Due to this, global variables can be used in all functions,
unlike a local variable.
Modularity: Modularity is when two dissimilar systems have two different tasks at hand
but are grouped together to conclude a larger task first. Every group of systems then
would have its own tasks finished one after the other until all tasks are complete.
ADVANTAGES
Procedural Programming is excellent for general purpose programming
The coded simplicity along with ease of implementation of compilers and interpreters
A large variety of books and online course material available on tested algorithms,
making it easier to learn along the way
The source code is portable, therefore, it can be used to target a different CPU as well
The code can be reused in different parts of the program, without the need to copy it
The Procedural code is often not reusable, which may pose the need to recreate the code
if is needed to use in another application
The importance is given to the operation rather than the data, which might pose issues in
some data-sensitive cases
The data is exposed to the whole program, making it not so much security friendly
An object is an entity that possesses both state (or properties or attributes) and behaviour. Put
another way, an object encapsulates data and the functions that operate on that data. The data is
usually hidden from other objects so that the only way to affect the data is through the object’s
functions (or methods).
PRINCIPLES OF OOP
Object-oriented programming is based on the following principles:
Encapsulation- The implementation and state of each object are privately held inside a
defined boundary, or class. Other objects do not have access to this class or the authority
to make changes but are only able to call a list of public functions, or methods. This
characteristic of data hiding provides greater program security and avoids
unintended data corruption.
Abstraction- Objects only reveal internal mechanisms that are relevant for the use of
other objects, hiding any unnecessary implementation code. This concept helps
developers make changes and additions over time more easily.
Example − If we have to develop a payroll management system, we will have entities like
employees, salary structure, leave rules, etc. around which the solution must be built.
FUNCTIONAL PROGRAMMING
Here the problem, or the desired solution, is broken down into functional units. Each unit
performs its own task and is self-sufficient. These units are then stitched together to form the
complete solution.
Functional programming languages are specially designed to handle symbolic computation and
list processing applications. Functional programming is based on mathematical functions. Some
of the popular functional programming languages include: Lisp, Python, Erlang, Haskell,
Clojure, etc.
Pure Functional Languages − These types of functional languages support only the
functional paradigms. For example − Haskell.
Functional programming languages don’t support flow Controls like loop statements and
conditional statements like If-Else and Switch Statements. They directly use the functions
and functional calls.
Bugs-Free Code − Functional programming does not support state, so there are no side-
effect results and we can write error-free codes.
Efficient Parallel Programming − Functional programming languages have NO
Mutable state, so there are no state-change issues. One can program "Functions" to work
parallel as "instructions". Such codes support easy reusability and testability.
Efficiency − Functional programs consist of independent units that can run concurrently.
As a result, such programs are more efficient.
As a downside, functional programming requires a large memory space. As it does not have
state, you need to create new objects every time to perform actions.
Lisp is used for artificial intelligence applications like Machine learning, language
processing, Modeling of speech and vision, etc.
ALGORITHM
Look around you. Computers and networks are everywhere, enabling an intricate web of
complex human activities: education, commerce, entertainment, research, manufacturing, health
management, communication, even war. Of the two main technological underpinnings of this
amazing proliferation, one is the breathtaking pace with which advances in microelectronics and
chip design have been bringing us faster and faster hardware. The other is efficient algorithms
that are fuelling the computer revolution.
In mathematics, computer science, and related subjects, an algorithm is a finite sequence of steps
expressed for solving a problem. An algorithm can be defined as “a process that performs some
sequence of operations in order to solve a given problem”. Algorithms are used for calculation,
data processing, and many other fields.
In computing, algorithms are essential because they serve as the systematic procedures that
computers require. A good algorithm is like using the right tool in the workshop. It does the job
with the right amount of effort. Using the wrong algorithm or one that is not clearly defined is
like trying to cut a piece of plywood with a pair of scissors: although the job may get done, you
have to wonder how effective you were in completing it. Let us follow an example to help us
understand the concept of algorithm in a better way.
Let’s say that you have a friend arriving at the railway station, and your friend needs to get from
the railway station to your house. Here are three different ways (algorithms) that you might give
your friend for getting to your home.
All these three algorithms accomplish the same goal, but each algorithm does it in a different
way. Each algorithm also has a different cost and a different travel time. Taking a taxi/auto-
rickshaw, for example, is the fastest way, but also the most expensive. Taking the bus is
definitely less expensive, but a whole lot slower. You choose the algorithm based on the
circumstances.
In computer programming, there are often many different algorithms to accomplish any given
task. Each algorithm has advantages and disadvantages in different situations. Sorting is one
place where a lot of research has been done, because computers spend a lot of time sorting lists.
Three reasons for using algorithms are efficiency, abstraction and reusability.
Efficiency: Certain types of problems, like sorting, occur often in computing. Efficient
algorithms must be used to solve such problems considering the time and cost factor involved in
each algorithm.
Reusability: Algorithms are often reusable in many different situations. Since many well-known
algorithms are the generalizations of more complicated ones, and since many complicated
problems can be distilled into simpler ones, an efficient means of solving certain simpler
problems potentially lets us solve many complicated problems.
WRITING ALGORITHM
Algorithms can be expressed in many different notations, including natural languages,
pseudocode, flowcharts and programming languages. Algorithms can be expressed in many
different notations, including natural languages, pseudocode, flowcharts and programming
languages. Natural language expressions of algorithms tend to be verbose and ambiguous and are
rarely used for complex or technical algorithms. Pseudocode and flowcharts are structured ways
to express algorithms that avoid many ambiguities common in natural language statements,
while remaining independent of a particular implementation language. Programming languages
are primarily intended for expressing algorithms in a form that can be executed by a computer,
but are often used to define or document algorithms.
Consider an example for finding the largest number in an unsorted list of numbers.
The solution for this problem requires looking at every number in the list, but only once at each.
largest = L0
return largest
CHARACTERISTICS OF ALGORITHMS
Input: it may accept zero or more inputs.
Output: it should produce at least one output (result).
Definiteness: each instruction must be clear, well-defined and precise. There
should be no ambiguity.
Finiteness: it should be a sequence of finite instructions. This means that
instructions must end after a fixed time not infinity.
Effectiveness: this means that operations must be simple and carried out in a
finite time at one or more levels of complexity (time and space complexity – BigOh
notation etc). **Time complexity indicates how fast an algorithm runs and
space complexity refers to the amount of memory units required by the algorithm
in addition to the space needed for its input and output.
ADVANTAGES OF ALGORITHMS
The use of algorithms provides a number of benefits. One of these benefits is in the development
of the procedure itself, which involves identification of the processes, major decision points, and
variables necessary to solve the problem. Developing an algorithm allows and even forces
examination of the solution process in a rational manner. Identification of the processes and
decision points reduces the task into a series of smaller steps of more manageable size. Problems
that would be difficult or impossible to solve in entirety can be approached as a series of small,
solvable sub-problems.
By using an algorithm, decision making becomes a more rational process. In addition to making
the process more rational, use of algorithm will make the process more efficient and more
consistent. Efficiency is an inherent result of the analysis and specification process. Consistency
comes from both the use of the same specified process and increased skill in applying the
process. An algorithm serves as a mnemonic device and helps ensure that variables or parts of
the problem are not ignored. Presenting the solution process as an algorithm allows more precise
communication. Finally, separation of the procedure steps facilitates division of labour and
development of expertise.
A final benefit of the use of an algorithm comes from the improvement it makes possible. If the
problem solver does not know what was done, he or she will not know what was done wrong. As
time goes by and results are compared with goals, the existence of a specified solution process
allows identification of weaknesses and errors in the process. Reduction of a task to a specified
set of steps or algorithm is an important part of analysis, control and evaluation.
FLOWCHART
Flowcharts was introduced in 1921 by Frank Gilberth, and they were called “Process Flow
Charts” at the beginning. It is a pictorial representation depicting the flow of steps in a program,
people in an organization, or pages in a presentation.
Flowcharting is the process of illustrating workflows and data flows in a system through symbols
and diagrams. It is an important tool to assist the system analyst in identifying a solution to the
problem. It depicts the components of the system visually. It can also be defined as a
diagrammatic representation of sequence of logical steps of a program. Flowcharts use simple
geometric shapes to depict processes and arrows to show relationships and process/data flow.
Flowchart contains elements. These elements are represented by simple icons (circles, rectangles,
diamonds, or other shapes), with lines and arrows representing connections between events and
the direction or order in which they occur. A flowchart indicates sequences and decision points
as well as starting and stopping points. Since it is easier to grasp relationships in a visual form
than in a verbal description, flowcharts can prevent the omission of steps in a process.
Flowcharts are particularly useful for instructional designers who are novice or occasional
programmers.
TYPES OF FLOWCHARTS
There are generally four types of flowcharts.
1. Document Flowchart
2. Data Flowchart
3. Program Flowchart
4. System Flowchart
PROGRAM FLOWCHART
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:
o Program Structure.
o Program Logic.
o Data Inputs at various stages.
o Data Processing.
o Computations and Calculations.
o Conditions on which decisions are based.
o Branching & Looping Sequences.
o Results.
o Various Outputs.
SYSTEM FLOWCHART
System flowcharts are used by system analyst to show various processes, sub systems, outputs
and operations on data in a system.
FLOWCHART SYMBOLS
While boxes, circles, diamonds and other symbols are not required to construct a flowchart, they
convey information about the events in the process clearly and efficiently. Below are the
symbols used for flowcharting.
TERMINAL SYMBOLS
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 your flowchart.
In case a program logic involves a pause, it is also indicated with the terminal symbol.
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.
PROCESS SYMBOL
A process symbol is used to represent arithmetic and data movement instructions in the
flowchart. All arithmetic processes of addition, subtraction, multiplication and division are
indicated in the process symbol. The logical process of data movement form one memory
location to another is also represented in the process box. 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.
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.
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.
CONNECTORS
In situations, where the flowcharts become 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. 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.
Example Flowcharts
o Developing the program logic and sequence. A macro flowchart can first be designed to
depict the main line of logic of the software. This model can then be broken down into
smaller detailed parts for further study and analysis.
o 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.
o It shows the execution of logical steps without the syntax and language complexities of a
program.
o 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. Hence, each programmer can develop his own flowchart and later on all the
flowcharts can be combined for depicting the overall system. 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.
o Flowcharts provide a strong documentation in the overall documentation of the software
system.
o 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.
o 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.
o A flowchart proves to be a very effective tool for testing. Different sets of data are fed as
input to program for the purpose.
o They act as blueprints for actual program coding.
o Flowcharts are important for program documentation.
DISADVANTAGES OF FLOWCHARTS
o Complex logic cannot be depicted using flowcharts.
o In case of any change in logic or data/work flow, flowchart has to be redrawn completely.
DEVELOPING A FLOWCHART
In developing the flowcharts following points have to be considered:
With this background of flowcharts and flowchart symbols let us now draw some sample
flowcharts. First, we shall write the steps to prepare the flowchart for a particular task and then
draw the flowchart.
Solution:
1. Start.
2. Get two numbers N1 and N2.
3. Add them.
4. Print the result.
5. Stop.
Figure 2
Hint: Here we use the decision symbol. We also combine the two reads for numbers A and B in
one box.
Solution:
1. Start
2. Get two number A and B.
3. If A > B then print A else print B.
4. Stop.
Figure 3
Note that in the first example, we have used two separate input/output boxes to read the numbers
N1 and N2. In the second example, both the numbers a and b are read in the same box. Thus, if
more than one instructions of the same kind follow one another then they can be combined in the
same box.
DFD is a structured analysis and design method. It is traditional visual representation of the
information flows within a system. DFD is widely used for software analysis and design. A neat
and clear DFD can depict a good amount of the system requirements graphically.
The Data Flow Diagram (DFD) depicts the logic models and expresses data transformation in a
system. It includes a mechanism to model the data flow and supports decomposition to illustrate
details of the data flows and functions. A Data Flow Diagram cannot present information on
operation sequence. Therefore, it is not a process or procedure modeling method.
EXTERNAL ENTITY
An external entity can represent a human, system or subsystem. It is where certain data comes
from or goes to. It is external to the system we study, in terms of the business process. For this
reason, people used to draw external entities on the edge of a diagram.
PROCESS
A process is a business activity or function where the manipulation and transformation of data
takes place. A process can be decomposed to finer level of details, for representing how data is
being processed within the process.
DATA STORE
A data store represents the storage of persistent data required and/or produced by the process.
Here are some examples of data stores: membership forms, database table, etc.
DATA FLOW
A data flow represents the flow of information, with its direction represented by an arrow head
that shows at the end(s) of flow connector.
PSEUDOCODE
After the system is designed, it is handed over to the project manager for implementation, i.e.
coding. The actual coding of a program is done in a programming language, which can be
understood only by programmers who are trained in that language. However, before the actual
coding occurs, the basic operating principles, work flows and data flows of the program are
written using a notation similar to the programming language to be used. Such a notation is
called pseudocode.
It is neither an algorithm nor a program. It also consists of English-like
statements, which perform specific operations with no form of graphical representation. It is not
executable – cannot be compiled.
Here is an example of a pseudocode. The programmer just needs to translate each statement into
the appropriate programming language syntax to get the program code.
An input device sends information to a computer system for processing, and an output
device reproduces or displays the results of that processing. Depending on the interaction, a
device can be both, referred to as an input/output or I/O device.
For example, as you can see in the top half of the image, a keyboard sends electrical signals,
which are received by the computer (input). Those signals are then interpreted by the computer
and displayed on the monitor as text (output). In the lower half of the image, the computer sends
data to a printer, which will print the data onto a piece of paper (output).
An input device can send data to another device, but it cannot receive data from another device.
Examples of an input device include a computer keyboard and mouse, which can send data
(input) to the computer, but they cannot receive or reproduce information (output) from the
computer.
Process is the most important element of the system. The process accepts the inputs into the
system and performs some type of operation on it which transforms it into some other state. In
the simplest of terms, the process is at the heart of any system. It involves storage retrieval and
modification of data, which is accomplished by hardware and software. The Programming
process consists of several steps, which include design, creation, testing and debugging activities.
In designing and creating a program, the following steps are recommended and show the
importance of planning. A good program always begins with planning.
Output is information that a program sends to the outside world. It can be alpha numeric words
or graphics displayed on a screen or a report sent to the printer or data stored in a file or
information sent to any device connected to the computer. It is the result of processing the input.
An output device can receive data from another device, but it cannot send data to another device.
Examples of an output device include a computer monitor, projector, and speakers, which can
receive data (output) from the computer, but they cannot send information (input) to the
computer.
An input/output device can send data to another device and also receive data from another
device. Examples of an input/output include a computer CD-RW drive and USB flash drive,
which can send data (input) to a computer and also receive data (output) from a computer.
Simple IPO model
This process or steps are dynamic which means you may need to continually return to
previous steps.
Examples:
Solution:
Input Process Output
Get result of test 1 Calculate final score
Get result of test 2 Final score =
Get result of final exam {(test 1 + test 2) * 15/100} +
Get result of project 1 (final exam score * 30/100) + Final score.
Get result of project 2 {(project 1 + project 2 +
Get result of project 3 project 3 + project 4) *
Get result of project 4 40/100}
DECISION TABLE
A decision table is used to represent conditional logic by creating a list of tasks depicting
business level rules. Decision tables can be used when there is a consistent number of conditions
that must be evaluated and assigned a specific set of actions to be used when the conditions are
finally met.
Decision tables are a good way to deal with inputs (sets of data). They provide a
systematic way of testing the program and exploring the effects of combination of different
inputs. It is used when there are multiple actions that should be taken under certain sets of
condition and many possible combinations of conditions to test. In practice, when the
specification has many IFTHEN-ELSE type conditions. Decision tables are made up of
conditions, actions and rules. The number of rules is calculated by 2n where n = number of
conditions.
Example:
Let’s take an example scenario for an ATM where a decision table would be of use. A customer
requests a cash withdrawal. One of the business rules for the ATM is that the ATM machine pays
out the amount if the customer has sufficient funds in their account or if the customer has the
credit granted. Already, this simple example of a business rule is quite complicated to describe in
text. A decision table makes the same requirements clearer to understand:
Withdrawal amount<=Balance T F T F
Credit granted F T T F
Actions
WithdrawalGranted T T T F
Example:
If you are a new customer and you want to open a credit card account then there are three
conditions first you will get a 15% discount on all your purchases today, second if you are an
existing customer and you hold a loyalty card, you get a 10% discount and third if you have a
coupon, you can get 20% off today (but it can’t be used with the ‘new customer’ discount).
Discount amounts are added, if applicable.
SOFTWARE DEVELOPMENT PROCESS
A typical software development process follows the software development life cycle (SDLC). It
is classified into the following phases.
Requirement gathering
Problem definition
System design
Implementation
Testing
Documentation
Maintenance
REQUIREMENT GATHERING
Usually, clients or users are not able to clearly define their problems or requirements. They have
a vague idea of what they want. So, system developers need to gather client requirements to
understand the problem that needs to be resolved, or what needs to be delivered. Detailed
understanding of the problem is possible only by first understanding the business area for which
the solution is being developed. Some key questions that help in understanding a business
include −
Interviews
Questionnaires
Increased costs
Delayed delivery
Due to the depth of information required, requirement gathering is also known as detailed
investigation.
PROBLEM DEFINITION
After gathering requirements and analyzing them, problem statement must be stated clearly.
Problem definition should unambiguously state what problem or problems need to be solved.
Having a clear problem statement is necessary to −
Often, coding is supposed to be the most essential part of any software development process.
However, coding is just a part of the process and may actually take the minimum amount of time
if the system is designed correctly. Before the system can be designed, a solution must be
identified for the problem at hand.
The first thing to be noted about designing a system is that initially the system analyst may come
up with more than one solution. But the final solution or the product can be only one. In-depth
analysis of data gathered during the requirement gathering phase can help in coming to a unique
solution. Correctly defining the problem is also crucial for getting to the solution.
When faced with the problem of multiple solutions, analysts go for visual aids like flowcharts,
data flow diagrams, entity relationship diagrams, etc. to understand each solution in depth.
SYSTEM DESIGN
It is a process of planning a new business system or replacing an existing system by
defining its components or modules to satisfy the specific requirements. Before planning,
you need to understand the old system thoroughly and determine how computers can best
be used in order to operate efficiently.
Systems
Processes
Technology
IMPLEMENTATION
After the analysis phase, the computer needs a way to process all the data in a language it
understands. The computer does not know how to process algorithms or flowcharts but executes
the program. The process of writing a program is called coding. Programs are written using high
level programming languages and fed to the computer.
The CPU is where all the processing takes place. The written program is executed (or ran) in the
CPU. Three steps are involved in this phase:
Once the programmer is done writing the program, it is ready for execution. Instructions stored
in the RAM (Random Access Memory) are fetched one by one by ALU (Arithmetic Logic Unit)
to perform the corresponding operations, then finally the processed data (results) are transferred
to the output devices.
The process of translating high level language (source code) program into machine language
requires an intermediary program called the translator. The complier and interpreter are two
translator programs used. The source code or program is translated (by a complier or interpreter)
into an object program.
The process of executing the program to check for correctness of the output (result) of the
problem is called testing. Different sets of data are used to test the program. A technique used in
software testing called decision table
Compiler speed
Operating system
The efficiency of a programming language can be improved by performing the following tasks −
By making the use of error & exception handling at all layers of program.
By developing the program code that's compliant with the design logic and flow.
An efficient programming code can reduce resource consumption and completion time as much
as possible with minimum risk to the operating environment.
COMPUTER PROGRAMMING
A computer program is a sequence of instructions written using a Computer Programming
Language to perform a specified task by the computer.
The two important terms that we have used in the above definition are:
o Sequence of instructions
o Computer Programming Language
There are hundreds of programming languages, which can be used to write computer programs
and following are a few of them:
o Java
o C
o C++
o Python
o PHP
o Perl
o Ruby
Today computer programs are being used in almost every field, household, agriculture, medical,
entertainment, defense, communication, etc. Listed below are a few applications of computer
programs:
o MS Word, MS Excel, Adobe Photoshop, Internet Explorer, Chrome, etc., are examples of
computer programs.
o Computer programs are being used to develop graphics and special effects in movie
making.
o Computer programs are being used to perform Ultrasounds, X-Rays, and other medical
examinations.
o Computer programs are being used in our mobile phones for SMS, Chat, and voice
communication.
You will need the following setup to start with programming using any programming language.
A text editor is a software that is used to write computer programs. Your Windows machine must
have a Notepad, which can be used to type programs.
Now let us try to get a little more detail on how the computer understands a program written by
you using a programming language. Actually, the computer cannot understand your program
directly given in the text format, so we need to convert this program in a binary format, which
can be understood by the computer. The conversion from text program to binary file is done by
another software called Compiler and this process of conversion from text formatted program to
binary format file is called program compilation. Finally, you can execute binary file to perform
the programmed task.
So, if you are going to write your program in any such language, which needs compilation like
C, C++, Java and Pascal, etc., then you will need to install their compilers before you start
programming.
There are other programming languages such as Python, PHP, and Perl, which do not need any
compilation into binary format, rather an interpreter can be used to read such programs line by
line and execute them directly without any further conversion.
So, if you are going to write your programs in PHP, Python, Perl, Ruby, etc., then you will need
to install their interpreters before you start programming
INTRODUCTION TO C PROGRAMMING LANGUAGE
C is a general-purpose programming language that is extremely popular, simple and flexible. It is
machine-independent, procedural computer programming language supporting structured
programming and is used extensively in various applications.
C was the basics language to write everything from operating systems (Windows and many
others) to complex programs like the Oracle database, Git, Python interpreter and more.
It is said that 'C' is a god's programming language. One can say, C is a base for the programming.
If you know 'C,' you can easily grasp the knowledge of the other programming languages that
uses the concept of 'C'.
If you are new to programming, C is a good choice to start your programming journey.
HISTORY OF C LANGUAGE
The base or father of programming languages is 'ALGOL.' It was first introduced in 1960.
'ALGOL' was used on a large basis in European countries. 'ALGOL' introduced the concept of
structured programming to the developer community. In 1967, a new computer programming
language was announced called as 'BCPL' which stands for Basic Combined Programming
Language. BCPL was designed and developed by Martin Richards, especially for writing system
software. This was the era of programming languages. Just after three years, in 1970 a new
programming language called 'B' was introduced by Ken Thompson that contained multiple
features of 'BCPL.' This programming language was created using UNIX operating system at
AT&T and Bell Laboratories. Both the 'BCPL' and 'B' were system programming languages.
In 1972, a great computer scientist Dennis Ritchie created a new programming language called
'C' at the Bell Laboratories. It was created from 'ALGOL', 'BCPL' and 'B' programming
languages. 'C' programming language contains all the features of these languages and many more
additional concepts that make it unique from other languages.
'C' is a powerful programming language which is strongly associated with the UNIX operating
system. Even most of the UNIX operating system is coded in 'C'. Initially 'C' programming was
limited to the UNIX operating system, but as it started spreading around the world, it became
commercial, and many compilers were released for cross-platform systems. Today 'C' runs under
a variety of operating systems and hardware platforms. As it started evolving many different
versions of the language were released. At times it became difficult for the developers to keep up
with the latest version as the systems were running under the older versions. To assure that 'C'
language will remain standard, American National Standards Institute (ANSI) defined a
commercial standard for 'C' language in 1989. Later, it was approved by the International
Standards Organization (ISO) in 1990. 'C' programming language is also called as 'ANSI C'.
Figure 1: History of C
Languages such as C++/Java are developed from 'C'. These languages are widely used in various
technologies. Thus, 'C' forms a base for many other languages that are currently in use.
4. Most of the applications by Adobe are developed using 'C' programming language.
5. It is used for developing browsers and their extensions. Google's Chromium is built using
'C' programming language.
6. It is used to develop databases. MySQL is the most popular database software which is
built using 'C'.
'C' is a structured programming language in which program is divided into various modules.
Each module can be written separately and together it forms a single 'C' program. This structure
makes it easy for testing, maintaining and debugging processes.
'C' contains 32 keywords, various data types and a set of powerful built-in functions that make
programming very efficient.
Another feature of 'C' programming is that it can extend itself. A 'C' program contains various
functions which are part of a library. We can add our features and functions to the library. We
can access and use these functions anytime we want in our program. This feature makes it simple
while working with complex programming.
Various compilers are available in the market that can be used for executing programs written in
this language.
It is a highly portable language which means programs written in 'C' language can run on other
machines. This feature is essential if we wish to use or execute the code on another computer.
Clang compiler
Turbo C
APPLICATIONS OF C PROGRAMMING
C was initially used for system development work, particularly the programs that make-up the
operating system. C was adopted as a system development language because it produces code
that runs nearly as fast as the code written in assembly language. Some examples of the use of C
are -
Operating Systems
Language Compilers
Assemblers
Text Editors
Print Spoolers
Network Drivers
Modern Programs
Databases
Language Interpreters
Utilities
INSTALLATION ON UNIX/LINUX
If you are using Linux or UNIX, then check whether GCC is installed on your system by
entering the following command from the command line –
$ gcc -v
If you have GNU compiler installed on your machine, then it should print a message as follows –
If GCC is not installed, then you will have to install it yourself using the detailed instructions
available at https://gcc.gnu.org/install/
This tutorial has been written based on Linux and all the given examples have been compiled on
the Cent OS flavor of the Linux system.
INSTALLATION ON MAC OS
If you use Mac OS X, the easiest way to obtain GCC is to download the Xcode development
environment from Apple's web site and follow the simple installation instructions. Once you
have Xcode setup, you will be able to use GNU compiler for C/C++.
INSTALLATION ON WINDOWS
To install GCC on Windows, you need to install MinGW. To install MinGW, go to the MinGW
homepage, www.mingw.org, and follow the link to the MinGW download page. Download the
latest version of the MinGW installation program, which should be named MinGW-
<version>.exe.
While installing Min GW, at a minimum, you must install gcc-core, gcc-g++, binutils, and the
MinGW runtime, but you may wish to install more.
Add the bin subdirectory of your MinGW installation to your PATH environment variable, so
that you can specify these tools on the command line by their simple names.
After the installation is complete, you will be able to run gcc, g++, ar, ranlib, dlltool, and several
other GNU tools from the Windows command line.
C KEYWORDS
These are reserved words that have standard pre-defined meanings. They are
only used for special actions or intended purposes. They cannot be used as a programmer's
defined identifier. All keywords are written in lower case letters. Examples of keywords
used in C: int , void, if , else, return, for, do, long, goto, char, while etc.
int money;
Here, int is a keyword that indicates money is a variable of type int (integer).
As C is a case sensitive language, all keywords must be written in lowercase. Here is a list of all
keywords allowed in ANSI C.
do if static while
C IDENTIFIER
Identifier refers to name given to entities such as variables, functions, structures etc.
Identifiers must be unique. They are created to give a unique name to an entity to identify it
during the execution of the program. For example:
1. int money;
2. double accountBalance;
Also remember, identifier names must be different from keywords. You cannot use int as an
identifier because int is a keyword.
RULES FOR NAMING IDENTIFIERS
1. A valid identifier can have letters (both uppercase and lowercase letters), digits and
underscores.
4. There is no rule on how long an identifier can be. However, you may run into problems
in some compilers if the identifier is longer than 31 characters.
You can choose any name as an identifier if you follow the above rule, however, give
meaningful names to identifiers that make sense.
1. Preprocessor statements:
2. Main ():
3. A pair of curly braces {}:
4. Declarations:
5. Statements:
6. User defined functions:
int main() {
/* my first program in C */
printf("Hello, World! \n");
return 0;
}
Note: Every program statements must end with a semi colon (;). All programming statements
must lie within curly braces. Comment statements doesn’t compile by the computer.
In C, #include is a preprocessor directive that tells the C preprocessor to look for a file and place
the file in the location where #include indicates. The preprocessor includes the header file such
as stdio.h, conio.h, string.h etc. Other examples of preprocessor directives are:
Header Files
These files are placed at the header portion of your program before main(). The standard header
files in C have the .h extension. The header files are used to provide the necessary information in
support of the various library functions. Table below shows some header files and the library
function they are declared for:
Angular <> braces: In C, the angular bracket asks the C preprocessor to look for a header file in
directory other than the current one. If we want to let the C preprocessor look into current
directory first for header file before it starts to work, we can use double quotes to surround the
name of the header file. Normally, the header file are saved in a sub directory called include.
Main ( ) function: Every C program must have one and only one main functions. The main
function can be put anywhere but the execution of a program starts with main function. The main
function starts and end with curly braces {}.
Declarations: this is a part of the program where all variables, arrays, functions etc used in the C
program are declared and they may be initialized with their basic data types.
Statements: they are instructions given to the computer to perform specific operations. They
may be I/O statements, arithmetic or control statements.
User defined functions: there are subprograms that contain a set of instructions to specific tasks
for the user. They are written by the user of a program in a context where the usual assumption is
built in the program or environment. They may be written before or after the main ( ) function.
Printf functions and new line character: The printf function is used to print the character
string. The new line character which is usually sufficient at the end of the message, tells the
system to move the cursor to the beginning of next line.
Return statements: all function in C can return value. The main function itself returns an
integer value. So, return 0 indicates that 0 is returned from main function and the program is
terminated normally. We can return values other than 0 to tell the system that there is an error.
Compiling a C program means translating it into machine language. The program to be compiled
must be typed in using an editor. An editor is a program that allows the programmer to type in
the program and modify it. C compilers are available with or without editors.The environment
where you find the compiler, the editor, debugging tools, linking facilities, tracing and testing
tools is called Integrated Development Environment (IDE).
Format Specifiers: they are character strings with the percent sign (%) followed by a character.
They specify the type of data that is being processed. They are also refer to a conversion
specifiers. When a data is being output or input, it must be specified with the identifier (variable)
and their format specifier. Some examples of format specifiers are:
Escape Sequence: these are special characters denoted by a backslash (\) and a character after it.
It is called escape sequence because it causes an escape from the normal way character are being
represented or interpreted. Some examples of escape sequence are:
1. Unary operators: they act upon only one operand. Examples are Logical NOT operator
and bitwise complementation.
2. Binary operators: they act upon two or more operands and can be classified into four
categories; Arithmetic, logical relational and bitwise operators.
Example: X x Y = (X * Y)/Z
Z
(2x + 1) (3y + 2) = [(2 * x) + 1]
3. Ternary operators
Precedence and associativity of all C operators.: All C operators have some form of
precedence (that is, an order or rank). C specifies the precedence of operators in the evaluation of
an expression with the highest precedence first. The associativity of operators defines the order
in which an operator evaluates its operands. Note that the use of parentheses raises the
precedence of the operator within parentheses. Here is a summary of C operators with their
precedence and associativity in the given table:
Operator
Operator Precedence Associativity
Category
Parentheses,
( ), { } 1 Left to Right
braces
Unary operators - - , ++, !, & 2 Right to Left
Multiplicative
*, /, % 3 Left to Right
operators
Additive
+, - 4 Left to Right
operators
Shift operators <<, >> 5 Left to Right
Relational
<, >, <=, >= 6 Left to Right
operators
Equality
!, =, = = 7 Left to Right
operators
Bitwise operators ^, | 8 Left to Right
Logical operators &&, || 9 Left to Right
Conditional
?, : 10 Right to Left
operators
Assignment +=, -=, /=, <<=,
11 Right to Left
operators >>=
Comma operator , 12 Left to Right
DIFFERENCES BETWEEN A COMPLIER AND AN INTERPRETER
Complier Interpreter
It takes the entire source code as input and It takes only one statement from the source
translates it into machine language and code
executed at a time, translates it to machine language and
it. then executes it.
All errors that occur within the entire program Only errors that occur in each executed
are listed and displayed. statement are displayed.
Debugging is faster. Debugging is slower.
It requires more memory. Less memory is required.
Expensive Less expensive.
PRACTICE QUESTIONS
o Flowchart for a program that converts temperature in degrees Celsius to degrees
Fahrenheit.
o Flowchart for a program that converts inches to centimeters First let us write the steps
involved in this computation technique.
o Flowchart to get marks for 3 subjects and declare the result. If the marks >= 35 in all the
subjects the student passes else fails.
o To find the sum of first N numbers. This example illustrates the use of a loop for a
specific number of times.
o To check whether character read from keyboard is Z. If it is Z then print END, else read
another character. This example shows the test which executes till a particular condition
is satisfied.