0% found this document useful (0 votes)
1 views8 pages

Computer Programming

The document outlines the fundamental concepts and phases of software engineering, including Analysis, Design, and Development, as well as the definitions and uses of algorithms and pseudocode. It explains various programming constructs such as variables, data types, operators, control structures, loops, procedures, functions, and arrays, providing examples of pseudocode for each concept. Additionally, it includes assignments for practical application of the discussed topics.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views8 pages

Computer Programming

The document outlines the fundamental concepts and phases of software engineering, including Analysis, Design, and Development, as well as the definitions and uses of algorithms and pseudocode. It explains various programming constructs such as variables, data types, operators, control structures, loops, procedures, functions, and arrays, providing examples of pseudocode for each concept. Additionally, it includes assignments for practical application of the discussed topics.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Chapter (1)

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.

1) Input / Output Statement


i) ACCEPT : to input data from a keyboard. E.g: ACCEPT num;
ii) READ : to input data from a backing store E.g: READ num;
iii) WRITE : to output data to backing store E.g: WRITE num;
iv) DISPLAY : to output data to a screen E.g: DISPLAY num;
v) PRINT : to output data to a printer E.g: PRINT num;

2) Comment /* To find the maximum */

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.

Use Variable : mark of type Integer // declare variable


mark:=100 // assign

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.

Computer Programming Ch 1-1


KMD Computer Centre
Global variable
 A team used to describe the scope of a variable: global variables are accessible from all parts of a
program.

The different types of data are represented as follows:

Whole number (eg: 12, 3040, 50987) Integer


Fractional number (eg: 3.1415) Real or Float
Letter (eg: A Character
Name (eg: John Smith) String
FALSE OR TRUE, 0 OR 1 Boolean

Operators
a) Arithmetic Operators
+ Addition - Subtraction
* Multiplication / division % Modules

Precedence of the arithmetic operations:


Bracket, Of, Division, Multiplication, Addition, Subtraction

b) Relational Operators
< Less than
> Greater than
<= Less than or equal
>= Greater than or equal
= Equal
<> Not Equal

c) Logical Operators and, or

3) Assignment Statement ( ) or ( := )

Format: Variable := Expression; (or) variable Expression


e.g: Salary := 3000; (or) sum a+b+c

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

Computer Programming Ch 1-2


KMD Computer Centre
6) Selection Control Structure
 Test a condition and perform action according to the outcome.

a) One Way Selection


IF condition
THEN command sequence;
ENDIF

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

Computer Programming Ch 1-3


KMD Computer Centre
e.g. BEGIN
Use variable: mark OF TYPE Integer
DISPLAY “Enter mark”
ACCEPT mark
IF mark >=80 THEN
DISPLAY ‘Distinction’
ELSE IF mark >=60 and mark <80
THEN DISPLAY ‘merit’
ELSE IF mark >=40 and mark <60
THEN DISPLAY ‘Pass’
ELSE
DISPLAY ‘Fail’
ENDIF
END PROGRAM

7) Loop
a) FOR Loop
 Used when the number of iterations is known in advance.

FOR (starting state; stopping condition; increment)


Statements
ENDFOR

e.g. BEGIN PROGRAM


Use variable: c OF TYPE Integer
FOR (c :=1; c<=5; c+1)
DISPLAY ‘Hello’, c
END FOR
END PROGRAM

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

e.g.(1) Use Variable: c OF TYPE Integer


c := 1
WHILE (c <=5)
DISPLAY “Hello”, c
c := c+1
ENDWHILE

e.g.(2) Use Variable: letter OF TYPE Character


ACCEPT letter
WHILE letter <> ‘q’
DISPLAY letter
ACCEPT letter
ENDWHILE

Computer Programming Ch 1-4


KMD Computer Centre
c) REPEAT UNTIL Loop
 Condition is checked after the action.
 Commands are executed at least one time.
 Commands are executed repeatedly when the condition is true.

Starting State;
REPEAT
Commands
Increment / decrement
UNTIL (a true condition)

e.g.(1) Use Variable: c OF TYPE Integer


c := 1
REPEAT
DISPLAY “Hello”, c
c := c+1
UNTIL c >5

e.g.(2) Use Variable: letter OF TYPE Character


ACCEPT letter
REPEAT
DISPLAY letter
ACCEPT letter
UNTIL letter=’q’

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.

PROCEDURE xyz (list of parameters)


Body of procedure
END PROCEDURE

e.g: MAIN PROGRAM


writechar(10, ‘b’) // call
writechar(20, ‘d’)
END MAIN PROGRAM

PROCEDURE writechar (n OF TYPE integer, ch OF TYPE character) // definition


Use variable: i OF TYPE Integer
FOR(i :=1; i<=n; i+1)
DISPLAY ch
ENDFOR
END PRPCEDURE

9) Function
A program unit which, given values for input parameters, computers a value and then return calling program.

FUNCTION xyz (list of parameters)


Body of function
RETURN value
END FUNCTION

Computer Programming Ch 1-5


KMD Computer Centre
INTEGER FUNCTION Add (x, y OF TYPE integer) // definition
Use variable: ans OF TYPE Integer
ans := x+y
RETURN ans
END FUNCTION

INTEGER FUNCTION Subtract (x, y OF TYPE integer) // definition


Use variable: ans OF TYPE Integer
ans := x+y
RETURN ans
END FUNCTION

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

 A one-dimensional array, a list of elements distinguished by a single index.

Syntax: Array Name[index] ARRAY OF TYPE data type

Exam: Use variable: a[10] ARRAY OF TYPE Integer

Begin
Use variable: a[10] ARRAY OF TYPE Integer
i OF TYPE Integer

FOR( i :=1; i<=10; i+1)


ACCEPT a[i]
ENDFOR

FOR( i :=1; i<=10; i+1)


DISPLAY a[i]
ENDFOR
End

Computer Programming Ch 1-6


KMD Computer Centre
Two-dimensional Array

 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.

Syntax: Array Name[row][col] ARRAY OF TYPE data type

Exam: Use variable: a[3][4] ARRAY OF TYPE Integer

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

FOR(r:=1; r<=3; i+1)


FOR(c:=1, c<=4; c+1)
DISPLAY a[r][c]
ENDFOR
ENDFOR
End

Liner Search
User variable: a[10] ARRAY OF TYPE Integer
I, SearchNo, found OF TYPE Integer
found:=0

FOR(i:=1; i<=10; i+1)


ACCEPT a[i]
ENDFOR
DISPLAY “Enter number to be search”
ACCEPT SearchNo
FOR(i:=1; i<=10; i+1)
IF SearchNo=a[i] THEN
DISPLAY SearchNo, “Found at position”, i
found:=1
ENDIF
ENDFOR
IF found=0 THEN
DISPLAY SearchNo, “not found”
ENDIF

Assignments

1. To find the min and max value in two unequal integers.

2. To define even and odd number for given number.

3. To determine the positive, negative or zero from given number using keyboard.

Computer Programming Ch 1-7


KMD Computer Centre
4. Rewrite the pseudo code program to Sort the three variable following code.
5. Begin
6. use variable : a,b,c of type Integer
7.
8. if ( a> b and a>c and b>c ) then
9. display a,b,c
10. else if a>c and a>b and c>b then
11. display a,c,b;
12. ………
13. ………
14. ………
15. ………
16. endif
17. End

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.

Computer Programming Ch 1-8

You might also like