Write a program to perform Single Inheritance

/* Student Single Inheritance */

#include<iostream>
using namespace std;

class Student
{
   protected:
 
   int roll_no;
   char name[20];
   
   public:
void accept()
{
cout<<"\n\n Enter Rollno and Name: ";
cin>>roll_no>>name;
}         



};

class Marks : public Student
{
   int m1,m2,m3,total;
   float percentage;

    public:
     void accept1()
{
    cout<<"\n\n Enter 3 subject marks:";
cin>>m1>>m2>>m3;
}

void cal()
{
total=m1+m2+m3;
percentage=total/3.0;
}

void display()
{
cout<<"\n\n Name: "<<name;
cout<<"\n Rollno: "<<roll_no;
cout<<"\n Total: "<<total;
cout<<"\n Percentage: "<<percentage;
}
};

int main()
{
Marks m;

m.accept();
m.accept1();
m.cal();

m.display();

return 0;
}



Previous
Next Post »