Tamilnadu State Board New Syllabus Samacheer Kalvi 12th Computer Science Guide Pdf Chapter 3 Scoping Text Book Back Questions and Answers, Notes.
Tamilnadu Samacheer Kalvi 12th Computer Science Solutions Chapter 3 Scoping
12th Computer Science Guide Scoping Text Book Questions and Answers
I. Choose the best answer (I Marks)
Question 1.
Which of the following refers to the visibility of variables in one part of a program to another part of the same program.
a) Scope
b) Memory
c) Address
d) Accessibility
Answer:
a) Scope
Question 2.
The process of binding a variable name with an object is called
a) Scope
b) Mapping
c) late binding
d) early binding
Answer:
b) Mapping
Question 3.
Which of the following is used in programming languages to map the variable and obj ect?
a) ::
b) :=
c) =
d) ==
Answer:
c) =
Question 4.
Containers for mapping names of variables to objects is called
a) Scope
b) Mapping
c) Binding
d) Name spaces
Answer:
d) Name spaces
Question 5.
Which scope refers to variables defined in current function?
a) Local Scope
b) Global scope
c) Module scope
d) Function Scope
Answer:
a) Local Scope
Question 6.
The process of subdividing a computer program into separate sub-programs is called
a) Procedural Programming
b) Modular programming
c) Event Driven Programming
d) Object oriented Programming
Answer:
b) Modular programming
Question 7.
Which of the following security technique that regulates who can use resources in a computing environment?
a) Password
b) Authentication ‘
c) Access control
d) Certification
Answer:
c) Access control
Question 8.
Which of the following members of a class can be handled only from within the class?
a) Public members
b) Protected members
c) Secured members
d) Private members
Answer:
d) Private members
Question 9.
Which members are accessible from outside the class?
a) Public members
b) Protected members
c) Secured members
d) Private members
Answer:
a) Public members
Question 10.
The members that are accessible from within the class and are also available to its sub classes is called
a) Public members
b) Protected members
c) Secured members
d) Private members
Answer:
b) Protected members
II. Answer the following questions (2 Marks)
Question 1.
What is a scope?
Answer:
Scope refers to the visibility of variables, parameters, and functions in one part of a program to another part of the same program.
Question 2.
Why scope should be used for variables. State the reason
Answer:
- Every variable defined in a program has global scope.
- Once defined, every part of your program can access that variable.
- But it is a good practice to limit a variable’s scope to a single definition.
- This way, changes inside the function can’t affect the variable on the outside of the function in unexpected ways.
Question 3.
What is Mapping?
Answer:
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.
Question 4.
What do you mean by Namespaces?
Answer:
Names paces are containers for mapping names of variables to objects.
Question 5.
How Python represents the private and protected Access specifiers?
Answer:
Private members of a class are denied access from the outside of the class. They can be handled only within the class.
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.
III. Answer the following questions (3 Marks)
Define Local scope with an example.
Answer:
Local scope:
- Local scope refers to variables defined in the current function.
- Always, a function will first lookup for a variable name in its local scope.
- Only if it does not find it there, the outer scopes are checked.
Example:
- On execution of the above code, the variable a displays the value 7, because it is defined and available in the local scope.
Question 2.
Define Global scope with an example
Answer:
Global variable:
- A variable which is declared outside of all the functions in a program is known as Global variable.
- Global variable can be accessed inside or outside of all the functions in a program
Example:
- On execution of the above code the variable a which is defined inside the, function displays the value 7 for the function call Disp() and then it displays 10, because a is defined in global scope.
Question 3.
Define Enclosed scope with an example
Answer:
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.
- When a compiler or interpreter search for a variable in a program, it first searches Local, and then searches Enclosing scopes.
Example:
Question 4.
Why access control is required?
Answer:
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. In other words, access control is a selective restriction of access to data.
In Object-oriented programming languages, it is implemented through access modifies.
Classical object-oriented languages, such as C++ and Java, control the access to class members by the public, private, and protected keywords.
Question 5.
Identify the scope of the variables in the following pseudo-code and write its output
color:= Red
mycolor():
b:=Blue
myfavcolor():
g:=Green
printcolor, b, g
myfavcolor()
printcolor, b
mycolor()
print color
Answer:
Scopes:
g – Local scope
b – Enclosed scope
color – Global scope
Output:
Red Blue Green
Red Blue
Red
IV. Answer the following questions (5 Marks)
Question 1.
Explain the types of scopes for variable or LEGB rule with example.
Answer:
Types of Scope:
There are four types of Scope namely
Local Scope, Global Scope, Enclosed Scope and Built-in Scope:
Local Scope:
- Local scope refers to variables defined in the current function.
- Always, a function will first lookup for a variable name in its local scope.
- Only if it does not find it there, the outer scopes are checked.
Example:
- On execution of the above code the variable a displays the value 7, because it is defined and available in the local scope.
Global Scope:
- A variable which is declared outside of all the functions in a program is known as a global variable.
- This means global variable can be accessed inside or outside of all the functions in a program.
Example:
- On execution of the above code the variable ‘a’ which is defined inside the function displays the value 7 for the function call Disp() and then it displays 10; because a is defined in global scope.
- Enclosed Scope:
- All programming languages permit functions to be nested. A function (method) with in another function is called nested function.
- 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.
- When a compiler or interpreter search for a variable in a program, it first search Local, and then search Enclosing scopes.
Example:
- In the above example Displ() is defined with in Disp().
- The variable ‘a’ defined in Disp( ) can be even used by Displ( ) because it is also a member of Disp().
Built-in Scope:
- The built-in scope has all the names that are pre-loaded into the program scope when we start the compiler or interpreter.
- Any variable or module which is defined in the library functions of a programming
language has a Built-in or module scope. They are loaded as soon as the library files are imported to the program.
LEGB rule:
- 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).
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) |
Scope also defines the order in which variables have to be mapped to the object in order to obtain the value.
Example:
1. x:= ‘outer x variable’
2. display ():
3. x:= ‘inner x variable’
4. print x
5. display()
- When the above statements have executed the statement (4) and (5) display the result as
Output:
outer x variable
inner x variable
- Above statements give different outputs because the same variable name ‘x’ resides in different scopes, one inside the function display() and the other in the upper level.
- The value ‘outer x variable’ is printed when x is referenced outside the function definition.
- Whereas when display() gets executed, ‘inner x variable’ is printed which is the x value inside the function definition.
- From the above example, we can guess that there is a rule followed, in order to decide from which scope a variable has to be picked.
Question 2.
Write any Five Characteristics of Modules
Answer:
- 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.
Question 3.
Write any five benefits of using modular programming.
Answer:
- 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.
- 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.
- 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.
12th Computer Science Guide Scoping Additional Questions and Answers
I. Choose the best answer (1 Mark)
Question 1.
Names paces are compared with ……………………….
(a) Programs
(b) Dictionaries
(c) Books
(d) Notebooks
Answer:
(b) Dictionaries
Question 2.
The scope of a ……………. is that part of the code where it is visible
a) Variable
b) Keyword
c) Function
d) Operator
Answer:
a) Variable
Question 3.
Find the value of a.
1. a: = 5
2. b: = a
3. a: = 3
(a) 0
(b) 3
(c) 5
(d) 2
Answer:
(b) 3
Question 4.
The inner function can access the variable of the outer function. This is called ………… scope.
a) Local
b) Enclosed
c) Function
d) Global
Answer:
b) Enclosed
Question 5.
The duration for which a variable is alive is called its ……………………………
(a) Scale
(b) Life time
(c) Static
(d) Function
Answer:
(b) Lifetime
Question 6.
InObjectOrientedProgrammingLanguageAccesscontrolisimplementedthrough ………….
a) Access modules
b) Access modifiers
c) Access variables
d) Keywords
Answer:
b) Access modifiers
Question 7.
………… is a selective restriction of access to data in a program?
a) Control variable
b) Access control
c) System authentication
d) Module
Answer:
b) Access control
Question 8.
How many types of variable scopes are there?
(a) 1
(b) 2
(c) 3
(d) 4
Answer:
(d) 4
Question 9.
How many variables can be mapped to the same instance?
a) 2
b) 3
c) Multiple
d) 4
Answer:
c) Multiple
Question 10.
A variable which is declared outside of all the functions in a program is known as …………………………… variable.
(a) L
(b) E
(c) G
(d) B
Answer:
(c) G
Question 11.
Which of the following rule is used to decide the order in which the scopes are to be searched for scope resolution?
a) LGEB
b) LEGB
c) LBEG
d) LGBE
Answer:
b) LEGB
Question 12.
How many types of variable scope are there?
a) 2
b) 3
c) 4
d) 6
Answer:
c) 4
Question 13.
A variable which is declared outside all the functions in a program is known as
a) Local
b) Enclosed
c) Global
d) Extern
Answer:
c) Global
Question 14.
The scope of a nested function is …………………………… scope
(a) Local
(b) Global
(c) Enclosed
(d) Built-in
Answer:
(c) Enclosed
Question 15.
Which of the following programming enables programmers to divide up the work and retry pieces of the program independently?
a) Procedural Programming
b) Modular Programming
c) Object-Oriented Programming
d) Structural Programming
Answer:
b) Modular Programming
Question 16.
Which of the following contain instructions, processing logic, and data?
a) Scopes
b) Indentation
c) Modules
d) Access control
Answer:
c) Modules
Question 17.
Which of the following members of a class are denied access from outside the class?
a) Protected
b) Private
c) Public
d) Enclosed
Answer:
b) Private
Question 18.
Variables of built-in scopes are loaded as …………………………… files.
(a) Exe
(b) Linker
(c) Object
(d) Library
Answer:
(d) Library
Question 19.
By default the Python class members are
a) Private
b) Protected
c) Public
d) Global
Answer:
c) Public
Question 20.
By default the C++ and Java class members are
a) Protected
b) Private
c) Public
d) Local
Answer:
b) Private
Question 21.
…………….. are composed of one or more independently developed Modules
a)’Access control
b) Programs
c) Encapsulation
d) Members of a class
Answer:
b) Programs
Question 22.
Identify which is not a module?
(a) Algorithm
(b) Procedures
(c) Subroutines
(d) Functions
Answer:
(a) Algorithm
II. Answer the following questions (2 and 3 Marks)
Question 1.
Define variable.
Answer:
Variable are addresses (references, or pointers, to an object in memory.
Question 2.
Define lifetime?
Answer:
The duration for which a variable is alive is called its ‘lifetime’.
Question 3.
Define Modular programming.
Answer:
The process of subdividing a computer program into separate sub-programs is called modular programming.
Question 4.
Define: module
Answer:
- A module is a part of a program.
- Programs are composed of one or more independently developed modules
Question 5.
Define nested function.
Answer:
A function (method) within another function is called a nested function.
Question 6.
Write a note on module
Answer:
- A module is a part of a program.
- Programs are composed of one or more independently developed modules.
- A single module can contain one or several statements closely related to each other.
- Modules work perfectly on an individual level and can be integrated with other modules.
- A software program can be divided into modules to ease the job of programming and debugging as well.
- A program can be divided into small functional modules that work together to get the output.
- The process of subdividing a computer program into separate subprograms is called Modular programming.
- Modular programming enables programmers to divide up the work and debug pieces of the program independently.
- The examples of modules are procedures, subroutines, and functions.
Question 7.
Write a note on modules?
Answer:
A module is a part of a program. Programs are composed of one or more independently developed modules. A single module can contain one or several statements closely related to each other. Modules work perfectly on an individual level and can be integrated with other modules.
III. Answer the following questions (5 Marks)
Question 1.
Explain how Access Specifiers are activated in Python, C++, and Java:
Answer:
- Python prescribes a convention of prefixing the name of the variable/ method with a single or double underscore to emulate the behaviour of protected and private access specifiers.
- C++ and Java, control the access to class members by the public, private, and protected
keywords. - All members in a Python class are public by default whereas by default in C++ and java all members are private.
- Any member can be accessed from outside the class environment in Python which is not. possible in C++ and java.