FOP Unit-1 Part-1 (Introduction To Computer Programming)
FOP Unit-1 Part-1 (Introduction To Computer Programming)
Subject
Fundamentals of Programming (CE3002)
Unit – 1
Introduction of Computer Programming
(Part – 1)
CONTENTS
1. Understanding Computer Systems and Computer Languages
2. Programming Paradigm and Classification
2.1. Types of Programming Paradigms
2.1.1. Imperative Programming Paradigms
2.1.2. Declarative Programming paradigms
3. Programming Development Process
4. Pseudocode Statements and Flowchart
4.1. Algorithm
4.2. Flowchart
4.3. Programming Constructs / Programming Structures
4.4. Algorithm and Flowchart Examples
Software is computer instructions that tell the hardware what to do. Software is
programs - instructions written by programmers.
Input – Data items enter the computer system and are put into memory, where
they can be processed. Hardware devices that perform input operations include
keyboards and mice. Data items include all the text, numbers, and other
information that are processed by a computer.
Output – After data items have been processed, the resulting information
usually is sent to a printer, monitor, or some other output device so people can view,
interpret, and use the results.
[The instructions you write using a programming language are called program code;
when you write instructions, you are coding the program.]
When you write a program, you usually type its instructions using a keyboard.
When you type program instructions, they are stored in computer memory, which is
a computer’s temporary, internal storage. Internal storage is volatile - its contents
are lost when the computer is turned off or loses power. Usually, you want to be
able to retrieve and perhaps modify the stored instructions later, so you also store
them on a permanent storage device, such as a disk. Permanent storage devices
are non-volatile - that is, their contents are persistent and are retained even when
power is lost.
[The program statements you write in a programming language are known as source
code. The translated machine language statements are known as object code.]
Only after program instructions are successfully translated to machine code the
computer can carry out the program instructions. When instructions are carried out,
a program runs, or executes. In a typical program, some input will be accepted,
some processing will occur, and results will be output.
The programming paradigms can be classified into two main types. The
paradigm type depends upon the programming language features and a
particular style of organizing the program code.
The programmer can either use standard library functions or create library
of user defined functions.
Object-oriented programming -
This approach seems to be like divide and conquer. Examples are NESL (one
of the oldest one) and C/C++ also supports because of some library function.
The main focus of the declarative style of programming is achieving the end
result. This paradigm is straight forward and to the point while writing the
program code.
The term algorithm is defined as logic plus control (logic + control). The logic
defines what should be solved whereas the control defines how it should be
solved.
The main advantage of the logic programming is that the programmer needs
to simply define the what part of the problem. And the system finds the best
solution to that problem.
Function can be replaced with their values without changing the meaning of
the program. Some of the languages like perl, javascript mostly uses this
paradigm.
There are several programming languages that are developed mostly for
database application. For example, SQL. It is applied to streams of structured
data, for filtering, transforming, aggregating (such as computing statistics), or
calling other programs. So, it has its own wide application.
Problem analysis -
Analyzing the problem is the first and most crucial step in programming. This
step requires you to do the following:
The heart of the programming process lies in planning the program’s logic.
During this phase, the programmer plans the steps of the program, deciding
what steps to include and how to order them. This is known as the algorithm.
You can plan the solution to a problem in many ways. The two most common
planning tools are flowcharts and pseudocode. If the problem is complex, you
broke the problem into subproblems, you need to design an algorithm for each
subproblem. Once you design an algorithm, you need to check it for correctness.
You can sometimes test an algorithm’s correctness by using sample data. At
other times, you might need to perform some mathematical analysis to test the
algorithm’s correctness.
Planning the logic includes thinking carefully about all the possible data
values a program might encounter and how you want the program to handle
each scenario.
Once you have designed the algorithm and verified its correctness, the next
step is to convert it into an equivalent programming code by coding the
program in one of more than hundreds of programming languages.
You then use a text editor to enter the programming code or the program
into a computer.
Compile and link the source program to produce the executable program -
Next, you must make sure that the program follows the language’s syntax. To
verify the correctness of the syntax, you run the code through a compiler.
A computer program must be free of syntax errors before you can execute
it. Usually, the software displays a list of syntax errors, which the programmer
corrects. If the compiler generates error messages, you must identify the errors
in the code, correct them, and then run the code through the compiler again.
When all the syntax errors are removed, the compiler generates the
equivalent machine code, the linker links the machine code with the system’s
resources, and the loader places the program into main memory so that it can
be executed.
The final step is to execute the program and test with some data to verify for
correct outputs. The compiler guarantees only that the program follows the
language’s syntax. It does not guarantee that the program will run correctly. A
program that is free of syntax errors is not necessarily free of logical errors.
results. Under these circumstances, you may have to re-examine the code, the
algorithm, or even the problem analysis.
After programs are put into production, making necessary changes is called
maintenance. These changes or revisions maybe for new requirements in the
Program's Input/Process/Output. Like new format or specification for input or
output data or requiring a new revision or additional operating process or
computation.
When you make changes to existing programs, you repeat the development
cycle. That is, you must understand these changes, plan, code, translate, and test
them again before putting them into production.
Pseudo is a prefix that means “false,” and to code a program means to put it in
a programming language; therefore, pseudocode simply means “false code,” or
sentences that appear to have been written in a computer programming language
but do not necessarily follow all the syntax rules of any specific language.
4.1. Algorithm
An algorithm is defined as sequence of steps to solve a problem (task). The
steps must be finite, well defined and unambiguous. Writing algorithm requires
some thinking. Algorithm can also be defined as a plan to solve a problem and
represents its logic. Note that an algorithm is of no use if it does not help us
arrive at the desired solution.
Characteristics of algorithm -
4.2. Flowchart
A flowchart is a pictorial (graphical) representation of an algorithm. A
flowchart is drawn using different kinds of symbols. A symbol is used for a
specific purpose. Each symbol has name.
Flowchart symbols –
2. Input / Output:
4. Decision:
6. Connector:
7. Loop:
Advantages of flowchart -
Disadvantages of flowchart -
1. Sequence
2. Selection
3. Iteration (Loop)
Sequence -
Selection -
Selection logic, also known as decision logic, is used for making decisions.
Selection logic is depicted as either an if…then…else or if…then structure.
Iteration (Loop) –
Iteration logic is also known as loop. Iteration logic is used when one or more
instructions may be executed several times depending on some condition.
1. Start
2. Read A,B
3. C=A+B
4. Print or display C
5. Stop
1. Start
2. Read length, L
3. Area = L*L
4. Print or display Area
5. Stop
1. Start
2. Read side length, A
3. Read side length B
4. Area = A*B
5. Print or display Area
6. Stop
1. Start
2. Read two values into two variables A, B
3. Declare third variable, C
4. C = A
5. A = B
6. B = C
7. Print or display A, B
8. Stop
1. Start
2. Read 3 numbers A, B, C
3. Calculate the average by the equation
Average = (A + B + C)/3
4. Print Average
5. Stop
1. Start
2. Read A,B
3. If A>B then
Print A is large
else
Print B is large
4. Stop
1. Start
2. Read n
3. Initialize count = 0, sum = 0
4. count = count + 1
5. sum = sum + count
6. Repeat steps 4 and 5 until count>=5
7. Print sum
8. Stop
1. Start
2. Read P, N, R
3. SI=(P*N*R)/100
4. Print SI
5. Stop
1. Start
2. Initialize F = 0, C = 0
3. Read F
4. C = (F-32) * 5/9
5. Write C
6. Stop
1. Start
2. Initialize count i = 1, sum = 0
3. sum = sum + i
4. Increment i by 1
5. Repeat steps 3 and 4 until i > 100
6. Print sum
7. Stop
1. Start
2. Read N
3. Initialize F = 1, I = 1
4. F = F * i
5. Increment i by 1
6. Repeat steps 4 and 5 until
i=N
7. Print F
8. Stop
1. Start
2. Read n
3. Initialize Count = 0, Sum = 0
4. Count = Count + 1
5. Sum = Sum + Count
6. Repeat steps 4 until 5 until Count >= n
7. Print sum
8. Stop
1. Start
2. Read n
3. Initialize Count = 0, Sum = 0
4. Count = count + 2
5. Sum = Sum + Count
6. Repeat steps 4 and 5 until count >= n
7. Print Sum
8. Stop
1. Start
2. Read n
3. Initialize Count = 0, Product = 1
4. Count = Count + 1
5. Product = Product * Count
6. Repeat steps 4 and 5 until count >= N
7. Print Product
8. Stop
1. Start
2. Read n
3. Initialize i = 0, Sum = 0
4. i = i + 1
5. Sum = Sum + (i * i)
6. Repeat steps 4 and 5 until i >= n
7. Print Sum
8. Stop
1. Start
2. Initialize Sum = 0, N = 1
3. Sum= Sum + N
4. N = N + 2
5. Repeat steps 3 and 4 until N <= 99
6. Print Sum
7. Stop
1. Start
2. Read Input data
3. Add marks of all subjects giving total
Obtained Marks
4. Percentage = ∗ 100
Total Marks
5. Write Percentage
6. Stop