0% found this document useful (0 votes)
13 views67 pages

CHIP - Programming Concepts

n

Uploaded by

Aashika 1999
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views67 pages

CHIP - Programming Concepts

n

Uploaded by

Aashika 1999
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 67

Programming Concepts

18 October 2021

© Atos|Syntel Inc. - For internal use


Content

Types of Software Variables

Programming and Operators, Expressions


Execution Environment and Statements

Programming Language Arrays


Paradigms

Program Modular Programming

2 | 18-Oct-21 | © Atos|Syntel Inc. - For internal use


Content Contd…

Good Programming Pseudo code


Practices

Debugging and Error Flowcharts


Handling

Data Structures and Files and Databases


Algorithms

Flow Control Constructs

3 | 18-Oct-21 | © Atos|Syntel Inc. - For internal use


Types of Software
Types of Software
▶ System Software

– Operating Systems (DOS, Windows, Unix etc)

– Device Drivers (extensions to the OS for new devices)

▶ Application Software

– General Purpose (Word, Excel, PowerPoint)

– Special Purpose (Billing, Payroll, Accounting)

▶ Utilities

– Compilers (C, C++, COBOL, PASCAL)

– Interpreters

– Virus Scanners

– Disk Maintenance

5 |18-Oct-21 | © Atos|Syntel Inc. - For internal use


Programming and Execution
Environment
Programming Environment
▶ Steps in program development

– Run an editor utility (notepad)

– Type the program and save (test.c)

– (Optionally) Compile the program (test.obj)

– (Optionally) Link the program (test.exe)

▶ Steps in running a program

– Compiled programs

• Double-click the .exe file

• Type the name of .exe file on command prompt

– Interpreted programs

• Pass the name of source program as a parameter to the Interpreter

7 |18-Oct-21 | © Atos|Syntel Inc. - For internal use


Programming Environment

Source file Source file

Compiler Interpreter

Object file Libraries

Linker Operating System, H/W

Executable

8 |18-Oct-21 | © Atos|Syntel Inc. - For internal use


Execution Environment – Memory Layout
▶ Steps carried out by OS
– Allocate memory for the program
– Load the program from secondary storage

▶ Sections of a Loaded program in memory


– Data
– Code
– Stack
– Heap

9 |18-Oct-21 | © Atos|Syntel Inc. - For internal use


Programming Language
Paradigms
Programming Language Paradigms
▶ Procedural (e.g. Fortran, C)

▶ Functional (e.g. LISP)

▶ Scripting (e.g. VBScript, JavaScript)

▶ Object Oriented

– Pure (SmallTalk, Java)

– Impure (C++)

• OOP is not compulsory to be used

▶ Object Based (VB)

– Makes use of objects but not all oops concepts can be used

11 |18-Oct-21 | © Atos|Syntel Inc. - For internal use


Program
What is a Program?
▶ Set of Instructions

– coded by a programmer

– to be executed by the computer

– for carrying out a task

– in a particular sequence

“Programming is an art as well as science” INPUT num1


INPUT num2
Result = num1+num2
DISPLAY result

13 |18-Oct-21 | © Atos|Syntel Inc. - For internal use


Program Structure
▶ A Program is composed of

– Data

• Concept of Type

• Storage Class

• Definition and Use

• Scope and Visibility

– Executable Statements

• Sequence (e.g. assignment, increment)

• Iteration (e.g. while, for, do)

• Flow control (e.g. function call, return, goto)

• Conditional (e.g. if, switch)

14 |18-Oct-21 | © Atos|Syntel Inc. - For internal use


Variables
Variables
▶ A variable

– Is a convenient name useful in the program, to refer to a memory location

– Usually has a data type which indicates


• The type of data that can be stored
• Size of the data that can be stored

– Is located at one of the following places


• Data Section int num1;
• Stack Section char choice;
• Heap float price;

– Has the following properties


• Scope
• Lifetime

16 |18-Oct-21 | © Atos|Syntel Inc. - For internal use


Variables – Best Practices
▶ Name should not start with

– White space (Spaces, tabs, new line characters)

– Special Characters (+, - , ?, *)

– Digits

▶ Name should not contain Keywords (if, for, while)

▶ Name should reflect the use of the variable

▶ It should not be too short/long

– Valid variable names: a1, a_1, k

– Invalid variable name: 1a, a 1, a+b

– Good variable name: age, employee_name, iAge

17 |18-Oct-21 | © Atos|Syntel Inc. - For internal use


Operators, Expressions and
Statements
Operators
▶ Types of Operators

– Arithmetic (Unary & Binary)

– Logical

– Conditional

– Conversion (Unary & Binary)

▶ Operator Precedence and associativity

19 |18-Oct-21 | © Atos|Syntel Inc. - For internal use


Expressions and Statements
▶ An expression is

– A single variable/constant/function call

– Multiple variables/constants/function call concatenated together using operators (a+b,


a+f1())

20 |18-Oct-21 | © Atos|Syntel Inc. - For internal use


Arrays
Arrays
▶ An array is a

– Homogeneous collection of elements

– Set of adjacent memory locations

– Set, storing variables of the same data type referred with a single variable name

• and a subscript to refer to the correct element in the group

▶ Arrays can be multi-dimensional


int result[10];
result[0]=100;
result[1]=150;
….

22 |18-Oct-21 | © Atos|Syntel Inc. - For internal use


Modular Programming
Modular Programming

▶ A group of named statements is called a Function or Procedure or a Subroutine

▶ A function can have

– Local variables int addition(int n1, int n2)


{
– Statements
int result=n1+n2;
– Parameters n1=0;
return result;
– Return type }
▶ Parameters

– Must be passed to the function (unless they are optional)

– Are passed by value or reference

24 |18-Oct-21 | © Atos|Syntel Inc. - For internal use


Statements
▶ Statements

– Directives

– Declarative statements

– Executable statements

• Expression statements

• Assignment statements

• Simple & compound statements

• Control statements (conditional/unconditional/looping)

25 |18-Oct-21 | © Atos|Syntel Inc. - For internal use


Modular Programming
▶ Module

– Set of functions defined in a file is called a module

▶ Application

– One or more Modules make up an Application

▶ Scope of a Variable
– Local (defined in a function/block)
– Global (defined outside a function)
▶ Lifetime of a Variable
– Local variables – same as the life of function
– Global variables – same as the life of application
– Static variables – same as the life of application but scope is like a local variable (allowed only
by some languages e.g. C++)
▶ Parameters behave as local variables (allocated on stack)

26 |18-Oct-21 | © Atos|Syntel Inc. - For internal use


Good Programming Practices
Good Programming Practices
▶ Comment the program before writing it

▶ All programs should include a comment block at or near the beginning of the program

▶ Avoid obscure programming language constructs and reliance on language-specific precedence


rules

▶ Be consistent! Stick to a method for variable naming or indenting throughout your program

▶ Each subroutine should have one clearly defined task

▶ Subroutines should be short enough so that reader can grasp their meaning as a unit

▶ Every subroutine should be preceded by a comment describing its purpose and use

▶ keep the number of parameters to any one subroutine at a minimum

▶ Limit the number of parameters passed by reference

▶ Functions should affect precisely one value - the function's return value

28 |18-Oct-21 | © Atos|Syntel Inc. - For internal use


Good Programming Practices (contd…)
▶ A new level of indentation should be used at every level of statement nesting in the program

▶ Do not put more than one statement on the same line

▶ Pick identifiers (i.e. names for variables, functions, records, etc.) that communicate the named
object's purpose to the reader

▶ Never change the value of a loop variable within that loop

▶ Use variables at the smallest possible level of scope

▶ Be consistent about the use of local variables with the same name throughout the program

▶ Give a comment to every variable in the program, describing its use

▶ Carefully consider every number that is typed in the code, and substitute a name for it (unless
you have a reason not to do so)

▶ If goto statement is used in the program, comment the reason thoroughly

29 |18-Oct-21 | © Atos|Syntel Inc. - For internal use


Debugging and Error Handling
Debugging and Error Handling
▶ What Happens When Execution Stops?

– In case of most IDE's, whenever an error is detected during the execution of a program,
program execution stops and an error message is printed.

– The execution context is that of the program unit (procedure, function, or main program) in
which the error occurred.

– When execution is interrupted, a current-line indicator is placed next to the line that will be
executed when processing resumes.

▶ When execution stops, you can take the following steps:

– Correct the problem and continue program execution

– Anticipate and handle errors to avoid execution halt

– To understand what is happening during program execution, consider setting breakpoint and
stepping through the code

31 |18-Oct-21 | © Atos|Syntel Inc. - For internal use


Debugging and Error Handling
▶ Working with Breakpoints
– Most programming tools allow you to pause the execution of a program at the specified line,
which is called setting a breakpoint.
– Breakpoints can be set at multiple points in a program.
– Breakpoints can be enabled/disabled at any point of time.

▶ Stepping Through a Program


– Once execution halts at a breakpoint, you can step through the program manually, or
continue execution automatically.
– When stepping through a main program, if the next line calls another procedure or function,
you have three options with which to handle execution of the nested program:
• Step Into executes statements in order by successive Step commands
• Step Over executes statements to the end of the called function, without interactive
capability
• Step Out to continue processing until the main program returns.

32 |18-Oct-21 | © Atos|Syntel Inc. - For internal use


Debugging and Error Handling
▶ Monitoring Variable Values
– Write statements to output the values of variables
– Use the Variable Watch window (preferred technique)

▶ Correcting Errors During Execution


– Sometimes it is possible to recover from an error by manually entering statements to correct
the problem. (Setting the values of variables, closing files, etc)
– Then choose to continue, which resumes execution of the program unit at the beginning of
the statement that caused the error.

▶ As an example:
– If an error occurs because an undefined variable is referenced,
– you can simply define the variable at the command prompt and then continue execution.
– Of course, this is a temporary solution. You should still edit the program file to fix the
problem permanently.

33 |18-Oct-21 | © Atos|Syntel Inc. - For internal use


Data Structures and
Algorithms
Data Structures: Beginning
▶ Languages provide basic data types (int, float..)

▶ Some languages also allow creation of user-defined types - UDFs (struct, class, record..)

struct Employee
{
char name[30];
int age;
float salary;
};

35 |18-Oct-21 | © Atos|Syntel Inc. - For internal use


Data Structures: Classification
► User-defined types can be used to create chains of objects in memory
Stack

Data Structure

Linear Non-Linear

Array Linked List Tree Graph


Graph

Stack Queue

Linear data structure Non-linear data structure

Has linear [unique] relationship between Does not have the linear relationship between
predecessor and successor predecessor and successor

36 |18-Oct-21 | © Atos|Syntel Inc. - For internal use


Data Structures: Linked Lists
▶ Linked Lists

– Use nodes which contain data and pointer to the next node in memory

– Are flexible in terms of addition/deletion of nodes as opposed to arrays

– Allow only sequential access to the nodes unlike Arrays

Head

Data Data Data

37 |18-Oct-21 | © Atos|Syntel Inc. - For internal use


Data Structures: Stack

▶ A Stack is a Last In First Out (LIFO) structure

– Can be implemented using Array or Linked List

– Items can be removed from the same end from where they are added

– Useful in situations where the LIFO discipline is required

Current TOP
Item2

Item1

38 |18-Oct-21 | © Atos|Syntel Inc. - For internal use


Data Structures: Queue

▶ A Queue is a First In First Out (FIFO) structure

– Can be implemented using Array or Linked List

– Items can be removed from front while they are added from the back

– Can be Circular

front

Item1 Item2

back

39 |18-Oct-21 | © Atos|Syntel Inc. - For internal use


Data Structures: Tree
▶ A Binary Tree is built out of nodes having data as well as left and right pointers

– Can be implemented using Array or Linked List

– Binary tree has 0, 1 or 2 children for each node

– A Balanced Binary tree has 2 children for all nodes

– A node has exactly 1 parent (except root, which has 0)

root

Item1 Item2

Item3 Item4

40 |18-Oct-21 | © Atos|Syntel Inc. - For internal use


Data Structures: Graph
▶ A Graph is built out of nodes having data as well pointers/stored indexes to the neighboring
nodes

– Tree is open loop, Graph is closed loop

– Can be implemented using Array or Linked List

– There is nothing like root for a graph

– While tree has single path from root to any node, graph can have multiple paths from one
node to another
Item5

Item1 Item2

Item4 Item3

41 |18-Oct-21 | © Atos|Syntel Inc. - For internal use


Algorithm

▶ An algorithm is

– A procedure (a finite set of well-defined instructions) for accomplishing some task which,
given an initial state, will terminate in a defined end-state

▶ A computer program is also

– An algorithm that tells the computer

• What specific steps to perform

• In what specific order

• In order to carry out a specified task (calculating employee pay checks, printing students
report cards.)

42 |18-Oct-21 | © Atos|Syntel Inc. - For internal use


Algorithm
▶ Typically, when an algorithm is associated with processing information

– Data is read from an input source or device

– Written to an output sink or device

– And/or stored for further processing

▶ Ways to express algorithm

– Human languages

– Pseudo code

– Flowcharts

– Programming languages

43 |18-Oct-21 | © Atos|Syntel Inc. - For internal use


Ways to Express Algorithm

▶ Human languages

– A language that is spoken, written, or signed (visually or tactilely) by humans for general-
purpose communication

▶ Pseudo code

– A compact and informal high-level description of a computer programming algorithm that


uses the structural conventions of programming languages, but omits detailed subroutines,
variable declarations or language-specific syntax

▶ Flowchart

– A schematic representation of an algorithm or a process

44 |18-Oct-21 | © Atos|Syntel Inc. - For internal use


Flow Control Constructs
Constructs for Flow of Control
▶ SEQUENCE is a linear progression where one task is performed sequentially after another

▶ WHILE is a loop (repetition) with a simple conditional test at its beginning

▶ IF-THEN-ELSE is a decision (selection) in which a choice is made between two alternative


courses of action

▶ REPEAT-UNTIL is a loop with a simple conditional test at the bottom

▶ CASE is a multi-way branch (decision) based on the value of an expression. CASE is a


generalization of IF-THEN-ELSE

▶ FOR is a "counting" loop

46 |18-Oct-21 | © Atos|Syntel Inc. - For internal use


SEQUENCE

▶ Sequential control is indicated by writing one action after another, each action on a line by itself,
and all actions aligned with the same indent. The actions are performed in the sequence (top to
bottom) that they are written.

▶ Example

READ height of rectangle


READ width of rectangle
COMPUTE area as height times width

47 |18-Oct-21 | © Atos|Syntel Inc. - For internal use


Common Action Keywords
▶ Input: READ, OBTAIN, GET

▶ Output: PRINT, DISPLAY, SHOW

▶ Compute: COMPUTE, CALCULATE, DETERMINE

▶ Initialize: SET, INIT

▶ Add one: INCREMENT, BUMP

48 |18-Oct-21 | © Atos|Syntel Inc. - For internal use


WHILE
▶ The WHILE construct is used to specify a loop with a test at the top. The beginning and ending of
the loop are indicated by two keywords WHILE and ENDWHILE.

▶ Example

WHILE employee.type NOT EQUAL manager AND personCount < numEmployees

INCREMENT personCount
CALL employeeList.getPerson with personCount

ENDWHILE

49 |18-Oct-21 | © Atos|Syntel Inc. - For internal use


IF-THEN-ELSE

▶ Binary choice on a given Boolean condition is indicated by the use of four keywords: IF, THEN,
ELSE, and ENDIF

▶ Example

IF HoursWorked > NormalMax THEN


Display overtime message
ELSE
Display regular time message
ENDIF

50 |18-Oct-21 | © Atos|Syntel Inc. - For internal use


REPEAT-UNTIL

▶ This loop is similar to the WHILE loop except that the test is performed at the bottom of the loop
instead of at the top. Two keywords, REPEAT and UNTIL are used.

▶ General form:
REPEAT
sequence
UNTIL condition

51 |18-Oct-21 | © Atos|Syntel Inc. - For internal use


CASE
▶ A CASE construct indicates a multi-way branch based on conditions that are mutually exclusive.
Four keywords, CASE, OF, OTHERS, and ENDCASE, and conditions are used to indicate the
various alternatives.

▶ Example

CASE grade OF
A : points = 4
B : points = 3
C : points = 2
D : points = 1
F : points = 0
ENDCASE

52 |18-Oct-21 | © Atos|Syntel Inc. - For internal use


FOR
▶ This loop is a specialized construct for iterating a specific number of times, often called a
"counting" loop. Two keywords, FOR and ENDFOR are used.

▶ Example

FOR each month of the year (good)


FOR month = 1 to 12 (ok)

FOR each employee in the list (good)


FOR empno = 1 to listsize (ok)

53 |18-Oct-21 | © Atos|Syntel Inc. - For internal use


Pseudo code
Sample Pseudocode

FOR X = 1 to 10
FOR Y = 1 to 10
IF gameBoard[X][Y] = 0
Do nothing
ELSE
CALL theCall(X, Y) (recursive method)
increment counter
END IF
END FOR
END FOR

55 |18-Oct-21 | © Atos|Syntel Inc. - For internal use


Sample Pseudocode

Set moveCount to 1
FOR each row on the board
FOR each column on the board
IF gameBoard position (row, column) is occupied THEN
CALL findAdjacentTiles with row, column
INCREMENT moveCount
END IF
END FOR
END FOR

56 |18-Oct-21 | © Atos|Syntel Inc. - For internal use


Flowcharts
Flowchart Symbols
▶ Start and end symbols, represented as rounded
rectangles
START
▶ Arrows, showing what is called "flow of control"
in computer science

▶ Processing steps, represented as rectangles.

▶ Input/Output, represented as a parallelogram


Examples: Get X from the user; display X
Add 1 to X

INPUT Y

58 |18-Oct-21 | © Atos|Syntel Inc. - For internal use


Flowchart Symbols
▶ Conditions are represented by a diamond. E.g.
Y
Yes/No question or True/False test. Is X>Y ?
▶ A document is represented by a rectangle with N

a wavy base;
Pay slip
▶ A manual input is represented by rectangle,
with the top irregularly sloping up from left to
right. E.g. data-entry from a form; Enter P.O.

▶ A manual operation is represented by a


trapezoid with the longest parallel side utmost, Authorize
Leave
to represent an operation or adjustment to
process that can only be made manually.

▶ A data file is represented by a cylinder


salesdb

59 |18-Oct-21 | © Atos|Syntel Inc. - For internal use


Sample Flowchart – Calculate Factorial

Start

READ N

M=1, F=1

F=F*M

No
M=M+1 IS M=N?

Yes

PRINT F End

60 |18-Oct-21 | © Atos|Syntel Inc. - For internal use


Flowchart – Practice Assignments

▶ Find the minimum in an Array

▶ Sort array in ascending order

▶ Stack (push & pop operations)

▶ Queue (add and remove items)

▶ A game of guessing random number generated by the computer in a finite number of attempts

61 |18-Oct-21 | © Atos|Syntel Inc. - For internal use


Files and Database
Files
▶ Files represent permanent storage of data on a secondary medium (disk/floppy)

▶ Unit of storage

– Physically as sectors (each of 512 bytes)

– Logically as clusters (each of 4 to 32 sectors depending upon OS configuration)

▶ “Opening” a file in a program results in

– Creation of a file-handle which is a pointer used to read/write data to the file

– Allocation of a memory buffer which acts as a temporary area between the program and the
file on the disk

63 |18-Oct-21 | © Atos|Syntel Inc. - For internal use


Files
▶ Modes of Opening (Read, Write, Read/Write)

▶ Type of Access (Sequential, Indexed Sequential, Random)

▶ Locking (Shared, Exclusive)

▶ Methods of reading/writing

– Text Files

• Character-by-character

• Line-by-line

• Entire contents

– Binary Files

• Byte-by-byte

• Block (record)-by-block

64 |18-Oct-21 | © Atos|Syntel Inc. - For internal use


Databases
▶ Repository of data stored and retrieved independent of the applications using them

▶ A dedicated program called Database Management System (DBMS) takes care of data storage
and retrieval

▶ Applications communicate with DBMS in a standard way to work with data without worrying
about the names and location of the files containing actual data

▶ Types of DBMS

– Hierarchical, Network, Relational (Oracle/Sybase)

65 |18-Oct-21 | © Atos|Syntel Inc. - For internal use


Databases
▶ Relational Database Management System (RDBMS)

– Logically data is viewed as tables


Program
– Tables consist of rows and columns

– One or more columns of a table can be designated as Primary Key


DBMS
– Tables can have relations

• Concept of Foreign Key: A column of one referring to another


table’s column

▶ Structured Query Language (SQL) is used to query/update the data files


– SELECT, INSERT, UPDATE, DELETE

66 |18-Oct-21 | © Atos|Syntel Inc. - For internal use


Thank you
For more information please contact:
T+ 33 1 98765432
M+ 33 6 44445678
[email protected]

Atos, the Atos logo, Atos|Syntel are registered trademarks of the Atos group. © 2021
Atos. Confidential information owned by Atos, to be used by the recipient only. This
document, or any part of it, may not be reproduced, copied, circulated and/or distributed
nor quoted without prior written approval from Atos.

You might also like