Whats in this post?
- Background and Explanation of the code
To copy code: Click “View Source” on the right of this code snippet.
Background and Explanation of the code
In this program we create a base class stud_base having private data members rollno, name and public member functions read ( ), show ( ) for inputting and displaying values.Then we drive a class result publicly from stud_basic for calculating and displaying result.The derive class contains private data members an array of marks m  , per and public member functions input_marks ( ), cal ( ) and display ( ).Since the base class is inherited as public , so in main ( ) the object r1 of derived class result can invoke the public member functions of both base as well as derived classes.After creating the object r1 of the derived class, the statement r1.read ( ); in the main ( ) on execution invokes the public member function read ( )of the stud_basic class to input rollno and name of the student .The next statement invokes public member function input_marks ( ) of the result class to input marks of 4 subjects .The statement r1.cal (); invokes the public cal ( ) member function of result to calculate the percentage.The remaining statements in the main ( ) displays all information.
Enter rollno and name : 5134 kapil
Enter marks : 74 70 68 82
Rollno = 5134
Name = kapil
Displaying marks : 74 70 68 82
Percentage = 73.5