Friday, May 18, 2018

SINGLE INHERITANCE EXAMPLE IN C++

#include<iostream.h>
#include<conio.h>
class Student
{
 char name[20];
  public:
     char dept[10];
     int roll;
     int year;
    void get();
};
class Marks : public Student
{
 int math;
 int c;
 public:
     int total;
     void calculate()
     void show();
};
void Student :: get()
{
 cout<<"Enter the student name"<<endl;
 cin>>name;
 cout<<"Enter Roll"<<endl;
 cin>>roll;
 cout<<"Enter student department"<<endl;
 cin>>dept;
 cout<<"Enter year of passing"<<endl;
 cin>>year;
}
void Marks :: calculate()
{
 cout<<"Enter the obtained marks in maths"<<endl;
 cin>>math;
 cout<<"Enter the obtained marks in c"<<endl;
 cin>>c;
 total=math+c;
}
void Marks :: show()
{
 cout<<"Details of the student"<<endl;
 cout<<"Student Roll="<<roll<<endl<<"Student Depertment="<<dept<<endl<<"Year of passing="<<year<<endl<<"Total marks obtained="<<total<<endl;
}
void main()
{
 Marks ob;
 clrscr();
 ob.get();
 ob.calculate();
 ob.show();
 getch();
}

                             OUTPUT


No comments:

Post a Comment