Chapter # 1
CONCEPT OF COMPUTER PROGRAMMING
Q1) Define program
Program :A program is a set of instructions that computer must follow in order to
process data into information. The instructions consists of statements used in
programming language, such as BASIC, Pascal ,C, C++,Java etc.
Q) Describe programming process steps
1. Defining the problem.
2. Planning the solution.
3. Coding the program.
4. Testing the program.
5. Documenting the program.
Step 1: Defining the problem
It is impossible to develop a solution to a problem if you do not have a clear
understanding of the problem itself.
Defining the problem requires that the programmer specify our mini tasks. They are
Determining Program Objectives: You solve problems every day. A problem might
deciding whether to attend a picnic at night or not. Or you might try to change your class
section in order to adjust in a better way.
Determining the Desired output: it is always better to understand the outputs of a
program before you specify the inputs. For example, what kind of hard copy is wanted?
Determining the Input Data: Once you know the output you want, you can determine
input data requirements. What kind of input data is needed? What form should it app ear
in? What is its source? What type or style of user interface is required by the users?
Determining the Processing Requirements: Here you make sure you understand
the operations which must be performed in order to process data. Exactly what
computers, peripheral equipment, and other programs will be needed to run the
program?
Step 2: Planning the Solution
Once the programmer has determined what the program must do, the next set is to plan
a solution, preferably using structured programming techniques consist of the following:
(1)top-down programs design (2)algorithm (3)flowcharts.
Top-Down Program Design: Once you have determined the outputs and inputs you
can use top-down program design to identify the program’s processing steps. Such steps
are called program modules. Each module is made up logically related program
statements.
Algorithm: Algorithm is a step-by-step method of designing a program using normal
human-language statements. It describes the logic and processing flow of a program.
Algorithm is like an outline or summary form of the program you will write.
Flowchart: A flowchart is a pictorial representation of logic used in a computer program.
It illustrates the major program elements and how they are logically integrated. The
flowchart uses standard symbol-called ANSI symbols.
Step 3: Coding the Program
Coding is the process of writing instructions in a programming language. The
language used depends on the system resources available, the expertise of
the programmer, and the type of application.
In order to execute a program, a program must be in machine language. A
machine language is a complex language that uses actual machine addresses and
difficult operation codes. Because of the complexity of machine language, programs are
written in high level languages, such as BASIC, Pascal, C, C++ or PL/1.
The high level program is called the source program, and the translated program in
machine language is called the object program.
Types of translators:
The two main types of translator programs used to translator programs written in high-
level languages into machine language are interpreters and compilers. Interpreters and
compiler break down a single high-level instruction or language statement into several
machine-language instructions.
Interpreters: Interpreters translate the program one statement at a time as the
program is actually being run on the computer. Each statement is translated and
executed before the interpreter proceeds to the next statement. This process continues
until the end of the program is reached.
Compilers: Compilers translate the entire source program into machine language in one
process, creating an object program. Another, referred to as the linking loader or linkage
editor, prepares the object program for execution.
Assembler: The assembler translates the program written in assembly language into machine language
instructions for execution.
Step 4: Testing the Program (Debugging)
After the program has been coded comes the stage to check whether the program works
or not? Testing a program to see if it does what it is supposed to do is usually the
hardest, longest and most frustrating stage in the program development process.
Programming errors are known as bugs and the process of detecting and correcting
these errors is called debugging.
ERRORS:
Computer error refers to a mistake or malfunction that occurs within a computer system, leading to unexpected or
incorrect behavior.
Types of Errors
There are three types of errors that occur in a computer program: syntax errors, logic
errors and runtime errors.
Syntax errors: A syntax error is a violation of the rules of whatever the language the
programs being written. These are often caused by simple typing mistakes. for example,
the C statement
C = (A+B/2
Logic errors: the logical error is an error in planning the program’s logic. In this case
the language processor successfully translates the source code into machine code.
When a logical error occurs, all you know is that the computer is not printing the correct
output. The computer does not tell you what is wrong.
For example, you wanted to do the sum of A and B and put the result ion the variable C.
This is accomplished by typing:
Let A = 5
B=6
C=A+B
But while typing the programmer has’ however typed the following expression:
C=A - B
Runtime errors: Runtime errors occur when the program is run on the computer and
the results are not achieved due to some misinterpretation of a particular instruction.
This could be something like dividing a number by zero which results in a very large
value of quotient. It may also be any other instruction which a computer is not able to
understand.
Step 5: Documenting the Program
Documentation is a written detailed description of the programming cycle and specific
facts about the program. Typical program documentation materials include the origin
and nature of the problem, a brief narrative description of the program, algorithm and
flowcharts, data-recorded description program, listings, and testing result. Comments in
the program itself are also considered an essential part of documentation.
1. User documentation.
2. Operator Documentation.
3. Programmers Documentation
Q2) Describe the characteristics of programming language.
Characteristics of programming Language
There are many different programming languages, each one designed to solve certain
types of problems all of them have the basic function of directing the operations of a
computer. Therefore, certain general classes of instructions are present in every
programming language, which can be categorized as follows:
Input / Output Instructions: These instructions direct the computer to “read from” or
“write to” with a peripheral device (for example, disk drive or a printer).
Computation Instructions: These instruction direct the computer to perform
arithmetic operations (add, subtract, multiply, divide, and raise a number to a power).
For example, PAY = HOURS * RATE computer gross earnings hourly employees.
Control Instruction: These instruction can alter the sequence of the program’s
execution or terminate execution. For example, in an accounts receivable program,
different sequence of instructions are executed for customers who pay on time and
those who pay after the due date.
Assignment Instructions: These instructions transfer data internally from one RAM
location to another. For example, a data item may be copied from one location to
another, the result of a computation may be stored at a specified location.
Q3) Write advantages and disadvantages of different programming languages.
1) FORTRAN: The Language of Mathematics & the First High-Level Language
Advantages
1. FORTRAN can handle complex mathematical and logical expressions.
2. Its statements are relatively short and simple.
3. FORTRAN programs developed on one type of computer can often be easily modified
to work on other types.
Disadvantages:
1. FORTRAN does not handle input and output operations to storage device as efficiently
as some other higher-level language.
2. It has only a limited ability to express and process nonnumeric data.
3. It is not as easy to read and understand as some other high-level language.
2) COBOL: the language of business
Advantages
1. It is machine independent.
2. Its English-like statements are easy to understand, even for a nonprogrammer.
3. It can handle many files, records and fields.
4. It easily handles input/output operations.
Disadvantages
1. Because it is so readable, it is wordy. Thus, even simple program are lengthy, and
programmer productively is slowed.
2. It cannot handle mathematical processing.
3) BASIC: For Beginners and Others
Advantages
1. The primary advantage of BASIC is its ease of use.
2. Its best programming language for beginners.
Disadvantages
1. Its processing speed is relatively slow, although compiler versions are faster than
interpreter versions.
2. There is no one version of BASIC, although is 1987 ASNI adopted a new standard that
eliminated portability problems-that is, problems with running it on different computers.
4) Pascal: The Simple Language
Advantages
1. Pascal is easy to learn.
2. It has extensive capabilities for graphics programming.
3. It is excellent for scientific use.
Disadvantages
1. Pascal has limited input/output programming capabilities, which limits its business
applications.
C LANGUAGE:
Advantages
1. A Portable Language
2. C works well with microcomputers.
3. It has a high degree of portability-it can be run without change on a variety of
computers.
4. It is fast and efficient.
5. It enables the programmer to manipulate individual bits in main memory.
Disadvantages
1. C is considered difficult to learn.
2. Because of its conscience, the code could be difficult to follow.
3. It is not suited to applications that require a lot of report formatting the data file
manipulation.
Chapter #2
ALGORITHM AND FLOWCHART
Q1) Define Algorithm and also write importance of algorithm.
ALGORITHM:
The word algorithm is derived from the well-known ninth century mathematician of Iran Abu Jafar Ibne Musa
Al Khwarizmi, who developed methods to solve problems using specific instructions step by step. Originally
the term was algorism but later on, it changed to algorithm.
Definition:
Algorithm is a step-by-step method of designing a program using normal human-
language statements. It describes the logic and processing flow of a program. Algorithm
is like an outline or summary form of the program you will write.
IMPORTANCE: Algorithm is the founder of computer science. It tells the computer to do the task in more
efficient manner. The efficiency of algorithm usually determines the efficiency of entire program and it also
optimizes the computer. Users can easily get the idea of the entire system by just read the algorithm.
Q2) Write an algorithm to compute the distance travelled by train in specific time.
Step 1. Start the calculation.
Step 2. Enter a value for SPEED.
Step2 3.Enter a value for TIME.
Step 4. Calculate DISTANCE by using formula SPEED x TIME.
Step 5. Write the value of DISTANCE.
Step 6. Exit
Q3) What do you know about IDE?
IDE: -
IDE stands for Integrated Development Environment . IDE’s provide interfaces for users to write
code, organize text groups and automate programming tools. Instead of a simple plain text editor IDE
combines the functionality of multiple programming processes into one. Most IDEs come with built-in
translators. Some common popular IDE’s are listed below.
1) TURBO C++
2) DEV-C ++
3) VISUAL STUDIO.
Q4) What do you know about Pseudo code?
PSEUDOCODES:
Pseudo codes is an English-like way of representing the solution to a problem. The prefix pseudo means fake;
pseudo codes, therefore literally means the fake codes - that is not the codes that actually entered into the
computer. It is considered a “first draft” because the pseudo code eventually has to be translated into
programming language. In general, a pseudo codes is a notational system in which ideas can be expressed
informally during the algorithm development process.
MATHEMATICAL NOTATION AND FUNCTION:
Remainder Function:
Let k be any integer and M be a positive integer. then
k (MOD M) = remainder
(read k modulo M) will donate the integer remainder when k is divided by M.
EXAMPLE:
11(MOD 2) = 1 24(MOD 7) = 3 20(MOD 4) = 0
22(MOD 3) = 1 3(MOD 7) = 3 4(MOD 10) = 4
INTEGER VALUE FUNCTION:
Let X be any real no then the integer value of X, written as INT(X), convert X into an integer by deleting
(truncating) the fractional part of the number. Thus
INT (4.32) = 4 INT (5.392) = 5 INT(-8.7) = -8 INT (9) = 9
ABSOLUTE VALUE FUNCTION:
The absolute value of the real number X, written as ABS(X) or |X|, is define as the greater of X or –X. Hence
ABS (0) = 0
ABS (X) = X
ABS (-X) = X
Thus
ABS (-15) = 15 ABS (6) = 6 ABS (3.86) = 3.86 ABS (-0.21) = 0.21
Note that |X|= |-X| and, for X not equal to 0, |X| is positive.
FACTORIAL FUNCTION:
The product of the positive integers from 1 to n is denoted by n! (read ‘n factorial’). That is,
n! = 1 x 2 x 3 x … x (n-2) x (n-1) x n
It is also convenient to define 0! = 1
EXAMPLE:
2! = 1 x 2 = 2 3! = 1 x 2 x 3 = 6 4! =1 x 2 x 3 x 4 = 24
ALGORITHMIC NOTATION:
Example: SUM = X + Y
This algorithm takes two numbers X and Y and output their sum.
1. Read X [To get first Number]
2. Read Y [To get second Number]
3. Set SUM = X+Y [Summing two Numbers]
4. Write SUM [Displaying result on Screen]
5. Exit [Termination of Program]
Following paragraph summaries certain points and terminology used in making algorithm
1. Algorithm Name: each algorithm must be written a unique name for identification.
2. Step Number: Each statement of the algorithm must be given a unique number for identification. (e.g.
1,2,3,etc)
3. Variables Name: variables name will use capital letters, as X, Y, SUM.
4. Getting Input from the User: ‘Read’ is used to get Input from the user (computer ask the users for
value)
5. Assigning Value to a variable: ‘Set’ is used to assign value to a variable (computer itself sets the value
for variable).
6. Algorithm Termination: ‘Exit’ is used to terminate the algorithm
7. Comments: ‘[‘ and ‘]’ are used for providing comments or remarks.
8. Control Transfer: use ‘Go to Step n’ to transfer control to step n.
Q5) Describe flowchart?
FLOWCHART: A flowchart is a pictorial representation of logic used in a computer
program. It illustrates the major program elements and how they are logically integrated.
The flowchart uses standard symbol-called ANSI symbols.
TYPES OF FLOWCHART:
1. Sequential Flowchart
2. Branched (Or Jump) Flowchart
3. Loop Flowchart
4. Nested Loops In a Flowchart.
Q6) Draw flow charts symbols
FLOWCHARTS:
Terminal Symbol Oval
START/ STOP
__________________________________________________________________________________________
__________________________________________________________________________________________
__________________________________________________________________________________________
Input/ Output Symbols
(PARALLELOGRAM)
__________________________________________________________________________________________
__________________________________________________________________________________________
__________________________________________________________________________________________
Process Symbol:
RECCTANGLE
(RECTANGLE)
__________________________________________________________________________________________
__________________________________________________________________________________________
__________________________________________________________________________________________
Flow Lines:
ARROWS
__________________________________________________________________________________________
__________________________________________________________________________________________
__________________________________________________________________________________________
Decision Symbol:
Decision
(DIAMOND)
__________________________________________________________________________________________
__________________________________________________________________________________________
__________________________________________________________________________________________
On- Page Connector Symbol:
CIRCLE
__________________________________________________________________________________________
__________________________________________________________________________________________
OFF- Page Connector Symbol:
PENTAGON
__________________________________________________________________________________________
__________________________________________________________________________________________
Predefined Process Symbol:
Predefined
__________________________________________________________________________________________
__________________________________________________________________________________________
Q7) Describe types of flowchart:
Read by book.