12th Standard Syllabus & Materials
12th Standard
TN 12th Computer Applications மின்னணு தரவு பரிமாற்றம் Sample Question Papers Study Material - QB365 Set A
NEW12th Standard
TN 12th Computer Applications மின் - வணிக பாதுகாப்பு அமைப்புகள் Sample Question Papers Study Material - QB365 Set A
NEW12th Standard
TN 12th Computer Applications மின்னணு செலுத்தல் முறைகள் Sample Question Papers Study Material - QB365 Set A
NEW12th Standard
TN 12th Computer Applications மின் - வணிகம் Sample Question Papers Study Material - QB365 Set A
NEW12th Standard
TN 12th Computer Applications திறந்த மூல கருத்துருக்கள் Sample Question Papers Study Material - QB365 Set A
NEW12th Standard
TN 12th Computer Applications வலையமைப்பு வடமிடல் Sample Question Papers Study Material - QB365 Set A

Published on: 27/02/2021
12th Standard English Medium Computer Science Reduced Syllabus Five Mark important Questions With Answer Key - 2021(Public Exam )
Download Tamil Nadu 12th Standard Computer Science question papers, model tests, one-mark questions, important questions, and public exam papers in PDF format. Free study materials and answer keys for TN State Board students.
Questions + Answers key
Take MCQ Computer Science Test

1.
Write a python program to find Fibonacci series of n terms using recursion.
2.
Explain different types arguments used in python with an example.
3.
Explain remove (), pop () and clear () used in list with an example.
4.
Explain the sorting algorithm that uses n-1 number passes to get the final sorted list.
5.
Define efficiency of an algorithm? How the efficiency of an algorithm was determined?
6.
Explain the representation of Abstract datatype using rational numbers.
7.
Write any 5 features of Python.
8.
Differentiate Excel file and CSV file.
9.
What are the components of SQL? Write the commands in each.
10.
Explain the characteristics of DBMS.
11.
Differentiate DBMS and RDBMS.
12.
What is nested tuple? Explain with an example.
13.
What the different ways to insert an element in a list. Explain with suitable example.
14.
Explain about string operators in python with suitable example.
15.
Explain the different types of function with an example.
16.
Write a program to display multiplication table for a given number.
17.
Explain the Bubble sort algorithm with example.
18.
What is Binary search? Discuss with example
19.
Explain the characteristics of an algorithm.
20.
Describe in detail the procedure Script mode programming.
21.
Write any Five Characteristics of Modules.
22.
Explain the types of scopes for variable or LEGB rule with example.
23.
What is a List? Why List can be called as Pairs. Explain with suitable example.
24.
How will you facilitate data abstraction. Explain it with suitable example.
25.
Explain with example Pure and impure functions.
1.
# program to find fibonacci series
def fibo (n):
if n < = 1:
return n
else:
return (fibo (n - 1) + fibo (n - 2))
n = int (input ("Enter How manu terms"))
for i in range (n):
print (fibo (i))
2.
(i) Required Arguments:
"Required Arguments" are the arguments passed to a function in correct positional order. Here, the number of arguments in the function call should match exactly with the function definition. Atleast one parameter to prevent syntax errors to get the required output.
(ii) Example:
def printstring(str):
print ("Example - Required arguments")
print (str)
return
# Now you can call printstring() function
printstring ("Welcome")
Output:
Example - Required arguments
Welcome
(iii) When the above code is executed, it produces the following error.
Traceback (most recent call last):
File "Req-arg.py", line 10, in
printstring()
TypeError: printstring() missing 1 required positional argument: 'str'
(iv) Instead of printstring() in the above code if we use printstring ("Welcome") then the output is
Output:
Example - Required arguments
Welcome
Keyword Arguments:
Keyword arguments will invoke the function after the parameters are recognized by their parameter names. The value of the keyword argument is matched with the parameter name and so, one can also put arguments in improper order (not in order).
(ii) Example:
def printdata (name):
print ("Example-1 Keyword arguments")
print ("Name :":name)
return
# Now you can call printdatat() function
printdata(name = "Gshan")
(iii) When the above code is executed, it produces the following output:
Output:
Example-1 Keyword arguments
Name:Gshan
Default Arguments:
In Python the default argument is an argument that takes a default value if no value is provided in the function call. The following example uses default arguments, that prints default salary when no argument is passed.
Example:
def printinfo( name, salary = 3500):
print ("Name: ", name)
print ("Salary: ", salary)
return
printinfo("Mani")
(iii) When the above code is executed, it produces the following output
Output:
Name: Mani
Salary: 3500
(iv) When the above code is changed as print info("Ram,":2000) it produces the following output:
Output:
Name: Ram
Salary: 2000
Syntax - Variable-Length Arguments:
(i) def function_name(*args):
function_body
return_statement
(ii) Example:
def printnos (*nos):
for n in nos:
print(n)
return
# now invoking the printnos() function
print ('Printing two values')
printnos (1,2)
print ('Printing three values')
printnos (10,20,30)
Output:
Printing two values
1
2
Printing three values
10
20
30
3.
remove ( ):
(i) The remove( ) function can also be used to delete one or more elements if the index value is not known.
(ii) Syntax:
List.remove(element) # to delete a particular element
(iii) Example:
> > > MyList= [12,89,34,'Kannan', 'Gowri sankar', 'Lenin']
> > > print(MyList)
[12, 89, 34, 'Karman', 'Gowrisankar', 'Lenin')
> > > MyList.remove(89)
> > > print(MyList)
[12, 34, 'Karman', 'Gowrisankar', 'Lenin']
pop ():
(i) pop() function can also be used to delete an element using the given index value. pope ) function deletes and returns the last element of a list if the index is not given.
(ii) pop() function is used to delete a particular element using its index value, as soon as the element is deleted.
(iii) The pop( ) function shows the element which is deleted. pope ) function is used to delete only one element from a list. Remember that, del statement deletes multiple elements.
(iv) Syntax: List.pop(index of an element)
(v) Example:
> > > MyList.pop(1)
34
> > > print(MyList)
[12, 'Kannan', 'Gowrisankar', 'Lenin')
clear ():
(i) The function clear( ) is used to delete all the elements in list, it deletes only the elements and retains the list
(ii) clear() function removes only the elements and retains the list. When you try to print the list which is already cleared, an empty square bracket is displayed without any elements, which means the list is empty.
(iii) Syntax:
List.clear( )
Example:
> > > MyList.clear( )
> > > print(MyList)
[ ]
4.
(i) Insertion sort is a simple sorting algorithm. It works by taking elements from the list one by one and inserting then in their correct position in to a new sorted list.
(ii) This algorithm builds the final sorted array at the end. This algorithm uses n-1 number of passes to get the final sorted list as per the pervious algorithm as we have discussed.
Pseudo for Insertion sort:
Step 1 - If it is the first element, it is already sorted.
Step 2 - Pick next element
Step 3 - Compare with all elements in the sorted sub-list
Step 4 - Shift all the elements in the sorted sublist that is greater than the value to be sorted Step 5 - Insert the value Step 6 - Repeat until list is sorted.
5.
(i) Computer resources are limited that should be utilized efficiently. The efficiency of an algorithm is defined as the number of computational resources used by the algorithm.
(ii) An algorithm must be analyzed to determine its resource usage. The efficiency of an algorithm can be measured based on the usage of different resources.
(iii) For maximum efficiency of algorithm we wish to minimize resource usage. The important resources such as time and space complexity cannot be compared directly, so time and space complexity could be considered for an algorithmic efficiency.
Method for determining Efficiency:
(i) The efficiency of an algorithm depends on how efficiently it uses time and memory space.
(ii) The time efficiency of an algorithm is measured by different factors. For example, write a program for a defined algorithm, execute it by using any programming language, and measure the total time it takes to run.
(iii) The execution time that you measure in this case would depend on a number of factors such as: -
1. Speed of the machine
2. Compiler and other system Software tools
3. Operating System
4. Programming language used
5. Volume of data required
(iv) However, to determine: how efficiently an algorithm solves a given problem, you would like to determine how the execution time is affected by the nature of the algorithm.
(v) Therefore, we need to develop fundamental laws that determine the efficiency of a program in terms of the nature of the underlying algorithm.
6.
(i) The basic idea of data abstraction is to structure programs so that they operate on abstract data. That is, our programs should use data in such a way, as to make as few assumptions about the data as possible.
(li) At the same time, a concrete data representation is defined as an independent part of the program.
(iii) Any program consist of two parts. The two parts of a program are, the part that operates on abstract data and the part that defines a concrete representation, is connected by a small set of functions that implement abstract data in terms of the concrete representation.
(iv) To illustrate this technique, let us consider an example to design a set of functions for manipulating rational numbers.
(v) Example: A rational number is a ratio of integers, and rational numbers constitute an important sub-class of real numbers. A rational number such as 8/3 or 19/23 is typically written as : < numerator > /< denominator >
(vi) where both the < numerator > and <denominator>
(vii) However, you can create an exact representation for rational numbers by combining together the numerator and denominator.
(viii) As we know from using functional abstractions, we can start programming productively before you have an implementation of some parts of our program.
(ix) Let us begin by assuming that you already have a way of constructing a rational number from a numerator and a denominator. You also assume that, given a rational number, you have a way of selecting its numerator and its denominator component.
7.
(i) Python uses Automatic Garbage Collection whereas C++ does not.
(ii) C++ is a statically typed language, while Python is a dynamically typed language.
(iii) Python runs through an interpreter, while C++ is pre-compiled.
(iv) Python code tends to be 5 to 10 times shorter than that written in C++.
(v) In Python, there is no need to declare types explicitly where as it should be done in C++.
(vi) In Python, a function may accept an argument of any type, and return multiple values without any kind of declaration beforehand. Whereas in C++ return statement can return only one value.
8.
| Excel | CSV |
|---|---|
| Excel is a binary file that holds information about all the worksheets in a file, including both content and formatting | CSV format is a plain text format with a series of values separated by commas. |
| XLS files can only be read by applications that have been especially written to read their format, and can only be written in the same way. | CSV can be opened with any text editor in Windows like notepad, MS Excel, Open Office, etc. |
| Excel is a spreadsheet that saves files into its own proprietary format viz. xls or xlsx | CSV is a format for saving tabular information into a delimited text file with extension .csv |
| Excel consumes-more memory while importing data | Importing CSV files can be much faster, and it also consumes less memory |
9.
SQL commands are divided into five categories:
Data Definition Language:
(i) The Data Definition Language (DDL) consist of SQL statements used to define the database structure or schema.
(ii) It simply deals with descriptions of the database schema and is used to create and modify the structure of database objects in databases.
(iii) The DDL provides a set of definitions to specify the storage structure and access methods used by the database system.
DDL performs the following functions:
(i) It should identify the type of data division such as data item, segment, record and database file.
(ii) It gives a unique name to each data item type, record type, file type and data base.
(iii) It should specify the proper data type.
(iv) It should define the size of the data item.
(v) It may define the range of values that a data item may use.
(vi) It may specify privacy locks for preventing unauthorized data entry.
Commands:
| CREATE | To create tables in the database. |
| ALTER | Alters the structure of the database |
| DROP | Data tables from database. |
| TRUNCATE | Remove all records from a table, also release the space occupied bv those records. |
Data Manipulation Language:
This is a computer programming language used for adding, removing and modifying data in a database. This language comprises the SQL-data change statements, which modify stored data but not the schema of the database table
Data Manipulation includes
(i) Insertion of new information into the database
(ii) Retrieval of information stored in a database
(iii) Deletion of information from the database.
(iv) Modification of data stored in the database
The DML is basically of two types:
Procedural DML - Requires a user to specify what data is needed and how to get it.
Non-Procedural DML - Requires a user to specify what data is needed without Specifying how to get it.
Commands:
| INSERT | Inserts data into a table |
| UPDATE | Updates the existing data within a table |
| DELETE | Deletes all records from a table, but not the space occupied by them. |
Data Control Language:
(i) A Data Control Language (DCL) is a programming language used to control the access of data stored in a database. It is used for controlling privileges in the database (Authorization).
(ii) The privileges are required for performing all the database operations such as creating sequences, views of tables etc.
Commands:
| GRANT | Grants permission to one or more users to perform specific tasks. |
| REVOKE | Withdraws the access permission given by the GRANT statement. |
Transactional Control Language:
Transactional control language (TCL) commands are used to manage transactions in the database. These are used to manage the changes made to the data in a table by DML statements.
Commands:
| COMMIT | Saves any transaction into the database permanently. |
| ROLL BACK | Restores the database to last commit state. |
| SAVE POINT | Temporarily save a transaction so that you can rollback. |
Data query language:
The Data Query Language consist of commands used to query or retrieve data from a database. One such SQL command in Data Query Language is
| SELECT | It displays the records from the table. |
10.
Characteristics of Database Management System
| 1. Data stored into Table | Data is never directly stored into the database. Data is stored into tables, created inside the database. DBMS also allows to have relationship between tables which makes the data more meaningful and connected. |
| 2. Reduced Redundancy | In the modern world hard drives are very cheap, but earlier when hard drives were too expensive, unnecessary repetition of data in database was a big problem But DBMS follows Normalisation which divides the data in such a way that repetition is minimum. |
| 3. Date Consistency | On live data, it is being continuously updated and added, maintaining the consistency of data can become a challenge. But DBMS handles it by itself. |
| 4. Support Multiple user and Concurrent Access | DBMS allows multiple users to work on it( update, insert, delete data) at the same time and still manages to maintain the data consistency. |
| 5. Query Language | DBMS provides users with a simple query language, using which data can be easily fetched, inserted, deleted and updated in a database. |
| 6. Security | The DBMS also takes care of the security of data, protecting the data from unauthorized access. In a typical DBMS, we can create user accounts with different access permissions, using which we can easily secure our data by restricting user access. |
| 7. DBMS Supports Transactions | It allows us to better handle and manage data integrity in real world applications where multi-threading is extensively used. |
11.
| Basis of Comparison | DBMS | RDBMS |
|---|---|---|
| Expansion | Database Management System | Relational Database Management System |
| Data storage | Navigational model ie data by linked records | Relational model (in tables). ie data in tables as row and column |
| Data redundancy | Exhibit | Not Present |
| Normalization | Not performed | RDBMS uses normalization to reduce redundancy |
| Data access | Consumes more time | Faster, compared to DBMS. |
| Keys and indexes | Does not use. | used to establish relationship. Keys are used in RDBMS. |
| Transaction management | Inefficient, Error prone and insecure | Efficient and secure |
| Distributed Databases | Not supported | Supported by RDBMS. |
| Example | Dbase, FoxPro. | SQL server, Oracle, mysql, MariaDB, SQLite. |
12.
In Python, a tuple can be defined inside another tuple; called Nested tuple. In a nested tuple, each tuple is considered as an element. The for loop will be useful to access all the elements in a nested tuple.
Example:
Toppers = (("Vinodini", "XII-F", 98.7), ("Soundarya", "XII-H", 97.5),
("Tharani", "XII-F", 95.3), ("Saisri", "XII-G", 93.8))
for i in Toppers:
print(i)
Output:
('Vinodini', 'XII-F', 98.7)
('Soundarya', 'XII-H', 97.5)
('Tharani', 'XII-F', 95.3)
('Saisri', 'XII-G', 93.8)
13.
Inserting elements in a list using insert ( ) :
(i) append ( ) function in Python is used to add more elements in a list. But, it includes elements at the end of a list.
(ii) If you want to include an element at your desired position, you can use insert ( ) function. The insert ( ) function is used to insert an element at any position of a list.
Syntax :
List.insert (position index, element)
Example :
>>> MyList=[34,98,47, Kannan,Gowrisankar','Lenin', 'Sreenivasan' ]
>>> print(MyList)
[34, 98, 47, 'Kannan', 'Gowrisankar', 'Lenin', 'Sreenivasan']
>>> MyList.insert(3, 'Ramakrishnan')
>>> print(MyList)
[34, 98, 47, 'Ramakrishnan', 'Kannan', 'Gowrisankar, 'Lenin', 'Sreenivasan']
Output : [34, 98, 47, 'Ramakrishnan', 'Kannan', 'Gowrisankar', 'Lenin', 'Sreenivasan']
(i) In the above cxample, insert( ) function inserts a new element 'Ramakrishnan' at the index value 3, ie. at the 4th position.
(ii) While inserting a new element in between the existing elements, at a particular location, the existing elements shifts one position to the right.
14.
String Operators:
Python provides the following operators for string operations. These operators are useful to manipulate string.
(i) Concatenation (+):
Joining of two or more strings is called as Concatenation. The plus (+) operator is used to concatenate strings in python.
Example:
>>> "welcome" + "Python"
'welcome python'
(ii) Append (+ =):
Adding more strings at the end of an existing string is known as append. The operator += is used to append a new string with an existing string.
Example:
>>> str1 = "welcome to"
>>> str1 + = "Learn Python"
>>> print (str1)
Welcome to Learn Python
(iii) Repeating (*):
The multiplication operator (*) is used to display a string in multiple number of times.
Example:
>>> str1= "welcome "
>>> print (str1 *4)
Welcome Welcome Welcome Welcome
(iv) String slicing:
Slice is a substring of a main string.
A substring can be taken from the original string by using [ ] operator and index or subscript values. Thus [ ] is also known as slicing operator. Using slice operator, we have to slice one or more substrings from a main string.
General format of slice operation:
str[start:end]
Where start is the beginning index and end is the last index value of a character in the string. Python takes the end value less than one from the actual index specified.
Example: I
Slice a single character from a string
>>>str 1 = "THIRUKKURAL"
>>>print (str 1 [0])
T
(v) Stride when slicing string:
Example :
>>>str1 = "Welcome to learn python"
>>>print(str1[::-2])
Output :
nhy re teolW
15.
Functions are named blocks of code that are designed to do one specific job.
Types of Functions :
(i) User-defined Functions
(ii) Built-in Functions
(iii) Lambda Functions
(iv) Recursion Function
User defined functions:
1. Functions defined by the users themselves are called user defined function.
2. Functions must be defined, to create and use certain functionality.
3.Function blocks begin with the keyword "def" followed by function name and parenthesis ().
Syntax:
def
return
def hello ():
print ("hello Python")
return
Built-in function: Functions which are using Python libraries are called Built-in function.
x = 20
y = 23.2
print('x=',abs(x))
print ('y=', abs(y))
Output:
x = 20
y = 23.2
Lambda function :
1. In Python, anonymous function is a function that is defined without a name.
2. While normal functions are defined using the def keyword, in Python anonymous functions are defined using the lambda keyword.
3.Hence anonymous functions are also called as lambda functions.
Example:
Sum =lambda arg1, arg 2: arg 1 + arg 2
print ("The sum is:", sum (30,40))
print ("The sum is:", sum (-30,40))
Output:
The sum is: 70
The sum is: 10
Recursion Function: Function that calls itself is known as recursive.
Overview of how recursive function works :
(a) Recursive function is called by some external code.
(b) If the base condition is met then the program gives meaningful output and exits.
(c) Otherwise, function does some required processing and then calls itself to continue recursion.
Example:
def fact(n):
if n==0:
return 1
else:
return n* fact (n-1)
print (fact (0))
print (fact (5))
Output:
1
120
16.
Multiplication table :
num =int(input("Enter the number: "))
print("multiplication Table of", num)
for i in range(1,11):
print (num,"x",i, "= ",num*i )
Output :
Enter the number : 6
Multiplication Table of 6
6 x 1 = 6
6 x 2 = 12
6 x 3 = 18
6 x 4 = 24
6 x 5 = 30
6 x 6 = 36
6 x 7 = 42
6 x 8 = 48
6 x 9 = 54
6 x 10 = 60.
17.
Bubble sort algorithm:
(i) Bubble sort algorithm simple sorting algorithm. The algorithm starts at the beginning of the list of values stored in an array. It compares each pair of adjacent elements and swaps them if they are in the unsorted order.
(ii) This comparison and passed to be continued until no swaps are needed, which indicates that the list of values stored in an array is sorted. The algorithm is a comparison sort, is named for the way smaller elements "bubble" to the top of the list.
(iii) Although the algorithm is simple, it is too slow and less efficient when compared to insertion sort and other sorting methods.
(iv) Assume list is an array of n elements. The swap function swaps the values of the given array elements.
Procedure :
(i) Start with the first element i.e., index = 0, compare the current element with the next element of the array.
(ii) If the current element is greater than the next element of the array, swap them.
(iii) If the current element is less than the next or right side of the element, move to the next element. Go to Step 1 and repeat until the end of the index is reached.
(iv) Let's consider an array with values {15, 11, 16, 12, 14, 13} Below, we have a pictorial representation of how bubble sort will sort the given array.
(v) The above pictorial example is for iteration-d. Similarly, remaining iteration can be done. The final iteration will give the sorted array. At the end of all the iterations we will get the sorted values in an array as given below:
| 11 | 12 | 13 | 14 | 15 | 16 |
18.
Binary Search:
Binary search also called half-interval search algorithm. It finds the position of a search element within a sorted array. The binary search algorithm can be done as a divide- and -conquer search algorithm and executes in logarithmic time.
Pseudo Code:
Start with the middle element:
(i) If the search element is equal to the middle element of the array i.e., the middle value = number of elements in array/2, then return the index of the middle element.
(ii) If not, then compare the middle element with the search value,
(iii) If the search element is greater than the number in the middle index, then select the elements to the right side of the middle index, and go to Step-1.
(iv) If the search element is less than the number in the middle index, then select the elements to the left side of the middle index, and start with Step-1.
(v) When a match is found, display success message with the index of the element matched.
(vi) If no match is found for all comparisons, then display unsuccessful message.
Binary Search Working principles :
(i) List of elements in an array must be sorted first for Binary search. The following example describes the step by step operation of binary search.
(ii) Consider the following array of elements, the array. is being sorted so itenables to do the binary searçh algorithm. Let us assume that the search element is 60 and we need to search the location or index of search element 60 using binary search.

(iii) First, we find index of middle element of. the array byusing this formula:
mid = low + (high - low) /2
(iv) Here it is, 0 + (9-0)/2=4 (fractional part ignored). So, 4 is thè mid value of the array.

(v) Now compare the search element with the value stored at mid value location 4. The value stored at location or index 4 is 50, which is not match with search element. As the search value 60 is greater than 50.

(vi) Now we change our low to mid+1 and find the new mid value again using the formula.
low = mid + 1
mid = low + (high - low) / 2
(vii) Our new mid is 7 now. We compare the value stored at location 7 with our target value 60.

(viii) The value stored at location or index 7 is not a match with search element, rather it is more than what we are looking for. So, the search element must be in the lower part from the current mid value location.

(ix) The search element still not found. Hence, we calculated the mid again by using the formula.
high = mid -1
mid = low +(high - low)/2
Now the mid value is 5.

(x) Now we compare the value stored at location 5 with our search element. We found that it is a match.

(xi) We can conclude that the search element 60 is found at locationor index 5. For example if we take the search element as 95, For this value this binary search algorithm return unsucessful result.
19.
| Input | Zero or more quantities to be supplied. |
| Output | At least one quantityis produced. |
| Finiteness | Algorithms must terminate after finite number of steps. |
| Definiteness | All operations should be well defined. For example operations involving division by zero or taking square root for negative number are unacceptable. |
| Effectiveness | Every instruction must be carried out effectively. |
| Correctness | The algorithms should be error free. |
| Simplicity | East to implement. |
| Unambiguous | Algorithm should be clear and unambiguous. Each of its steps and their inputs/outputs should be clear and must lead to only one meaning. |
| Feasibility | Should be feasible with the avaliable resources. |
| Portable | An algorithm should be generic, independent of any programming language or an operating system able to handle all range of inputs. |
| Independent | An algorithm should have step-by-step directions, which should be independent of any programming code. |
20.
A script is a text file containing the Python statements. Python Scripts are reusable code. Once the script is created, it can be executed6again and again without retyping. The Scripts are editable
i) Creating Scripts in Python:
1. Choose File → New File or press Ctrl + N in Python shell window.
2. An untitled blank script text editor will be displayed on screen
3. Type the following code in script editor.
a = 100
b= 350
C = a + b
print ("The sum=", c)
ii) Saving Python script:
1. Choose File → Save or press Ctrl+S.
2. Now, Save As dialog box appears on the screen.
3. In the Sare As dialog box, select the location where you want to save your Python code, and type the File name in File Name box. Python files are by default saved will extension • py. Thus, while creating Python Scripts using Pyrhons script editor, no need to specify the file extension.
4. Hinallyiclick save button to save your python script.
iii) Exccuthon Python Script:
1. Choose Run → Run module or Press F5.
2. If your code has any error, it will be shown in red color in the IDLE window, and Python describes the type of error occurred. To correct the errors, go back to Script editor, make corrections, save the file using Ctrl +s or File → Save and execute il again.
3, For all error line code, the output will appear in the IDLL window of Python.
21.
The following are the desirable characteristics of a module.
(i) Modules contain instructions, processing logic, and data.
(ii) Modules can be separately compiled and stored in a library.
(iii) Modules can be included in a program.
(iv) Module segments can be used by invoking a name and some parameters.
(v) Module segments can be used by other modules.
22.
Types of Variable Scope:
There are 4 types of Variable Scope, let's discuss them one by one:
Local Scope:
(i) 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.
Look at this example
| 1. Disp(): 2. a:=7 3. print a 4. Disp() |
Entire program |
Output of the Program 7 |
(ii) 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:
(i) A variable which is declared outside of all the functions in a program is known as global variable.
(ii) This means, global variable can be accessed inside or outside of all the functions in a program.
Example:
| 1. a:=10 2. Disp(): 3. a:=7 4. print a 5. Disp() 6. print a |
Entire program |
Output of the Program 7 10 |
(iii) 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:
(i) All programming languages permit functions to be nested. A function (method) with in another function is called nested function.
(ii) 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.
(iii) When a compiler or interpreter search for a variable in a program, it first search Local, and then search Enclosing scopes. Consider
the following example:
| 1. Disp(): 2. a:=10 3. Disp1() 4. print a 5. Disp1() 6. print a 7. Disp() |
Entire Program |
Output of the Program 10 10 |
(iv) In the above example Disp1( ) is defined with in Disp( ). The variable 'a' defined in Disp( ) can be even used by Disp1( ) because it is also a member of Disp( ).
Built-in Scope:
(i) The built-in scope has all the names that are pre-loaded into the program scope when we start the compiler or interpreter.
(ii) Any variable or function which is defined in the modules of a programming language has Built-in or module scope. They are loaded as soon as the library files are imported to the program.Consider the following example.
| Library files associated with the software |
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).
.png)
23.
List :
(i) List is constructed by placing expressions within square brackets separated by commas. Such an expression is called a list literal. List can store multiple values. Each value can be of any type and can even be another list.
Example for List [10, 20].
(ii) The elenments of a list can be accessed in two ways. The first way is via our familiar method of multiple assignment, which unpacks a list into its elements and binds each elenment to a different name.
Ist := [10, 20]
x, y = lst
(iii) In the above example x will become l0 and y will become 20. A second method for accessing the elements in a list is by the element selection operator.
(iv) Unlike a list literal, a square-brackets expression directly following another expression does not evaluate to a list value, but instead selects an element from the value of the preceding expression.
lst [0]
10
Ist [1]
20
(v) In both the example mentioned above mathematically we can represent list similar to a set.

Pair :
Any way of bundling two values together into one can be considered as a pair. Lists are a common methodto do so. Therefore List can be called as Pairs.
24.
Data abstraction is used to define an Abstract Data Type (ADT), which is a collection of constructors and selectors. T facilitate data abstraction,you will need to create two types of functions : Constructors and Selectors.
Constructors :
(i) Constructors are functions that build the abstract data type.
(ii) Constructors create an object, bundling together different pieces of information.
(iii) For example, say you have an abstract data type called city.
(iv) This city object will hold the city's name, and its latitude and longitude.
(v) To create a city object, you'd use a function like city = makecity (name, lat, lon).
(vi) Here makecity (name, lat, lon) is the constructor which creates the object city.

Selectors :
(i) Selectors are functions that retrieve information from the data type.
(ii) Selectors extract individual pieces of information fromn the object.
(iii) To extract the information of a city object, you wouldused functions like
getname(city)
getlat(city)
getlon(city)
These are the selectors because these functions extract the information of the city object.
.png)
25.
Pure functions:
(i) Pure functions are functions which will give exact result when the same arguments are passed.
(ii) For example the mathematical function sin (0) always results 0. This means that every time you call the function with the same arguments, you wil always get the same result.
(iii) A function can be a pure function provided it should not have any external variable which will alter the behavior of that variable.
let us see an Example:
Let square x : =
return: x * x
(iv) The above function square is a pure function because it will not give different results for same input.
(v) There are various theoretical advantages of having pure functions. One advantage is that if a function is pure, then if it is called several times with the same arguments, the compiler only needs to actually call the function once.
Example:
let length s:=
i:= 0
let i:= 0;
if i<strlen (s) then
-- Do something which doesn't affect s
++1
(vi) If it is compiled, strlen (s) is called each time and strlen needs to iterate over the whole of 's'. If the compiler is smart enough to work out that strlen is a pure function and that 's' is not updated in the loop, then it can remove the redundant extra calls to strlen and make the loop to execute only one time.
(vii) From these what we can understand, strlen is a pure function because the function takes one variable as a parameter, and accesses it to find its length. This function reads external memory but does not change it, and the value returned derives from the external memory accessed
Impure functions:
(i) The variables used inside the function may cause side effects through the functions which are not passed with any arguments. In which cases the function is called impure function.
(ii) When a function depends on variable or functions outside of its definition block, you can never be sure that the function will behave the same every time it's called. For example, the mathematical functions random ( ) will give different outputs for the same function call.
Example:
let randomnumber:=
a := random()
if a > 10 then
return: a
else
return: 10
(iii) Here the function Random is impure as it is not sure what will be the result when we call the function
12th Standard Syllabus & Materials
12th Standard
TN 12th Computer Applications களப்பெயர் முறைமை (DNS) Sample Question Papers Study Material - QB365 Set A
NEW12th Standard
TN 12th Computer Applications வலையமைப்பு எடுத்துக்காட்டுகள் மற்றும் நெறிமுறைகள் Sample Question Papers Study Material - QB365 Set A
NEW12th Standard
TN 12th Computer Applications கணினி வலையமைப்பு ஓர் அறிமுகம் Sample Question Papers Study Material - QB365 Set A
NEW12th Standard
TN 12th Computer Applications PHP-உடன் MySQL-ஐ இணைத்தல் Sample Question Papers Study Material - QB365 Set A
Tamilnadu Stateboard 12th Standard Subjects

Maths

Chemistry

Physics

Biology

Computer Science

Business Maths and Statistics

Economics

Commerce

Accountancy

History

Computer Applications

Biology

Computer Technology

Computer Applications

Computer Science

Business Maths and Statistics

Commerce

Economics

Maths

Chemistry

Physics

Computer Technology

History

Accountancy

Tamil

English

French
Tamilnadu Stateboard Standards