1.

Write a Python program to execute the following C++ coding?

Answer»

#include<iostream>

using namespace std;

int main( )

{ cout« “WELCOME”;

return (0);

}

The above C++ program is saved in a file welcome.cpp

Python program

Type in notepad and save as welcome.cpp #include<include>

using namespace std;

int main( )

{

cout<<“WELCOME”;

retum(0);

}

Open Notepad and type python program and save as welcome.py 

import sys,os,getopt

def main(argv):

cppfile = ”

exefile = ”

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

...................



Discussion

No Comment Found