Friday, February 5, 2016

MULTILEVEL INHERITANCE

AIM:
         To implement a C++ program to find out the student details using multilevel inheritance.
ALGORITHM:
Step 1: Include the header files
Step 2: Declare the base class student.
Step 3: Declare and define the function get_ number ( ) and put_number( ).
Step 4: Declare the derived class test for student
Step 5: Declare and define the function get_ marks ( ) and put_marks( ).
Step 6: Declare the derived class result for test
Step 7: Declare and define the function display ( )
Step 8: Create objects for the derived class.
Step 9: Declare the derived class object, call the functions get_ number ( ), get_ marks ( ), display ( ).

PROGRAM:

#include<iostream.h>
#include<conio.h>
class student
{
protected:
 int roll;
public:
 void get_number(int a)
 {
  roll = a;
 }
  void put_number()
 {
  cout<<"Roll Number: "<<roll<<"\n";
 }
};
class test : public student

{
protected:
 float sub1;
 float sub2;
public:
 void get_marks(float x,float y)
 {
  sub1 = x;
  sub2 = y;
 }
 void put_marks()
 {
  cout<<"Marks in Subject 1 = "<<sub1<<"\n";
  cout<<"Marks in Subject 2 = "<<sub2<<"\n";
 }
};

class result : public test
{
private:
float total;
public:
void display()
 {
  total = sub1 + sub2;
  put_number();
  put_marks();
  cout<<"Total = "<<total<<"\n";
 }
};
void main()
{
clrscr();
result student;
student.get_number(83);
student.get_marks(99.0,98.5);
student.display();
getch();
}


SAMPLE OUTPUT:

Roll No: 83
Marks in sub 1:99
Marks in sub 2:98.5
Total: 197.5
RESULT:
                Thus a C++ program to find out the student details using multilevel inheritance is implemented successfully.

No comments:

Post a Comment