Wednesday, October 9, 2013

Virtual Base Class ( Student, Marks, Behaviour, ECA & Result ) C++ Program

#include<conio.h>
#include<iostream.h>

class student
{
    public:
    int roll,id;
    char name[20],std[6];
    void getstudent()
    {
        cout<<"\n\tEnter Student Details \n";
        cout<<"\nEnter ID No :";cin>>id;
        cout<<"\nEnter STD : ";cin>>std;
        cout<<"\nEnter Name : ";cin>>name;
    }
};


class marks:virtual public student
{
    public:
    int marks[7],i;
    void getmarks();
};
void marks :: getmarks()
{
        cout<<"\nEnter Subject's Marks : \n";
        for(i=0;i<6;i++)
        {
            cout<<"\nEnter "<<i+1<<" Subject's Mark : ";cin>>marks[i];
        }
}
class behaviour:virtual public student
{
    public:
    char grade;
    int mrk;
    void getbehaviour()
    {
        cout<<"\nEnter Student's Grade :";cin>>grade;
        if(grade=='A+') mrk=90;
        else if(grade=='A')mrk=80;
        else if(grade=='B+')mrk=70;
        else if(grade=='B')mrk=60;
        else if(grade=='C+')mrk=50;
        else if(grade=='C')mrk=35;
        else mrk=20;
    }
};
class ECA:virtual public student
{
    public:
    int extra;
    void geteca()
    {
        cout<<"\nEnter Extra Curricular Activity's Marks ";cin>>extra;
    }
};

class result:public ECA,public behaviour,public marks
{
    public:
    int to;
    float pr;
    void showresult();
};
void result :: showresult()
{
        cout<<"\n\n\t\tStudent's Status ";
        cout<<"\n ID : "<<id;
        cout<<"\n Name : "<<name;
        cout<<"\n STD : "<<std;
        cout<<"\n\n Sub Marks : ";
        to=0;
        for(i=0;i<6;i++)
        {
            cout<<"\nSub "<<i+1<<" Marks : "<<marks[i];
            to=to+marks[i];
        }
        pr=(to*100)/600;
        cout<<"\n\n Total Marks : "<<to;
        cout<<"\n Percentage : "<<pr;
        cout<<"\n Grade : "<<grade;
        cout<<"\n Extra Curricular Activity's Marks : "<<extra;
}
int main()
{
    clrscr();
    int i,n;
    result cool[10];
    cout<<"\n\tHow many Records you want to store ? ";cin>>n;

    for(i=0;i<n;i++)
    {
        cool[i].getstudent();
        cool[i].getmarks();
        cool[i].getbehaviour();
        cool[i].geteca();
    }

    clrscr();


    for(i=0;i<n;i++)
    {
        cool[i].showresult();
    }

    getch();
    return 0;
}

No comments:

Post a Comment