1.

Write a C++ program to create a class called Student with the following details?Protected memberRno integerPublic membersvoid Readno(int); to accept roll number and assign to Rnovoid Writeno( ); To display Rno.The class Test is derived Publically from the Studentclass contains the following detailsProtected memberMark1 floatMark2 floatPublic membersvoid Readmark(float, float);To accept mark1 and mark2void Writemark( ); To display the marksCreate a class called Sports with the following detailProtected membersscore integerPublic membersvoid Readscore(int); To accept the scorevoid Writescore( ); To display the scoreThe class Result is derived Publically from Test and Sports class contains the following – details Private memberTotal floatPublic membervoid display( ) assign the sum of mark1, mark2, score in totalinvokeWriteno( ), Writemark( ) and Writescore( ). Display the total also.Save the C++ program in a file called hybrid. Write a python program to execute the hybrid.cpp

Answer»

In Notepad, type the C++ program

#include<iostream>

using namespace std;

class student

protected:

int mo;

public:

void readno(int rollno)

{

mo = rollno;

}

void writeno( )

{

cout<< “\n Roll no:” <<rno;

}};

class test: public student

{

protected:

float mark1,mark2; 

public:

void readmark(float m1, float m2)

{

mark1 = m1;

mark2 = m2;

}

void writemark( )

{

cout<< “\n mark1 ” << mark1;

cout<< “\n mark2 ” << mark2;

}};

class sports

{

protected:

int score;

public:

void readscore(int s)

{

score = s;

}

void writescore( )

{

cout<< “SCORE : ” <<score;

}};

class result: public test, public sports

{

private: float total; public:

void display( )

{

total = mark1 + mark2;

cout<< “TOTAL MARKS: ” <<total;

}};

int main( )

{

result r;

r.readno(5);

r.readmark(100,100);

r.readscore(200);

r.writeno( );

r.writemark( );

r.display( );

r.writescore( );

}

save this file as hybrid.cpp

Now type the python program in New Notepad file. 

# python hybrid.py -i hybrid.cpp

import sys,os,getopt def main(argv): cpp Jile = ” exe_file = ”

opts, args = getopt.getopt(argv, “i:” ,[‘ifile-])

for o, a in opts:

if o in(“-i” , “–file”):

cpp_file = ”a+ ‘.cpp’

exe_file = a+ ‘.exe’

run(cpp_file, exefile)

def run(cpp_file, exe_file):

print(“Compiling” + cpp_file)

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

print(“Running” + exefile)

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

print

os.system(excfile)

print

if name == ’ main

main(sys.argv[1:])

Output:

Rollno : 5

Mark1 : 100

Mark2 : 100

TOTAL MARKS : 200

SCORE : 200



Discussion

No Comment Found