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 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.
Write a command for wrapping C++ code.
2.
Write the syntax and example of
(i) os.system ( )
(ii) getopt ( )
3.
Write a note on main (sys.argv [1]).
4.
What is meant by module?
5.
Write a note on
(i) CD command
(ii) CIs command
6.
What does cd command refers?
7.
How will you execute C++ program through python using MinGW interface? Give example
8.
What is the use of GNU C complier?
9.
What is garbage collection in python?
10.
List some scripting language
11.
Differentiate static typed language and dynamic typed language.
12.
Differentiate compiler and interpreter.
13.
What is the theoretical difference between Scripting language and other programming language?
14.
Write an algorithm for executing C++ program pali_cpp.cpp using python program.pall.py.
15.
How to import modules in python?
16.
Write a note on
(i) sys module
(ii) OS module
(iii) getopt module
17.
What is sys.argv? What does it contain?
18.
Identify the module, operator, definition name for the following
welcome.display().
19.
What is MinGW? What is its use?
20.
What are the applications of scripting language?
21.
Differentiate PYTHON and C++.
22.
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
23.
Write a python program to execute the following C++ program.
C++ program:
/*Write a C++ program using a user defined
function to function cube of a number. */
// Now select File⇾New in Notepad and type the C++ program
#include
using namespace std;
// Function declaration
int cube(int num),
int main( )
{
int num;
int c;
cout<< "Enter any number: "<<endl;
cin >>num;
c = cube(num);
cout<< "Cube of" << num<< " is "<< c;
return 0;
}
//Function to find cube of any number
int cube(int num)
{
return (num * num * num);
}
// Save this file as cube_file.cpp
24.
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
25.
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
26.
Explain the commands for wrapping C++ code.
27.
Write a Python program to execute the following c++ coding.
#include <iostream>
using namespace std;
int main()
{ cout<<“WELCOME”;
return(0);
}
The above C++ program is saved in a file welcome.cpp
28.
Explain each word of the following command.
Python
29.
The command to dear the window screen is __________.
CIs
Clear
Clr
Clrscr
30.
_________ command of 'os' module executes the exe file to get the desired output.
Main ( )
Name ( )
Run ( )
System ( )
31.
_________ is one such special variable which by default stores the name of the file
- - name - -
- - main - -
- - getopt - -
- - sys - -
32.
__________ method returns value consisting of two elements.
sys.argv
oS.system ( )
getopt ( )
none of these
33.
__________ refers to the complete path where python is installed.
Relative path
Python path
Absolute path
Directory path
34.
___________ refers to a set of runtime header files used in compiling and linking the C++ code to be run or window OS?
SWIG
MinGW
Cython
Boost
35.
__________ is typically interpreted language.
Python
Java
C++
None of these
36.
Which of the following definition invoke the 'g++' compiler and creates the exe file?
Main
Name
Run
System
37.
Which of the following is not a python module?
Sys
OS
Getopt
g++
38.
Which of the following is not a python module?
OS
Sys
Tel
Getopt
39.
In the command python <filename.py> -
Information
Input mode
ios
Interpreter
40.
Which of the following is needed to run a c++ program on windows?
m++
g++
ghre++
f++
41.
MinGW expansion is
Minimalist Graphics for windows
Minimum GNU for windows
Minimalist GNU for Windows
Motion Graphics for windows
42.
Which of the following python interface used for both C and C++?
MinGW
Ctypes
Cython
SWIG
43.
C++ code is 5 to 10 times more than
Java
Python
C
Java script
1.
if ___name____ =='____main____':
main(sys.argv[1:])
2.
(i) os.system ('g++' + <varaiable_name1>'-<mode>' + <Variable_name2>
(ii) <opts>,<args>
3.
maintsv (sys.argv[1]) Accepts the program file (Python program) and the input file (C++file) as a list(array). 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.
4.
(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.
5.
(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.
6.
The "cd"command refers to changes directory and absolute path refers to the complete path where Python is installed.
7.
Executing C++Program through Python
(i) Double click the run terminal of MinGW
(ii) Go to the folder where the Python software is located (Python.exe) is located.
For example here "Python" is located in
8.
g++ is a program that calls GCC (GNU C Compiler) and automatically links the required C++library files to the object code
9.
(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.
10.
The most widely used scripting languages are JavaScript, VBScript, PHP, Perl, Python, Ruby, ASP and Tcl.
11.
(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.
12.
| 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. |
13.
(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.
14.
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
15.
(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)
16.
(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.
17.
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.
18.
welcome → module name
● → operator name
display() → definition name
19.
(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.
20.
(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++.
21.
| 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 |
22.
//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:])
23.
# Save the File as fun.py
# Program that compiles and executes a .cpp file
# Python fun.py -i c:\pyprg\cube_file.cpp
Python Program:
import sys, os, getopt
def main(argv):
cpp_file ="
exe_file ="
opts,args = getopt.getopt(argv, "i:",['ifile='])
for 0, a in opts:
if 0 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_':
main(sys.argv[1:])
24.
//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:])
25.
# 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:])
26.
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.
27.
Execution Steps:
//save above file as welcome.cpp
#Now select File -> New in Notepad and type the Python program
#save the file as fun.py
#Program that compiles and executes a .cpp file
#Python fun.py- iC: |pyprg| welcome - file.cpp
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)
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:])
Output:
welcome.
28.
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.
29.
(a)
CIs
30.
(d)
System ( )
31.
(a)
- - name - -
32.
(c)
getopt ( )
33.
(c)
Absolute path
34.
(b)
MinGW
35.
(a)
Python
36.
(c)
Run
37.
(d)
g++
38.
(c)
Tel
39.
(b)
Input mode
40.
(b)
g++
41.
(c)
Minimalist GNU for Windows
42.
(d)
SWIG
43.
(b)
Python
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