செயற்கூறுகளைக் கொண்ட C++ நிரல்களை இயக்கும் பைத்தான்
நிரல்
இப்பொழுது நீங்கள் செயற்கூறுகள்
மற்றும் செயற்கூறு அழைப்புகள் கொண்ட C++ நிரலை இயக்க பைத்தான் Scriptஐ சோதிக்க போகிறீர்கள்.
எடுத்துக்காட்டு 14.10.1 - பயனர் வரையறுத்த செயற்கூறினைக் கொண்டு ஒரு
எண்ணின் கனத்தினை கண்டறியும் C++ நிரலை எழுதுக.
#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 FileNew 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):
opts,
args = getopt.getopt(argv, "i:")
for o,
a in opts:
if o in
"-i":
run(a)
def
run(a):
inp_file=a+'.cpp'
exe_file=a+'.
exe
os.system('g++
' + inp_file +' -o ' + exe_file)
os.system(exe_file)
if
_name_=='__main__':
main(sys.argv[1:])
------------------------------------------------------------------------------------
மேற்கண்ட நிரலின் வெளியீடு
Enter
any number:
5
Cube of
5 is 125