Computer Programming
Computer Programming
Pseudo Code
Required to be a Software Engineer
Analysis
The Analysis phase is focused on understanding and defining the requirements of the software.
Design
The Design phase involves creating a detailed plan for the software based on the requirements gathered in
the Analysis phase. It outlines the system architecture, modules, interfaces, and data structures.
Development
The Development phase is where the actual coding of the software takes place.
It involves writing, testing, and debugging the code.
What is an Algorithm?
A sequence of steps to solve a given problem is called as algorithm. Thus, an algorithm is a step-by-
step procedure developed for solving a given problem. An algorithm consists of sequences,
selections and iterations.
What is Pseudocode?
A Pseudocode is defined as a step-by-step description of an algorithm.
Pseudocode does not use any programming language in its representation instead it uses the simple
English language text as it is intended for human understanding rather than machine reading.
Pseudocode is the intermediate state between an idea and its implementation(code) in a high-level
language.
Variable
A variable in pseudocode is a way to store a value that can change throughout the execution of a
program1. Variables can store different data types and can be used in various operations
1. Understanding Variables: A variable is a named storage location in the computer's memory that can
be used to store values. Variables are usually assigned an initial value, and the value stored in a
variable can be changed throughout the execution of a program.
2. Naming Variables: Should be named using meaningful names that describe the purpose of the
variable.
3. Using Variables: Once a variable has been declared, it can be used in various operations within a
pseudocode program.
4. Updating Variables: The value stored in a variable can be updated throughout the execution of a
program. F
5. Data Types: Variables can store different data types, such as integers, floating-point numbers, and
strings. The data type of a variable determines the type of value.
Local variable
A term applied to variable which are only accessible in the program module within which they are
defined, typically in a procedure or function body.
Operators
a) Arithmetic Operators
+ Addition - Subtraction
* Multiplication / division % Modules
b) Relational Operators
< Less than
> Greater than
<= Less than or equal
>= Greater than or equal
= Equal
<> Not Equal
3) Assignment Statement ( ) or ( := )
4) Control Structure
Three main types of instructions are used in programming
-Sequence
-Selection
-Loops
5) Sequence
-The instructions are in the right order.
-All included instructions which have to be carried out in sequence.
BEGIN
Use variable: a, b, c, sum OF TYPE Integer
ACCEPT a, b, c
sum := a+b+c
PRINT “Sum=”, sum
END PROGRAM
e.g.(1) BEGIN
Use variable: mark OF TYPE Integer
DISPLAY “Enter mark”
ACCEPT mark
IF mark >=40 THEN
DISPLAY ‘Pass’
ENDIF
END PROGRAM
e.g.(2) BEGIN
Use variable: Salary, sales, Bonus OF TYPE Integer
DISPLAY “Enter sales”
ACCEPT sales Multi Way for Case Statement
IF sales >10000 THEN DO CASE OF exp
Salary := 3000 CASE condition
Bonus := 2000 Statement
ENDIF CASE condition
END PROGRAM Statement
CASE condition
b) Two Way Selection
Statement
IF condition
OTHERWISE
THEN command sequence 1
Statement
ELSE
ENDCASE
command sequence 2
ENDIF
Eg. BEGIN
Use variable: operator OF TYPE Character
e.g. BEGIN
Result, a, b OF TYPE Integer
Use variable: mark OF TYPE Integer
DISPLAY “Enter two number and operator”
DISPLAY “Enter mark”
ACCEPT a, b, operator
ACCEPT mark
DO CASE OF operatr
IF mark >=40 THEN
CASE operator=’+’
DISPLAY ‘Pass’
Display Result: =a+b
ELSE
CASE operator=’-’
DISPLAY ‘Fail’
Display Result: =a-b
ENDIF
CASE operator=’*’
END PROGRAM
Display Result: =a*b
CASE operator=’/’
c) Multi- Way Selection (or) Nested IF Statement
Display Result: =a/b
IF Condition 1
OTHERWISE
THEN command sequence 1;
Display “Invalid operator”
ELSE IF condition 2;
ENDCASE
THEN command sequence 2;
END PROGRAM
ELSE
command sequence 3;
ENDIF
7) Loop
a) FOR Loop
Used when the number of iterations is known in advance.
b) WHILE Loop
Test the condition before action.
Commands may not be executed at all, if condition is false.
Starting State;
WHILE (a true condition)
commands;
increment / decrement;
ENDWHILE
Starting State;
REPEAT
Commands
Increment / decrement
UNTIL (a true condition)
8) Procedures
A Section of a program which carries out a well-defined operation on data specified by parameters. It can be
called from anywhere in a program, and different parameter can be provided for each call.
9) Function
A program unit which, given values for input parameters, computers a value and then return calling program.
MAIN PROGRAM
Use variable: a, b, result, avg OF TYPE Integer
DISPLAY “Enter two number”
ACCEPT a, b
result := Add(a, b) // call
avg := result/2
DISPLAY “SUM=”, result
DISPLAY “AVG=”, avg
DISPLAY “Subtract=”, Subtract (a, b) // call
END MAIN PROGRAM
10) Array
An order collection of a number of elements of same type, the number being fixed unless the array is flexible.
There are three types of array
- One-dimensional Array
- Two-dimensional Array
-
One-dimensional Array
Begin
Use variable: a[10] ARRAY OF TYPE Integer
i OF TYPE Integer
Two dimensional arrays have two subscripts to identify an element of the array. They can be thought
of as the rows and columns in a table. All elements of a two-dimensional array must be of the same
data type.
Begin
Use variable: a[3][4] ARRAY OF TYPE Integer
r, c OF TYPE Integer
FOR(r:=1; r<=3; i+1)
FOR(c:=1, c<=4; c+1)
ACCEPT a[r][c]
ENDFOR
ENDFOR
Liner Search
User variable: a[10] ARRAY OF TYPE Integer
I, SearchNo, found OF TYPE Integer
found:=0
Assignments
3. To determine the positive, negative or zero from given number using keyboard.
5.Write a pseudo code program to determine vowel or not and accepted one character from the
keyboard.
6. Use pseudo code to construct a loop and condition which prints out the numbers 19, 21, 23, 25, 27
7. Write a program to output the following structure by using for loop and condition
1) 1 2 3 4 5 4 3 2 1
2) 5 4 3 2 1 2 3 4 5
8. Write a WHILE Loop which prints all the integers from 21 to 31 inclusive.
9. Write a FOR Loop which finds the sum of all the integers in the range m..n where m and n are both
variable of type integers and m<n.
10. Write a pseudo code program to find and output even number between 1 to 100.
11. Write a program to count character given from keyboard until character is ‘x’ and display the total
character count.
12. Write the pseudo for calculator program includes Multiply and Division using one procedure and one
function.