English
Tamil Nadu Board of Secondary EducationHSC Science Class 12

Write a Python program to execute the following c++ coding. #include<iostream>using namespace std; int main(){ cout<<“WELCOME”;return(0);} The above C++ program is saved in a file welcome. cpp. - Computer Science

Advertisements
Advertisements

Question

Write a Python program to execute the following c++ coding.

#include<iostream>
using namespace std;
int main()
{ cout<<“WELCOME”;
return(0);
}
The above C++ program is saved in a file welcome. cpp.

Answer in Brief
Advertisements

Solution

#include<iostream>
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
——————-

shaalaa.com
Python Program Executing C++ Program Using Control Statement
  Is there an error in this question or solution?
Chapter 14: Importing C++ programs in Python - Evaluation [Page 290]

APPEARS IN

Samacheer Kalvi Computer Science [English] Class 12 TN Board
Chapter 14 Importing C++ programs in Python
Evaluation | Q 5. | Page 290
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×