Variable Scope and Modular Programming: book back answers
20 solved questions from the end of this chapter, Class 12 Computer Science, Tamil Nadu State Board. Each answer is checked against the textbook, and you can open the page that proves it.
← Notes and quiz for Variable Scope and Modular ProgrammingChoose the best answer (1 Mark)
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
Try it, then show the answerAnswer
(A) Scope
Scope refers to the visibility of a variable from one part of a program to another.
From the book: “Scope refers to the accessibity of a variable with in one part of a program to another part of the same program.”
The process of binding a variable name with an object is called
- (A) Scope
- (B) Mapping
- (C) late binding
- (D) early binding
Try it, then show the answerAnswer
(B) Mapping
The chapter calls binding a variable name with an object mapping.
From the book: “The process of binding a variable name with an object is called mapping.”
Which of the following is used in programming languages to map the variable and object?
- (A) ::
- (B) :=
- (C) =
- (D) ==
Try it, then show the answerAnswer
(C) =
The chapter says the equal to sign is used to map a variable and object.
From the book: “= (equal to sign) is used in programming languages to map the variable and object.”
Containers for mapping names of variables to objects is called
- (A) Scope
- (B) Mapping
- (C) Binding
- (D) Namespaces
Try it, then show the answerAnswer
(D) Namespaces
Namespaces are the containers that map variable names to objects.
From the book: “Namespaces are containers for mapping names of variables to objects.”
Which scope refers to variables defined in current function?
- (A) Local Scope
- (B) Global scope
- (C) Module scope
- (D) Function Scope
Try it, then show the answerAnswer
(A) Local Scope
Variables defined in the current function are in local scope.
From the book: “Local scope refers to variables defined in current function.”
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
Try it, then show the answerAnswer
(B) Modular programming
The chapter defines modular programming as subdividing a program into separate sub-programs.
From the book: “The process of subdividing a computer program into separate sub-programs is called Modular programming.”
Which of the following security technique that regulates who canuse resources in a computing environment?
- (A) Password
- (B)Authentication
- (C) Access control
- (D) Certification
Try it, then show the answerAnswer
(C) Access control
Access control regulates who or what can view or use resources in a computing environment.
From the book: “Access control is a security technique that regulates who or what can view or use resources in a computing environment.”
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
Try it, then show the answerAnswer
(D) Private members
Private members are denied access from outside the class and can be handled only within it.
From the book: “They can be handled only from within the class.”
Which members are accessible from outside the class?
- (A) Public members
- (B)Protected members
- (C) Secured members
- (D) Private members
Try it, then show the answerAnswer
(A) Public members
Public members are accessible from outside the class.
From the book: “Public members (generally methods declared in a class) are accessible from outside the class.”
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
Try it, then show the answerAnswer
(B)Protected members
Protected members can be accessed within their class and are also available to subclasses.
From the book: “Protected members of a class are accessible from within the class and are also available to its sub-classes.”
Part - II — Answer the following questions (2 Marks)
What is a scope?
Try it, then show the answerAnswer
The scope of a variable is the part of the code where it is visible.
Scope describes where in a program a variable can be accessed.
From the book: “The scope of a variable is that part of the code where it is visible.”
Why scope should be used for variable. State the reason.
Try it, then show the answerAnswer
Scope is used to determine where a variable is visible and which scope is searched to obtain its value.
Scope helps locate a variable and resolve which value to use when names occur in different scopes.
From the book: “The LEGB rule is used to decide the order in which the scopes are to be searched for scope resolution.”
What is Mapping?
Try it, then show the answerAnswer
Mapping is the process of binding a variable name with an object.
A variable name is associated with the object it refers to.
From the book: “The process of binding a variable name with an object is called mapping.”
What do you mean by Namespaces?
Try it, then show the answerAnswer
Namespaces are containers for mapping names of variables to objects.
They keep track of variable-name-to-object mappings.
From the book: “Namespaces are containers for mapping names of variables to objects.”
How Python represents the private and protected Access specifiers?
Try it, then show the answerAnswer
Python uses a convention of prefixing a variable or method name with a single or double underscore to emulate protected and private access specifiers.
The underscores represent a convention; the chapter notes that Python does not effectively restrict access to instance variables or methods.
From the book: “Python prescribes a convention of prefixing the name of the variable or method with single or double underscore”
Part - III — Answer the following questions (3 Marks)
Define Local scope with an example.
Try it, then show the answerAnswer
Local scope refers to variables defined in the current function. For example, in Disp(): a:=7; print a, a is local to Disp().
A function first looks for a variable in its local scope. The chapter's example defines a inside Disp() and displays its value there.
From the book: “Local scope refers to variables defined in current function.”
Define Enclosed scope with an example.
Try it, then show the answerAnswer
Enclosed scope is the scope of a variable declared in an outer function that can also be accessed by an inner function. For example, if Disp() defines a:=10 and defines Disp1() inside it, Disp1() can print a.
The inner function can access a variable belonging to its enclosing function.
From the book: “the inner function can also access the variable of the outer function. This scope is called enclosed scope.”
Why access control is required?
Try it, then show the answerAnswer
Access control regulates who or what can view or use resources in a computing environment and minimizes risk to the object.
It selectively restricts access to data and resources as a security measure.
From the book: “It is a fundamental concept in security that minimizes risk to the object.”
Part - IV — Answer the following questions (5Marks)
Write any Five Characteristics of Modules.
Try it, then show the answerAnswer
A module is a part of a program. The following are the desirable characteristics of a module.
- Contains program elements: A module contains instructions, processing logic, and data.
- Can be compiled separately: Modules can be compiled separately and stored in a library.
- Can be included in a program: A module can be included in a program.
- Can be invoked: Module segments can be used by invoking a name and some parameters.
- Can be used by other modules: The segments of a module can also be used by other modules.
Example: Procedures, subroutines, and functions are examples of modules.
These characteristics allow modules to be used independently and together in programs.
From the book: “Modules contain instructions, processing logic, and data.”
Write any five benefits in using modular programming.
Try it, then show the answerAnswer
Modular programming is the process of dividing a computer program into separate sub-programs called modules. The chapter lists several benefits of using this approach.
- Less code and reuse: A procedure can be developed once and reused, so the same code does not need to be written repeatedly.
- Easier program design: A small team can work on a small part of the whole program, making the program easier to design.
- Programmer collaboration: Modular programming allows several programmers to work together on the same application.
- Easy to understand: The code is short and simple, which makes it easier to understand.
- Easier error identification: Errors are localized to a subroutine or function, so they can be identified easily.
Example: The chapter gives procedures, subroutines, and functions as examples of modules.
Thus, modular programming supports reuse, collaboration, simpler code, and easier debugging.
From the book: “Errors can easily be identified, as they are localized to a subroutine or function.”