12th Standard Syllabus & Materials
12th Standard
TN 12th Standard Biology Zoology - Reproduction in Organisms Creative Questions Study Material - QB365 Set D
NEW12th Standard
TN 12th Standard Biology Zoology - Reproduction in Organisms Creative Questions Study Material - QB365 Set C
NEW12th Standard
TN 12th Standard Biology Zoology - Reproduction in Organisms Creative Questions Study Material - QB365 Set B
NEW12th Standard
TN 12th Standard Biology Zoology - Reproduction in Organisms Creative Questions Study Material - QB365 Set A
NEW12th Standard
TN 12th Standard Physics Electronics and Communication Creative Questions Study Material - QB365 Set D
NEW12th Standard
TN 12th Standard Physics Electronics and Communication Creative Questions Study Material - QB365 Set C

Published on: 06/01/2020
Importing C++ Programs in Python
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.
Which of the following interface used for interfacing with C programs?
MicGW
Boost
Ctypes
Cython
2.
Which of the following is a scripting language?
Ruby
ASP
TCI
All of these
3.
Which of the following is not a compiled statically typed language?
C++
Java
Python
All of these
4.
5.
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
6.
Write a command for wrapping C++ code.
7.
What is the use of GNU C complier?
8.
What is garbage collection in python?
9.
10.
What is the use of modules?
11.
Write an algorithm for executing C++ program pali_cpp.cpp using python program.pall.py.
12.
How to import modules in python?
13.
List the commonly used python interfaces.
14.
What is MinGW? What is its use?
15.
What are the applications of scripting language?
16.
Write a python program to execute the following C++ program
To implement Multilevel Inheritance:
// C++ program to implement Multilevel Inheritance
// Now select File ⟶New in Notepad and type the C++ program
c++ Program.
#include < iostream >
using namespace std;
// base class
class Vehicle
{
public:
Vehicle ( )
{
cout<< "This is a Vehicle" << endl;
}
};
class threeWheeler: public Vehicle
{ public:
three Wheeler ( )
{
cout << "Objects with 3 wheels are vehicles" << endl;
}
};
// sub class derived from two base classes
class Auto: public threeWheeler{
public:
Auto ( )
{
cout<< "Auto has 3 Wheels"<< endl;
};
// main function
int main ( )
{
//creating object of sub class will invoke the constructor of base classes
Auto obj;
return 0;
}
// Save this file as inheri_cpp.cpp
17.
Explain the commands for wrapping C++ code.
18.
Write the syntax for getopt( ) and explain its arguments and return values.
19.
Write any 5 features of Python.
1.
(c)
Ctypes
2.
(d)
All of these
3.
(c)
Python
4.
(a)
5.
(b)
Modular programming
6.
if ___name____ =='____main____':
main(sys.argv[1:])
7.
g++ is a program that calls GCC (GNU C Compiler) and automatically links the required C++library files to the object code
8.
(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.
9.
10.
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.
11.
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
12.
(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)
13.
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)
14.
(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.
15.
(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++.
16.
//Now select File ➝ New in Notepad and type the Python program
# Save the File as classpy.py
# Python classpy.py -i inheri_cpp command to execute c++ program
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:
1ifile. ("'-"1", --ifile"):
cpp_file = a + '.cpp'
exe_file = a + '.exe'
run (cppfile, 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__"
main (sys.argv[1:])
17.
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.
18.
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[].
19.
(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 Standard Physics Electronics and Communication Creative Questions Study Material - QB365 Set B
NEW12th Standard
TN 12th Standard Physics Electronics and Communication Creative Questions Study Material - QB365 Set A
NEW12th Standard
TN 12th Standard Physics Wave Optics Creative Questions Study Material - QB365 Set D
NEW12th Standard
TN 12th Standard Physics Wave Optics Creative Questions Study Material - QB365 Set C
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