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: 03/02/2021
12th Standard Computer Science English Medium Importing C++ Programs in Python Reduced Syllabus Important Questions With Answer Key 2021
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.
_________ command of 'os' module executes the exe file to get the desired output.
Main ( )
Name ( )
Run ( )
System ( )
2.
__________ method returns value consisting of two elements.
sys.argv
oS.system ( )
getopt ( )
none of these
3.
__________ is both a python like language for writing C extensions.
Boost
Cython
SWIG
Ctypes
4.
Which of the following is a built - in variable which evaluates to the name of the current module?
- - main - -
- - getopt - -
- - name - -
- - sys - -
5.
How many options getopt provides to enable command line argument parsing?
3
7
2
4
6.
How many ways are there to create python interface?
4
3
5
Many
7.
A programming language requires
Complier
Interpreter
Modules
Scripts
8.
Which is a programming language designed for integrating and communicating with other programming languages?
Modular language
Procedural language
Scripting language
Procedural language
9.
Which of the following can act both as scripting and general purpose language?
Python
C
C++
Html
10.
Which of the following is not general purpose language?
Python
Perl
Java
C++
11.
What does __name__ contains?
c++ filename
main() name
python filename
os module name
12.
Identify the function call statement in the following snippet.
if __name__ =='__main__':
main(sys.argv[1:])
main(sys.argv[1:])
__name__
__main__
argv
13.
getopt() will return an empty array if there is no error in splitting strings to
argv variable
opt variable
args variable
ifile variable
14.
15.
Which of the following is a software design technique to split your code into separate parts?
Object oriented Programming
Modular programming
Low Level Programming
Procedure oriented Programming
16.
Which of the following is not a scripting language?
JavaScript
PHP
Perl
HTML
17.
What is meant by module?
18.
Write a note on
(i) CD command
(ii) CIs command
19.
What does cd command refers?
20.
What is the use of GNU C complier?
21.
What is garbage collection in python?
22.
Differentiate static typed language and dynamic typed language.
23.
24.
What is the use of modules?
25.
Write the expansion of (i) SWIG (ii) MinGW
26.
Differentiate compiler and interpreter.
27.
What is the theoretical difference between Scripting language and other programming language?
28.
Write an algorithm for executing C++ program pali_cpp.cpp using python program.pall.py.
29.
How to import modules in python?
30.
List the commonly used python interfaces.
31.
Write a note on
(i) sys module
(ii) OS module
(iii) getopt module
32.
What is sys.argv? What does it contain?
33.
Identify the module, operator, definition name for the following
welcome.display().
34.
What is MinGW? What is its use?
35.
What are the applications of scripting language?
36.
Differentiate PYTHON and C++.
37.
Write a python program to execute the following C++ program.
Transpose of a matrix(2 D array) C++ program:
#include < iostream >
using namespace std;
int main ( )
{
int a[3][3], i, j;
for(i=0; i< 3; i++)
{
for(j=0; j<3; j++)
{cout<< "enter the value for
array["<< i+ 1<< "]"<< " ["<< j+ 1<< "] :";
cin >>a[i][j];
}
}
system ("cIs");
cout<< "\n\nOriginal Array\n";
for(i=0; i<3; i++) {
for(j=0; j<3; j++ )
cout<< a[i][j]«' ';
cout<< endl; }
cout<< "\n\n The Transpose of Matrix\n";
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
cout<< a[j][i]<< ' ';
cout<< endl;
}
return 0;
}
// Save this file as trans_cpp.cpp
38.
Write a python program to execute the following C++ program.
/*. To check whether the number is palindrome or not using while Ioop.*/
// Now select File →New in Notepad and type the C++ program
#include < iostream >
using namespace std;
intmain ( )
{
int n, num, digit, rev = 0;
cout<< "Enter a positive number: ";
cin >>num;
n= num;
while(num)
{digit = num % 10;
rev = (rev * 10) + digit;
num = num / 10; }
cout<< "The reverse of the number is: " << rev <<endl;
if(n == rev)
cout< < "The number is a palindrome";
else
cout << "The number is not a palindrome";
return 0;
}
// Save this file as pali_cpp.cpp
39.
Explain the commands for wrapping C++ code.
40.
Write the syntax for getopt( ) and explain its arguments and return values.
41.
42.
Explain each word of the following command.
Python
43.
Write any 5 features of Python.
1.
(d)
System ( )
2.
(c)
getopt ( )
3.
(b)
Cython
4.
(c)
- - name - -
5.
(c)
2
6.
(d)
Many
7.
(b)
Interpreter
8.
(a)
Modular language
9.
(a)
Python
10.
(b)
Perl
11.
(a)
c++ filename
12.
(a)
main(sys.argv[1:])
13.
(a)
argv variable
14.
(a)
15.
(b)
Modular programming
16.
(d)
HTML
17.
(i) Modular programming is a software design technique to split your code into separate parts.
(ii) These parts are called modules. The focus for this separation should have modules with no or just few dependencies upon other modules.
18.
(i) CD command: The "cd" command refers to changes directory and absolute path refers to the complete path where Python is installed.
(ii) Cls command: To clear the screen in command window use cls command.
19.
The "cd"command refers to changes directory and absolute path refers to the complete path where Python is installed.
20.
g++ is a program that calls GCC (GNU C Compiler) and automatically links the required C++library files to the object code
21.
(i) Python deletes unwanted objects (built-in types or class instances) automatically to free the memory space.
(ii) The process by which Python periodically frees and reclaims blocks of memory that no longer are in use is called Garbage Collection.
22.
(i) A static typed language like C++ requires the programmer to explicitly tell the computer what "data type" each data value is going to use.
(ii) A dynamic typed language like Python, doesn't require the data type to be given explicitly for the data. Python manipulate the variable based on the type of value.
23.
24.
Modular programming is a software design technique to split our code into separate parts. These parts are called modules. The focus for this separation should have modules with no or just few dependencies upon other modules.
25.
(i) SWIG - Simplified Wrapper Interface Generator
(ii) MinGW - Minimalist GNU for Windows
26.
| S.No | Compiler | Interpreter |
|---|---|---|
| (i) | It takes an entire Program at a time. | It takes a single line of code or instruction at a time. |
| (ii) | Display all errors after compilation, all at the | Displays error of each line one by one. |
27.
(i) The theoretical difference between the two is that scripting languages do not require the compilation step and are rather interpreted.
(ii) For example, normally, a C++ program needs to be compiled before running whereas, a scripting language like JavaScript or Python need not be compiled.
(iii) A scripting language requires an interpreter while a programming language requires a compiler.
28.
Step 1: Type the C++ program to check whether the input number is palindrome or not in notepad and save it as "pali_cpp.cpp".
Step 2: Type the Python program and save it as pali.py.
Step 3: Click the Run Terminal and open the command window
Step 4: Go to the folder of Python using cd command
Step 5: Type the command Python pali.py -i pali_cpp
29.
(i) We can import the definitions inside a module to another module. We use the import keyword to do this.
(ii) Using the module name we can access the functions defined inside the module. The dot (.) operator is used to access the functions. The syntax for accessing the functions from the module is
<module name>. <function name>
(iii) Example: >>> factorial.fact(5)
30.
The commonly used interfaces are
(i) Python-C-API (API-Application Programming Interface for interfacing with C programs)
(ii) Ctypes (for interfacing with c programs)
(iii) SWIG (Simplified Wrapper Interface Generator- Both C and C++)
(iv) Cython (Cython is both a Python-like language for writing C-extensions)
(v) Boost. Python (a framework for interfacing Python and c++)
(vi) MinGW (Minimalist GNU for Windows)
31.
(i) sys module provides access to some variables used by the interpreter and to functions that interact with the interpreter
(ii) OS module in Python provides a way of using operating system dependent functionality
(iii) The getopt module of Python helps you to parse (split) command-line options and arguments.
32.
sys.argv is the list of command-line arguments passed to the Python program. argv contains all the items that come along via the command-line input, it's basically an array holding the command-line arguments of the program.
To use syss.argv, we will first have to import sys. The first argument, sys.argv [0], is always the name of the program as it was invoked and sys.argv [1] is the first argument we pass to the program.
Example:
main (sys.argv [1]) - Accepts the program file and the input file as a list. argv[0] contains the python program which is need not to be passed because by default _main_contains source code reference and argv[1] contains the name of the C++ file which is to be processed.
33.
welcome → module name
● → operator name
display() → definition name
34.
(i) MinGW refers to a set of runtime header files, used in compiling and linking the code of C, C++ and FORTRAN to be run on Windows Operating System.
(ii) MinGw- W64 (version of MinGW) is the best compiler for C++ on Windows. To compile and execute the C++ program, need 'g++' for Windows. MinGW allows to compile and execute C++ program dynamically through Python program using g++.
(iii) Python program that contains the c++ coding can be executed only through 'MinGW_w64 project' run terminal. The run terminal open the command -line window through which Python program should be executed.
(iv) g++ is a program that calls GCC (GNU C compiler) and automatically links the required C++ Library files to the object code.
35.
(i) To automate certain tasks in a program
(ii) Extracting information from a data set
(iii) Less code intensive as compared to traditional programming language
(iv) can bring new functions to applications and glue complex systems together
(v) Conjuction with other programming languages HTML, Java, C++.
36.
| S.No | PYTHON | C++ |
|---|---|---|
| (i) | Python is typically an "interpreted" language | C++ is typically a "compiled" language |
| (il) | Python is a dynamic typed language | C++ is compiled statically typed language |
| (iii) | Data type is not required while declaring variable | Data type is required while declaring variable |
| (iv) | It can act both as scripting and general purpose language | It is a general purpose language |
37.
//Now select File⟶New in Notepad and type the Python program
# Save the File as transpose.py. Program that compiles and executes a .cpp file
# Python tanspose.py -i trans_cpp
Python Program:
import sys, os, getopt
def main(argv):
cpp_file = "
exe_file = "
opts,args = getopt.getopt(argv, "i:",['ifile='])
for o, a in opts:
if o in ("-i", "< -ifile"):
cpp_file = a + '.cpp'
exe_file = a + '.exe'
run(cpp_file, exe_file)
defrun( cpp _file, exe_file):
print("Compiling" + cpp_file)
'os.system ('g++' + cpp_file + '-o' + exe_file)
print("Running" + exe_file)
print(" -------------------")
print
os.system( exe_file)
print
if __name__ =='__main__"
main( sys.argv[ 1:])
38.
# Save the File as pali.py . Program that compiles and executes a .cpp file
# Python c:\pyprg\pali.py -i c:\pyprg\pali_cpp import sys, os, getopt
def main(argv):
cpp_file ="
exe_file = "
opts, args= getopt.getopt(argv, "i:",['ifile='])
for o, a in opts:
if o in ("-i", "--ifile"):
cpp_file = a + '.cpp'
exe_file = a + '.exe'
run(cpp_file, exe_file)
def run(cpp_file, exe_file):
print("Compiling" + cpp_file)
os.system('g++' + cpp_file + '-o' + exe_file)
print("Running" + exe_file)
print("-----------------")
print
os.system(exe_file)
print
if __name__ =='__main__': # program starts executing from here
main(sys.argv[ 1:])
39.
commands for wrapping C++ code:
if___name___ =='___main___':
main(sys.argv[ 1:])
_name_ (A Special variable) in Python:
(i) Since there is no main ( ) function in Python, when the command to run a Python program is given to the interpreter, the code that is at level 0 indentation is to be executed.
(ii) However, before doing that, interpreter will define a few special variables. __name___ is one such special variable which by default stores the name of the file. If the source file is executed as the main program, the interpreter sets the ___name___ variable to have a value as "___main___".
(iii) __name__ is a built-in variable which evaluates to the name of the current module. Thus it can be used to check whether the current script is being run on its own.
(iv) For example consider the following:
if ___name___ ==' ___main___':
main (sys.argv[1:])
(v) if the command line Python program itself is going to execute first, then _main_ contains the name of that Python program and the Python special variable _name_ also contain the Python program name.
(vi) If the condition is true it calls the main which is passed with C++ file as argument.
40.
getopt() method returns value consisting of two elements. Each of these values are stored separately in two different list opts and args. opts contains list of splitted strings like made, path and args contains any string if at all not splitted because of wrong path or mode. args will be an empty array if there is no error in splitting strings by getopt().
Example:
The Python code which is going to execute the C++ file p4 in command line will have the getopt() method.
Syntax:
opts, args = getopt.getopt (argv, "i:", ['ifile ='])
where opts contains ('-i','c:\\pyprg\\p4')]]
-i:- option nothing but mode should be followed by
'c:\\pyprg\\p4' value nothing but the absolute path of C++ file,
Since the entire command-line commands are parsed and no leftover arguments, the second argunent args will be empty[].
41.
42.
Python < filename.py > - < i > <C++ filename without cpp extension>
| Python | Keyword to execute the Python program from command-line |
| filename.py- i | Name of the Python program to executed input mode |
| C++ filename without cpp extension | Name of C++ file to be compiled and executed |
For example type Python pycpp.py - i pali in the command prompt and press enter key. If the compilation is successful we will get the desired output. Otherwise the error will be displayed.
43.
(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.
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