Use app×
Join Bloom Tuition
One on One Online Tuition
JEE MAIN 2025 Foundation Course
NEET 2025 Foundation Course
CLASS 12 FOUNDATION COURSE
CLASS 10 FOUNDATION COURSE
CLASS 9 FOUNDATION COURSE
CLASS 8 FOUNDATION COURSE
0 votes
379 views
in Importing C++ Programs in Python by (49.1k points)
closed by

Write a C++ program to implement multilevel inheritance. Write a python program to execute it?

1 Answer

+1 vote
by (54.8k points)
selected by
 
Best answer

// 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”<<end1;

}

};

class threeWheeler: public Vehicle

{public:

threeWheeler( )

{

cout<<“Objects with 3 wheels are vehicles”<<end1;

}

};

// sub class derivedfrom two base classes

class Auto: public threeWheeler

{

public:

Auto( )

{

cout<<“Auto has 3 Wheels”<<end1;

}

// 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= 11

opts, args = getopt.getopt (argv, 11i: 11 ,[‘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 11 + cpp file)

os.system (‘g++’ + cpp_file +’ -o ‘+ exe_file)

print (“Running”+ exe file)

print(“........“)

print

os.system (exefile) print

if_name_== ’_main_’:

main (sys.argv[1:])

Output of the above program

Compiling c:\pyprg\class_file.cpp

Running c:\pyprg\class_file.exe

This is a Vehicle

Objects with 3 wheels are vehicles

Auto has 3 Wheels

Welcome to Sarthaks eConnect: A unique platform where students can interact with teachers/experts/students to get solutions to their queries. Students (upto class 10+2) preparing for All Government Exams, CBSE Board Exam, ICSE Board Exam, State Board Exam, JEE (Mains+Advance) and NEET can ask questions from any subject and get quick answers by subject teachers/ experts/mentors/students.

...