ஓர் இனக்குழுவின் மரபுரிமத்தை விளக்கும் பைத்தான்
நிரல்
நீங்கள் இப்பொழுது C++-ன் இனக்குழு நிரலை செயல்படுத்த போகிறீர்கள்.
இந்த இனக்குழு நிரல் பலநிலை மரபுரிமத்தைக் கொண்டுள்ளது. மேலும், இது பைத்தான்
Scriptஐ பயன்படுத்தி வெளியீட்டை தருகிறது.
எடுத்துக்காட்டு 14.11.1 - பலநிலை மரபுரிமத்தை செயல்படுத்தும் C++நிரல்
// 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:
Auto()
{
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):
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 + ' -0 ' + exe_file)
Os.system(exe_file)
if_name_=='_main_': -
main(sys.argv[1:])
-------------------------------------------------------------------
மேற்கண்ட நிரலின் வெளியீடு
This is a Vehicle
Objects with 3 wheels are
vehicles
Auto has 3 Wheels
இந்த எடுத்துக்காட்டிலிருந்து, C++ நிரல்களை ஒருங்கிணைக்கப்
பயன்படுத்தப்படும் பைத்தான் Script பொதுவானது என்பதை புரிந்துக் கொள்ளலாம். பைத்தான்
Script கோப்பு மற்றும் C++ (cpp) கோப்பின் பெயர்கள் மட்டும் மாற்றியமைக்கப்பட்டுள்ளது.
ஒருவருடைய கணினியில் முன்பே C++ கோப்பு இருந்தால், C++குறிமுறையை உள்ளீடு செய்வது கட்டாயமில்லை
என்பதை கவனத்தில் கொள்ளவும். இந்தப் பாடப்பகுதியில், பைத்தான் மூலம் சாதாரண செயற்கூறுவைப்
போல் மரபுரிமத்தை போன்ற அனைத்து வகை c++ நிரல்களிலும் செயல்படுத்த முடியும் என்பதைக்
காண்பிக்க C++ நிரல் குறிமுறைவெளிப்படையாக குறிப்பிடப்பட்டுள்ளது. இத்தகைய பைத்தான்
Script ஐ பயன்படுத்தி, நீங்கள் C நிரல்களையும் தொகுத்து, செயல்படுத்திக் கொள்ளலாம்.
பைத்தான், அதன் IDE இல்லாமலேயே தன்னிச்சையாக C++ நிரல் கோப்பை செயல்படுத்துவதால், அதனை
Scripting மொழி எனவும் அழைக்கலாம்.