0% found this document useful (0 votes)
80 views10 pages

Chapter 14

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
80 views10 pages

Chapter 14

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

PAAVENDHAR MATRIC. HR. SEC.

SCHOOL
M.V. SOUTH, ATTUR.
CHAPTER 14 – IM PORTING C++ PROGRAMS IN PYTHON
PART A
CHOOSE THE BEST ANSW ER
1. Which of the following is not a scripting language?
a) JavaScript b) PHP c) Perl d) HTML
2. Importing C++ program in a Python program is called
a) wrapping b) Downloading c) Interconnecting d) Parsing
3. The expansion of API is
a) Application Programming Interpreter b) Application Programming Interface
c) Application Performing Interface d) Application Programming Interlink
4. A framework for interfacing Python and C++ is
a) C types b) SWIG c) Cython d) Boost
5. Which of the following is a software design technique to split your code into separate
parts?
a) Object oriented Programming b) Modular programming
c) Low Level Programming d) Procedure oriented Programming
6. The module which allows you to interface with the Windows operating system is
a) OS module b) sys module c) csv module d) getopt module
7. getopt() will return an empty array if there is no error in splitting strings to
a) argv variable b) opt variable c) args variable d) ifile variable
8. Identify the function call statement in the following snippet.
if __name__ =='__main__':??
main(sys.argv[1:])
a) main(sys.argv[1:]) b) __name__ c) __main__ d) argv
9. Which of the following can be used for processing text, numbers, images, and scientific
data?
a) HTML b) C c) C++ d) PYTHON
10. What does __name__ contains?
a) c++ filename b) main () name c) python filename d) os module name
11. Which of the following are general purpose programming language?
a) Python b) C++ c) Java d) All of these
12. Which of the following is not general purpose language?
a) Python b) C++ c) Perl d) Java
13. Which of the following is not a compiled statically typed language?
a) C++ b) Python c) Java d) All of these
14. In which language datatype or not required while declare variable?
a) Python b) C++ c) C d) Java
15. Which of the following can act both as scripting and general purpose language?
a) Html b) Python c) C d) C++
16. Which programming language is useful when the logic can be written in C++ and
manipulated through python program?
a) C++ b) Html c) Perl d) Python
17. Which is a programming language designed for integrating and communicating with
other programming languages?
K.SIVAPRAKASAM M.SC.,M.PHIL.,B.ED., PGT IN CS, PAAVENDHAR MHSS-M.V.SOUTH, ATTUR 636121 Page 1
a) Procedural language b) Modular language
c) Scripting language d) none of these
18. Which of the following is a scripting language?
a) Ruby b) ASP c) TCl d) All of these
19. Which of the following language used automatic garbage collection?
a) C++ b) Java c) Python d) C
20. A scripting language requires
a) Interpreter b) Python c) Compiler d) Modules
21. A programming language requires
a) Compiler b) Interpreter c) Modules d) Scripts
22. C++ code is 5 to 10 times more than
a) Java b) Java script c) Python d) C
23. How many ways are there to create python interface?
a) 4 b) 3 c) 5 d) Many
24. Which of the following interface used for interfacing with C programs?
a) Ctypes b) MinGW c) Boost d) Cython
25. SWIG expansion is
a) Software Wrapper Information Generator b) System Wrapper Interface Generator
c) Simplified Wrapper Interface Generator d) None of these
26. Which of the following python interface used for both C and C++?
a) MinGW b) Ctypes c) Cython d) SWIG
27. MinGW expansion is
a) Minimalist GNU for windows b) Minimalist Graphics for windows
c) Minimum GNU for windows d) Motion Graphics for windows
28. Which of the following is needed to run a C++ program on windows?
a) m++ b) f++ c) g++ d) ghre++
29. The command to change to the folder where Python is located is
a) Change b) CD c) Dir d) CDir
30. The syntax to execute the python program is
a) Python - i < filename.py > < c++ filename >
b) Python < filename - py > < C++ filename > - i
c) Python < C++ filename > - i < filename.py >
d) Python < filename.py > < C++ filename >
31. In the command python < filename.py > - i < C++ filename > where i denotes.
a) Information b) Interpreter c) Input mode d) ios
32. Which of the following is not a python module?
a) Tel b) OS c) Sys d) Getopt
33. The operator used to access the python functions using modules is
a) ; b) . c) :: d) ,
34. Which of the following is not a python module?
a) Sys b) OS c) Getopt d) g++
35. Which of the following is a python module?
a) Sys b) OS c) Getopt d) All of these
36. Which of the following is an array holding the command line arguments of the
program?
a) g++ b) argv c) Opts d) Getopt
K.SIVAPRAKASAM M.SC.,M.PHIL.,B.ED., PGT IN CS, PAAVENDHAR MHSS-M.V.SOUTH, ATTUR 636121 Page 2
37. How many options getopt provides to enable command line argument parsing?
a) 2 b) 3 c) 4 d) 7
38. Getopt() method returns values are started in
a) Opts b) Args c) Sys d) a and b
39. Which of the following is a built - in variable which evaluates to the name of the current
module?
a) - - main - - b) - - name - - c) - - getopt - - d) - - sys - -
40. The mode 'i'/'o' parses each values of the command line and pass as argument to the
list called
a) Args b) Sys c) Opts d) Argv
41. Which of the following definition invoke the 'g++' compiler and creates the exe file?
a) Run b) Main c) Name d) System
42. ______ is typically interpreted language.
a) C++ b) Python c) Java d) None of these
43. ________ is mostly used as a 'glue' language.
a) CSV b) C++ c) Java d) Python
44. _________ is both a python like language for writing C extensions.
a) Boost b) Ctypes c) SWIG d) Cython
45. ________refers to a set of runtime header files used in compiling and linking the C++
code to be run or window OS?
a) MinGW b) SWIG c) Cython d) Boost
46. ______ version of MinGW is the best compiler for C++ on windows.
a) W32 b) W256 c) W64 d) W128
47. __________ allows to compile and execute C++ program dynamically through python
program using g++.
a) SWIG b) MinGW c) Ctypes d) Boost
48. ________ is a program that calls GCC for linking the C++ library files to the object code.
a) C++ b) C c) Python d) g++
49. ________ refers to the complete path where python is installed.
a) Relative path b) Directory path c) Python path d) Absolute path
50. ________ is a software design technique to split the code into separate parts.
a) Procedural programming b) Modular Programming
c) Structural programming d) Object Oriented Programming
51. ___________ refers to a file containing python statements and definitions?
a) Modules b) Procedures c) Structures d) Objects
52. ________ is the list of command-line argument passed to the python program?
a) OS.system() b) Getopt.getopt() c) Sys.argv d) Next()
53. To use sys.argv, you have to ______
a) Import CSV b) Import sys c) Import.+ py d) Include sys
54. _________ symbol is os.system() indicates that all strings are concatenated and send
that as a list.
a) - b) () c) . d) +
55. ____ module of python helps you to split command line options and arguments.
a) OS b) Getopt c) Sys d) All of these
56. ______ method returns value consisting of two elements.
a) sys.argv b) getopt() c) OS.system() d) none of these
K.SIVAPRAKASAM M.SC.,M.PHIL.,B.ED., PGT IN CS, PAAVENDHAR MHSS-M.V.SOUTH, ATTUR 636121 Page 3
57. ________ is one such special variable which by default stores the name of the file.
a) - - name - - b) - - main - - c) - - getopt - - d) - - sys - -
58. ________ command of 'os' module executes the exe file to get the desired output.
a) Main() b) System() c) Name() d) Run()
59. The command to clear the window screen is___________
a) Clear b) Cls c) Clr d) Clrscr
60. The keyword used to import the module is _________
a) Include b) Import c) Input d) None of these
61. Choose the incorrect statement from the following.
i. C++ program needs to be compiled before running.
ii. Python need to be compile(d)
iii. Perl, Ruby, ASP are the scripting languages.
iv. Python is not high-level general purpose programming language.
a) ii and iv b) i and ii c) ii and iii d) i, ii and iv
62. Python is mostly used as__________language.
a) High level b) Scripting c) glue d) B or C
63. What is the name called, python deletes unwanted objects automatically to free the
memory space?
a) Recycle b) Garbage collection c) Interface d) Wrapping
64. Which mode is specify to input or output in python?
a) '-o' b) '-i' c) '-a' d) '-s'
65. Which method is used to returns values consisting of two values?
a) append() b) extend() c) getopt() d) insert()
66. Which interface is used for python-like language for writing c-extensions?
a) Cython b) Boost c) MinGW d) SWIG
67. Which language is used both as scripting and general purpose language?
a) C b) C++ c) Python d) HTML
68. Which programming language is designed for integrating and communicating with
other programming language?
a) Modular language b) Procedural language
c) Scripting language d) High level language
69. Which of the following is not a scripting language?
a) Ruby b) TCI c) ASP d) COBOL
70. Which requires a programming language?
a) Compiler b) Interpreter c) Editor d) Exefile
71. Which is requires a scripting language?
a) Compiler b) Interpreter c) Editor d) Exefile
72. Which of the following interface used for interfacing with C programs?
a) Cython b) Ctypes c) MinGw d) SWIG
73. Which of the following python interface used for both C and C++?
a) Cython b) Ctypes c) MinGw d) SWIG
74. Which is needed to run a C++ program on windows?
a) m++ b) g++ c) e++ d) f++
75. Which of the following is not a python module?
a) sys b) g++ c) os d) Getopt
76. Which version of MinGW is the best compiler for C++ on windows?
a) W32 b) W64 c) W128 d) W256
77. Which interface to a set of runtime header files, used compiling and linking the code
of C, C++?
a) SWIG b) MinGW c) Cython d) Ctypes
K.SIVAPRAKASAM M.SC.,M.PHIL.,B.ED., PGT IN CS, PAAVENDHAR MHSS-M.V.SOUTH, ATTUR 636121 Page 4
78. g++ is a____
a) module b) program c) scope d) identifier
79. Which command is used to clear the screen in window?
a) cls b) clear c) cs d) cl
80. Which operator is used to access the function?
a) (.)dot b) (:)colon c) (,)comma d) (;)semi colon
81. Which is mostly used as a 'glue' language?
a) C b) C++ c) Java d) Python

ANSW ER KEY
1. d) HTML 22. c) Python 43. d) Python 66. a) Cython
2. a) wrapping 23. d) Many 44. d) Cython 67. a) C
3. b) Application 68. a) Modular
24. a) Ctypes 45. a) MinGW
Programming Interface language
25. c) Simplified
4. d) Boost Wrapper Interface 46. c) W64 69. d) COBOL
Generator
5. b) Modular
26. d) SWIG 47. b) MinGW 70. a) Compiler
programming

27. a) Minimalist GNU


6. a) OS module 48. d) g++ 71. b) Interpreter
for windows
7. c) args variable 28. c) g++ 49. d) Absolute path 72. b) Ctypes
50. b) Modular
8. c) __main__ 29. b) CD 73. d) SWIG
Programming
30. d) Python <
9. a) HTML filename.py > < C++ 51. a) Modules 74. b) g++
filename >
10. d) os module name 31. c) Input mode 52. c) Sys.argv 75. b) g++
11. d) All of these 32. a) Tel 53. b) Import sys 76. c) W128
12. c) Perl 33. b) . 54. d) + 77. b) MinGw
13. b) Python 34. d) g++ 55. b) Getopt 78. b) program
14. a) Python 35. d) All of these 56. b) getopt() 79. a) cls
15. b) Python 36. b) argv 57. a) - - name - - 80. a) (.)dot
16. d) Python 37. a) 2 58. b) System() 81. d) Python
17. b) Modular
38. d) a and b 59. b) Cls
language
18. d) All of these 39. b) - - name - - 60. b) Import
63. b) Garbage
19. c) Python 40. c) Opts
collection
20. a) Interpreter 41. a) Run 64. a) '-o'
21. b) Interpreter 42. b) Python 65. c) getopt()

PART B
1. W hat is the theoretical difference between Scripting language and other
programming language?
 The theoretical difference between the two is that scripting languages do not require
the compilation step and are rather interpreted.
 For example, normally, a C++ program needs to be compiled before running
whereas, a scripting language like JavaScript or Python need not be compiled.

K.SIVAPRAKASAM M.SC.,M.PHIL.,B.ED., PGT IN CS, PAAVENDHAR MHSS-M.V.SOUTH, ATTUR 636121 Page 5


 A scripting language requires an interpreter while a programming language requires
a compiler.
 A given language can be called as a scripting or programming language depending
on the environment they are put to use.
2. Differentiate compiler and interpreter.

Compiler Interpreter
Scans the entire program and
Translates program one statement
i. translates it as a whole into
at a time.
machine code.
It takes large amount of time to
It takes less amount of time to
analyze the source code but the
ii. analyze the source code but the
overall execution time is
overall execution time is slower.
comparatively faster.

Programming language like C, C++ Programming language like


iii.
use compilers. Python, Ruby use interpreters.

3. W rite the expansion of (i) SW IG (ii) M inGW


1. SWIG – Simplified Wrapper Interface Generator
2. MINGW – Minimalist GNU for Windows
4. W hat is the use of modules?
 The use of modules to break down large programs into small manageable and
organized files.
 Modules provide reusability of code. Define our most used functions in a module
and import it, instead of copying their definitions into different programs.
5. W hat is the use of cd command. Give an example.
 ‘cd’ command refers to change directory and absolute path refers to the couple path.
(Eg) “cd c:\program files\open office 4\program”
6. Differentiate static typed language and dynamic typed language.
Static typed language:
 A static typed language like C++ requires the programmer to explicitly tell the
computer what “data type” each data value is going to use.
Dynamic typed language:
 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.
7. List some scripting language.
 The most widely used scripting languages are JavaScript, VBScript, PHP, Perl,
Python, Ruby, ASP and Tcl.
8. W hat is garbage collection in python?
 Python deletes unwanted objects (built-in types or class instances) automatically
to free the memory space.
 The process by which Python periodically frees and reclaims blocks of memory
that no longer are in use is called Garbage Collection.

K.SIVAPRAKASAM M.SC.,M.PHIL.,B.ED., PGT IN CS, PAAVENDHAR MHSS-M.V.SOUTH, ATTUR 636121 Page 6


9. W hat is the use of GNU C compiler?
 g++ is a program that calls GCC (GNU C Compiler) and automatically links the
required C++ library files to the object code.
10. How will you execute C++ program through python using M inGW interface?
Give example.
1. Double click the run terminal of MinGW
2. Go to the folder where the Python software is located (Python.exe) is located. In
this example “Python folder” is located in
For example here “Python” is located in
C:\Program Files\OpenOffiice 4\Python.
11. W hat does cd command refers?
 “cd” command refers to change directory and absolute path refers to the
complete path where Python is installed.
12. W rite a note on (i) CD command (ii) Cls command
(i) CD command
 “cd” command refers to change 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.
13. W hat is meant by module?
 Modular programming is a software design technique to split your 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.
14. W rite a note on main (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.
15. W rite the syntax and example of (i) os.system() (ii) getopt()
(i) os.system()
os.system (‘g++’ + <varaiable_name1> ‘-<mode>’ + <variable_name2>
(ii) getopt()
<opts>,<args>=getopt.getopt(argv, options, [long_options])
16. W rite a command for wrapping C++ code.
if __name__=='__main__':
main(sys.argv[1:])
17. W hat is a script language?
 A scripting language is a programming language designed for integrating and
communicating with other programming languages.
 Some of the most widely used scripting languages are JavaScript, VBScript, PHP,
Perl, Python, Ruby, ASP and Tcl.

K.SIVAPRAKASAM M.SC.,M.PHIL.,B.ED., PGT IN CS, PAAVENDHAR MHSS-M.V.SOUTH, ATTUR 636121 Page 7


21. W hat is the use `+' in os.system()?
 ‘+’ in os.system() indicates that all strings are concatenated as a single string and
send that as a List.
PART C
1. Differentiate PYTHON and C++
PYTHON C++
Python is typically an "interpreted"
1 C++ is typically a "compiled" language
language

2 Python is a dynamic-typed language C++ is compiled statically typed language

Data type is not required while Data type is required while declaring
3
declaring variable variable

It can act both as scripting and general


4 It is a general purpose language
purpose language

2. W hat are the applications of scripting language?


 To automate certain tasks in a program
 Extracting information from a data set
 Less code intensive as compared to traditional programming language can bring new
functions to applications and glue complex systems together
3. W hat is M inGW? What is its use?
 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.
 Mingw-W64 (version of mingw) is the best compiler for C++ on Windows. To compile
and execute the C++ program. You need ‘g++’ for Windows. Mingw allows to compile
and execute C++ program
 Dynamically through Python program using g++.
 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.
4. Identify the module ,operator, definition name for the following .
welcome.display()

welcome.display()
Function call

Dot operator

Module name

5. W hat is sys.argv? W hat does it contain?


 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.

K.SIVAPRAKASAM M.SC.,M.PHIL.,B.ED., PGT IN CS, PAAVENDHAR MHSS-M.V.SOUTH, ATTUR 636121 Page 8


6. W rite a note on:
(i) sys module (ii) OS module (iii) getopt module
1. sys module
sys module provides access to some variables used by the interpreter and to
functions that interact with the interpreter
2. OS module
OS module in Python provides a way of using operating system dependent
functionality
3. getopt module
The getopt module of Python helps you to parse (split) command-line options
and arguments.
7. List the commonly used python interfaces.
1. Python-C-API (API-Application Programming Interface for interfacing with C
programs)
2. Ctypes (for interfacing with c programs)
3. SWIG (Simplified Wrapper Interface Generator- Both C and C++)
4. Cython (Cython is both a Python-like language for writing C-extensions)
5. Boost. Python (a framework for interfacing Python and C++)
6. MinGW (Minimalist GNU for Windows)
8. How to import modules in python?
 We can import the definitions inside a module to another module. We use the import
keyword to do this. To import our previously defined module factorial we type the
following in the Python prompt.
>>> import factorial
 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>
 For example:
 >>> factorial.fact(5)
 120
PART D
1. W rite any 5 features of Python.
1. Python uses Automatic Garbage Collection whereas C++ does not.
2. C++ is a statically typed language, while Python is a dynamically typed language.
3. Python runs through an interpreter, while C++ is pre-compiled.
4. Python code tends to be 5 to 10 times shorter than that written in C++.
5. In Python, there is no need to declare types explicitly where as it should be done
in C++
6. 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.

K.SIVAPRAKASAM M.SC.,M.PHIL.,B.ED., PGT IN CS, PAAVENDHAR MHSS-M.V.SOUTH, ATTUR 636121 Page 9


2. W hat is the purpose of sys, os, getopt module in Python.Explain
(i) Python’s sys module sys.argv :
 It's basically an array.
 Holding the command-line arguments of the program.
 It contains all the items via the command-line input To use sys.argv, you
will first have to import Sys.
 The first argument, sys.argv[0], is always the name of the program
sys.argv[1] is the next argument you pass to the Program.
(ii) Python's OS M odule os.system():
 The OS module allows you to interface with the Windows operating system
where Python is running on.
 Syntax:
 os.system (‘g++’ + <varaiable_name1х ‘-<modeх’ + <variable_name2>
 Example:
 os.system(‘g++’ + cpp_file + ‘-o’ + exe_file)
 g++ compiler compiles the file cpp_file and -o (output) send to exe_file
(iii) Python getopt module:
 The getopt module of Python helps you to split command-line options and
arguments. getopt() method returns value consisting of two elements.
1. opts and
2. args .
1. Opts contains list of splitted strings like mode, path.
2. args contains any string if at all not splitted . args will be an empty
array if there is no error in splitting strings by getopt().
Syntax:
opts, args = getopt.getopt (argv, "i:",['ifile='])

K. SIVAPRAKASAM, M .Sc., M .Phil., B.Ed.,


PG ASST IN COM PUTER SCIENCE
PAAVENDHAR MATRIC. HR. SEC. SCHOOL,
M .V. SOUTH (PO), ATTUR (TK),
SALEM (DT), PIN – 636121
Email: [email protected]
Contact No: 7904805300, 9566958422

K.SIVAPRAKASAM M.SC.,M.PHIL.,B.ED., PGT IN CS, PAAVENDHAR MHSS-M.V.SOUTH, ATTUR 636121 Page 10

You might also like