Chapter 1 Intoduction to Programming Language (1)
Chapter 1 Intoduction to Programming Language (1)
They have been deployed to solve different real life problems, from the simplest game
playing up to the complex nuclear energy production.
Nowadays, Computers are used almost everywhere.
Most of the areas have already started working with the help of computers such as
scientific researches, Banking, Airways, communication, businesses, Education, Industries,
engineering, hospital and so on. Any tools the used by engineers is developed by
programming language.
The terms computer programs, software programs, or just
programs are the instructions that tells the computer what to do.
computer programs does nothing unless its instructions are
executed by a CPU.
Computer programming (often shortened to programming or
coding) is the process of writing, testing, debugging/
troubleshooting, and maintaining the source code of computer
programs.
Writing computer programs means writing instructions, that will
make the computer follow and run a program based on those
instructions.
• Computer programs (also know as source code) is often written by
professionals known as Computer Programmers (simply
programmers).
• Source code is written in one of programming languages.
• A programming language is an artificial language that can be used
to control the behavior of a machine, particularly a computer.
Programming languages, like natural language, are defined by
syntactic and semantic rules which describe their structure and
meaning respectively.
• The syntax of a language describes the possible combinations of
symbols that form a syntactically correct program. The meaning
given to a combination of symbols is handled by semantics
• A main purpose of programming languages is to provide/run
instructions to a computer.
• Computers do exactly what they are told to do, and cannot
understand the code the programmer "intended" to write.
• Computer languages have relatively few, exactly defined, rules for
composition of programs, and strictly controlled vocabularies in
which unknown words must be defined before they can be used.
Programming languages can be divided in to three major categories:
low-level, Assembly language and high-level languages.
1. Low-level languages
Computers only understand one language and that is binary language or the language of 1s and
0s. Binary language is also known as machine language, one of low-level languages
Although the computer easily understood these programs, it proved too
difficult for human being to remember all instructions.
Language was developed, which were easier to learn and understand.
2. Assembly language correspondences symbolic instructions and
executable machine codes and was created to use letters (called
mnemonics) to each machine language instructions to make it easier
to remember or write. For example: ADD A, B – adds two numbers in
memory location A and B
The assembly language must be translated to machine code by a separate
program called assembler.
The machine instruction created by the assembler from the original program
(source code) is called object code.
3. High-level languages
High-level languages are more English-like, it easier for programmers
(human).
• High-level languages also require translation to machine language before
execution. This translation is accomplished by two ways.
Compilers translate the entire source code program before execution.
Interpreters translate source code programs one line at a time. Interpreters are
more interactive than compilers
some examples of high-level languages are FORTRAN (FORmula
TRANslator), BASIC (Bingers All Purpose Symbolic Instruction Code),
PASCAL, C, C++, Java e.t.c
• Every language has its strengths and weaknesses.
• For example, FORTRAN is a particularly good language for processing numerical
data, but it does not lend itself very well to organizing large programs. Pascal is very
good for writing well-structured and readable programs, but it is not as flexible as the
C programming language. C++ embodies powerful object-oriented features
Programming Paradigm
• Another most fundamental ways programming languages are
characterized (categorized) is by programming paradigm. A
programming paradigm provides the programmer's view of code
execution. The most influential paradigms are examined in the next
three sections, in approximate chronological order.
• Procedural Programming Languages
• Object-Oriented Programming Languages
• Procedural programming specifies a list of operations that the program must complete
to reach the desired state.
• Each program has a starting state, a list of operations to complete, and an ending point.
This approach is also known as imperative programming. Integral to the idea of
procedural programming is the concept of a procedure call.
• Procedures, also known as functions, subroutines, or methods, are small sections of
code that perform a particular function.
• A procedure is effectively a list of computations to be carried out. Procedural
programming can be compared to unstructured programming, where all of the code
resides in a single large block.
• By splitting the programmatic tasks into small pieces, procedural programming allows a
section of code to be re-used in the program without making multiple copies. It also
makes it easier for programmers to understand and maintain program structure.
• Two of the most popular procedural programming languages are FORTRAN and BASIC.
Object-Oriented Programming
Languages
• Object-oriented programming is one the newest and most powerful
paradigms. In object- oriented programs, the designer specifies both
the data structures and the types of operations that can be applied to
those data structures.
• This pairing of a piece of data with the operations that can be
performed on it is known as an object.
• A program thus becomes a collection of cooperating objects, rather
than a list of instructions.
• Objects can store state information and interact with other objects,
but generally each object has a distinct, limited role.
Software Development Life Cycle (SDLC)
• The Systems Development Life Cycle (SDLC) is a conceptual model used in
project management that describes the stages involved in system
development project.
• In general, the SDLC includes the following phases:
1. Feasibility Study: in this phase, the problem is identified precisely and
completely, i.e. understanding exactly what the problem is, what is
needed to solve it? What are the constraints and special conditions?
The feasibility study is used to determine if the project should get the go-
ahead. If the project is to proceed, the feasibility study will produce a
project plan and budget estimates for the future stages of development.
2. Requirement Analysis: Analysis gathers the requirements for the system. This
stage requires analysis of the data and procedures needed to achieve the
desired result. In this phase, the developer needs to develop various solutions
to solve the given problem..
3. Design: once the requirements of the program are defined, the next stage is to
design a solution to solve the problems. This stage is also called
Algorithm/Program design. In general, this phase focuses on:
• High Level Design: i.e. what programs are needed and how are they going to
interact.
• Low level Design: i.e. how the individual programs are going to work.
• Interface Design: i.e. what is the interface going to look like.
• Data Design: i.e. what data will be required?
Cont.…
4. Testing the Algorithm (Design): Before converting the algorithms into actual
code, it should be checked accuracy. The main purpose of checking algorithm is
to identify major logical errors at early stages, because logical errors are often
difficult to detect and correct at later stages. The testing also ensures that the
algorithm is a ‘true’ one and it should work for any data
5. Implementation (Coding): In this phase the designs are translated into code.
Computer programs are written using a conventional programming language.
Programming tools like Compilers, Interpreters, and Debuggers are used to
generate the code. Different high level programming languages like C, C++,,
and Java are used for coding.
6. Testing: once the code is generated (implemented), the software program
testing is begins. There are three different testing methodologies. These are:
1.3 Problem solving Techniques
Print C
end
• Example 2: Write an algorithm description and draw a flow chart
to check a number is negative or not.
Algorithm description.
• 1/ Read a number x
• 2/ If x is less than zero write a message negative
• else write a message not negative
• A loop normally consists of four parts. These are:
• Initialization: - Setting of variables of the computation to their initial values and setting the
counter for determining to exit from the loop.
• Computation: - Processing
• Test: - Every loop must have some way of exiting from it or else the program would endlessly
remain in a loop.
• Increment: - Re-initialization of the loop for the next loop.
• Write the algorithmic description and draw a flow chart to find the following
sum.
Sum = 1+2+3+…. + 50
Algorithmic description (pseodocode)
1. Initialize sum too and counter to 1
2. check the counter less than or equal to 50.
• Add counter to sum
• Increase counter by 1
• Repeat step 2
1.2 Else
Exit
Exercise :-
1. write a pseudo code and draw a flow chart to calculate 2 power 4
2. write a pseudo code and draw a flow chart to find and print the
largest of the three numbers.
3. write a pseudo code and draw a flow chart to calculate the sum of
numbers from 1to 10?
4. write a pseudo code and draw a flow chart to find and print an even
no in b/n 1 and 50?
Worksheet 1
Develop an algorithm for each of the following problems. Use flowchart and Pseudocode
method of developing an algorithm. An algorithm that:
1. Converts a mark for a given course to its corresponding letter-grade. (You may set
your own scale for the grading)
2. Checks if a given number is EVEN or ODD.
3. Counts and displays the number of even and odd occurrences in a given list of
integers.
4. Finds the minimum and maximum of two given numbers.
5. Finds the maximum of five given numbers.
6. Searches for the Greatest Common Divisor (GCD) of two natural numbers.
7. Searches for the Least Common Multiple (LCM) of two natural numbers.
8. Converts a decimal number to its binary equivalent.
9. That accepts two numbers and displays the product, sum, and difference of the two numbers.
10. That reads a number and print the sum of the integers up to the number, i.e.
1 + 2 + 3 + 4 + . . .+ n
11. That reads a number n and prints 2n