Page

Multilevel Inheritance example in C++

#include<iostream.h>
#include<conio.h>
#include<string.h>
class student    
{
private:
  int rl;
  char nm[20];
public:
   void read();
   void display();
};
class marks : public student 
{
protected:
  int s1;
  int s2;
  int s3;
public:
   void getmarks();
   void putmarks();
};
class result : public marks 
{
private:
  int t;
  float p;
  char div[10];
public:
   void process();
   void printresult();
};
   void student::read()
   {
    cout<<"enter Roll no and Name "<<endl;
    cin>>rl>>nm;
   }
   void student:: display()
   {
   cout <<"Roll NO:"<<rl<<endl;
   cout<<"name : "<<nm<<endl;
   }
   void marks ::getmarks()
   {
   cout<<"enter three subject marks  "<<endl;
    cin>>s1>>s2>>s3;
   }
   void marks ::putmarks()
   {
    cout <<"subject 1:"<<s1<<endl;
    cout<<" subject 2 : "<<s2<<endl;
    cout <<"subject 3:"<<s3<<endl;
   }

   void result::process()
   {
     t= s1+s2+s3;
     p = t/3.0;
     p>=60?strcpy(div,"first"):p>=50?strcpy(div, "second"): strcpy(div,"third");
   }

   void result::printresult()
   {
    cout<<"total = "<<t<<endl;
    cout<<"per  = "<<p<<endl;
    cout<<"div = "<<div<<endl;
   }
   void main()
   {
    result x;
    clrscr();
    x.read();
    x.getmarks();
    x.process();
    x.display();
    x.putmarks();
    x.printresult();
    getch();
   }

1 comment: