Presentation is loading. Please wait.

Presentation is loading. Please wait.

PROBLEM SOLVING TECHNIQUES

Similar presentations


Presentation on theme: "PROBLEM SOLVING TECHNIQUES"— Presentation transcript:

1 PROBLEM SOLVING TECHNIQUES
UNIT - 01 PROBLEM SOLVING TECHNIQUES R.Sreenivasan Computer Teacher Santhome Higher Secondary School Chennai

2 CHAPTER - 03 SCOPING

3 CONTENTS SCOPING MAPPING NAMESPACES LEGB RULE MODULES
MODULAR PROGRAMMING ACCESS CONTROL

4 WHAT IS SCOPE ?

5 SCOPE Scope refers to the visibility of variables, parameters and functions in one part of a program to another part of the same program. In other words, which parts of your program can see or use it.

6 VARIABLE SCOPE To understand the scope of variables in a programming language, it is important to learn about what variables really are. Essentially, they're addresses (references, or pointers), to an object in memory.

7 MAPPING The process of binding a variable name with an object is called mapping. = (equal to sign) is used in programming languages to map the variable and object.

8 NAMESPACES Namespaces are containers for mapping names of variables to objects. You can think of them as dictionaries, containing list of words and its meanings. The words are mapped with its meaning in dictionaries whereas names are mapped with objects (name : = object) in programming language.

9 LIFE TIME OF VARIABLES The duration for which a variable is alive is called its ‘life time’ of the variable .

10 LEGB RULE LEGB rule: When a name is encountered during the execution of the program, it searches for that name in the order of Local, Enclosed Global , Built in scope

11 TYPES OF VARIABLE SCOPES
The LEGB rule is used to decide the order in which the scopes are to be searched for scope resolution. The scopes are listed below in terms of hierarchy (highest to lowest).

12 TYPES OF VARIABLE SCOPES
Local(L) Defined inside function/class Enclosed(E) Defined inside enclosing functions (Nested function concept) Global(G) Defined at the uppermost level Built-in (B) Reserved names in built-in functions (modules)

13 LOCAL SCOPE Local scope refers to variables defined in current function. Always, a function will first look up for a variable name in its local scope. Only if it does not find it there, the outer scopes are checked.

14 EXAMPLE 1. Disp (): 2. a:=7 3. print a 4. Disp () OUTPUT 7 Disp() a:=7

15 GLOBAL SCOPE A variable which is declared outside of all the functions in a program is known as global variable. This means, global variable can be accessed inside or outside of all the functions in a program.

16 EXAMPLE 1. a:=10 2. Disp(): 3. a:=7 4. print a 5. Disp() 6. print a
OUTPUT 7 10 a:=10 Disp() a:=7 Print a Disp1(): Print a

17 ENCLOSED SCOPE A variable which is declared inside a function which contains another function definition with in it, the inner function can also access the variable of the outer function. This scope is called enclosed scope.

18 EXAMPLE 1. Disp(): OUTPUT 2. a:=10 3. Disp1(): 4. print a 10

19 BUILT IN SCOPE Any variable or module which is defined in the library functions of a programming language has Built-in or module scope.

20 EXAMPLE 1. a:=10 2. Disp(): 3. a:=7 Library files associated
4. print a 5. Disp() 6. print a Disp () Library files associated with the software D disp 1( ): print a Disp() Disp 1( ): print a Disp()

21 EXAMPLE PYTHON PROGRAM :
# Global scope x = 0 def outer(): # Enclosed scope x = 1 def inner(): # Local scope x = 2

22 MODULE A module is a part of a program.
Programs are composed of one or more independently developed modules.

23 EXAMPLES OF MODULES The examples of modules are
procedures , subroutines and functions.

24

25 MODULAR PROGRAMMING The process of subdividing a computer program into separate sub-programs is called Modular programming.

26

27 CHARACTERISTICS OF MODULES
Modules contain instructions, processing logic, and data. Modules can be separately compiled and stored in a library. Modules can be included in a program. Module segments can be used by invoking a name and some parameters. Module segments can be used by other modules.

28 BENEFITS OF MODULAR PROGRAMMING
Less code to be written. A single procedure can be developed for reuse, eliminating the need to retype the code many times. Programs can be designed more easily because a small team deals with only a small part of the entire code.

29 BENEFITS OF MODULAR PROGRAMMING ( cont. )
Modular programming allows many programmers to collaborate on the same application. The code is stored across multiple files. Code is short, simple and easy to understand.

30 BENEFITS OF MODULAR PROGRAMMING ( cont. )
Errors can easily be identified, as they are localized to a subroutine or function. The same code can be used in many applications. The scoping of variables can easily be controlled.

31 ACCESS CONTROL Access control is a security technique that regulates who or what can view or use resources in a computing environment. It is a fundamental concept in security that minimizes risk to the object.

32 ACCESS MODIFIERS In object-oriented languages, such as C++ and Java, control the access to class members by public, private and protected keywords.

33 PUBLIC MEMBERS Public members (generally methods declared in a class) are accessible from outside the class. The object of the same class is required to invoke a public method.

34 PRIVATE MEMBERS This arrangement of private instance variables and public methods ensures the principle of data encapsulation.

35 PROTECTED MEMBERS Protected members of a class are accessible from within the class and are also available to its sub-classes. No other process is permitted access to it. This enables specific resources of the parent class to be inherited by the child class.

36 Representation of the private and protected Access specifiers in python
Python prescribes a convention of prefixing the name of the variable or method with single or double underscore to emulate the behaviour of protected and private access specifiers.

37 conclusion All members in Python class are public by default, whereas by default in C++ and java they are private.

38 SUMMARY Scope refers to the visibility of variables, parameters and functions in one part of a program to another part of the same program. The LEGB rule is used to decide the order in which the scopes are to be searched for scope resolution.

39 SUMMARY ( cont.) The process of subdividing a computer program into separate sub-programs is called Modular programming. Access control is a security technique that regulates who or what can view or use resources in a computing environment. It is a fundamental concept in security that minimizes risk to the object.

40


Download ppt "PROBLEM SOLVING TECHNIQUES"

Similar presentations


Ads by Google