C++ Program For Multiple Inheritance

Free C++ course with real-time projects Start Now!!

Program 1

// Program for method overloading
#include<iostream>
#define clrscr() system("cls")
using namespace std;
class Student
{
    protected:
       int rno;
       char name[50];
       public:
    //    Student()
    //    {
    //     cout<<"\n constructor of student class";
    //    }
       void getStudent();
};
void Student::getStudent()
{
    cout<<"\n Enter roll no :";
    cin>>rno;
    cout<<"\n Enter name: ";
    cin>>name;
}
class Mark
{
    protected:
       int h,m,e,c;
     public:  
    //    Mark()
    //    {
    //     cout<<"\n constructor of mark class";
    //    }
       void getMark();
};
void Mark::getMark()
{
    cout<<"\n Enter marks of hindi";
    cin>>h;
    cout<<"\n Enter marks of english";
    cin>>e;
    cout<<"\n Enter marks of maths";
    cin>>m;
    cout<<"\n Enter marks of computer";
    cin>>c;
}
class Result:public Mark,public Student
{
       int total,per;
    public:
    // Result()
    //    {
    //     cout<<"\n constructor of result class";
    //    }
    void calculate()
    {
      total=h+e+m+c;
      per=total/4;
    }   
    void displayResult()
    {
        cout<<"Roll No: "<<rno << "     " <<"Name: "<<name<<"\n";
        cout<<"Hindi: "<<h<<" English: "<<e<<" Maths: "<<m<<" Computer: "<<c;  
        cout<<"\n Total Marks:  "<<total<<"     "<<"Percentage: "<<per<<"%";
    }
};
int main()
{
    clrscr();    
    Result R;
    R.getStudent();
    R.getMark();
    R.calculate();
    R.displayResult();
    return 0;

}

 

Did you know we work 24x7 to provide you best tutorials
Please encourage us - write a review on Google

follow dataflair on YouTube

Leave a Reply

Your email address will not be published. Required fields are marked *