St. Britto Hr. Sec. School - Madurai
12th Computer Science Monthly Test - 1 ( Importing C++ programs in Python. )-Aug 2020
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
Write a note on main (sys.argv [ 1 ]).
-
How will you execute C++ program through python using MinGW interface? Give example.
-
What is garbage collection in python?
-
Write a command for wrapping C++ code.
-
Write the syntax and example of
(i) os.system () (ii) getopt ()
-
Write a note on
(i) CD command
(ii) Cls command
-
What is the theoretical difference between Scripting language and other programming language?
-
Differentiate static typed language and dynamic typed language.
-
What is the use of cd command. Give an example.
-
What are the applications of scripting language?
-
What is MinGW? What is its use?
-
Write an algorithm for executing C++ program pali_cpp.cpp using python program.pali.py.
-
List the commonly used python interfaces.
-
What is sys.argv? What does it contain?
-
Differentiate PYTHON and C++
-
-
// C++ program to print the message Hello
//Now select File→New in Notepad and type the C++ program
#include<iostream>
using namespace std;
int main()
{
std::cout<<"hello"
return 0;
}
// Save this file as hello.cpp
#Now select File→New in Notepad and type the Python program as main.py
# Program that compiles and executes a .cpp file
# Python main.py -i hello
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:]) -
Identify the module ,operator, definition name for the following
welcome.display()
-
-
Write a note on (i) sys module (ii) OS module (iii) getopt module
-
Write a C++ program to print Transpose of a matrix(2 D array).*/
//Now select File->New in Notepad and type the 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("cls");
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++)
co
ut<<a[j][i]<<' ';
cout<<endl ;
}
return 0;
}
// Save this file as trans_cpp.cpp
//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
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:]) -
How to import modules in python?
-
Write any 5 features of Python.
-
-
Write a python program to execute the following C++ program.
-
Write a python program to execute the following C++ program.
-
-
What is the purpose of sys,os,getopt module in Python.Explain
-
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:]) -
Write a C++ program using a user defined function to function cube of a number
/*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 <iostream>
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
#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 -i c:\pyprg\cube_file.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'
ex_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:])