St. Britto Hr. Sec. School - Madurai
12th Computer Science Monthly Test - 2 ( Importing C++ programs in Python. )-Aug 2020
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
Write a note on main (sys.argv [ 1 ]).
-
Write a command for wrapping C++ code.
-
Differentiate PYTHON and C++
-
Write an algorithm for executing C++ program pali_cpp.cpp using python program.pali.py.
-
List the commonly used python interfaces.
-
How to import modules in python?
-
What are the applications of scripting language?
-
Identify the module ,operator, definition name for the following
welcome.display() -
-
Write a note on (i) sys module (ii) OS module (iii) getopt module
-
What is sys.argv? What does it contain?
-
-
-
Write a python program to execute the following C++ program.
-
C++ program to implement Multilevel Inheritance
// C++ program to implement Multilevel Inheritance
//Now select File→New in Notepad and type the C++ program
#include <iostream>
using namespace std;
// base class
class Vehicle
{
public:
Vehicle()
{
cout<< "This is a Vehicle" <<endl;
}
};
class threeWheeler: public Vehicle
{ public:
threeWheeler()
{
cout<<"Objects with 3 wheels are vehicles"<<endl;
}
};
// sub class derived from two base classes
class Auto: public threeWheeler{
public:
A
uto()
{
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
//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
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:])
-
-
What is the purpose of sys,os,getopt module in Python.Explain
-
Write a python program to execute the following C++ program.
-
Explain each word of the following command.
Python-< filename.py >- < i > <C++ filename without cpp extension > -
Explain the commands for wrapping C++ code.