/* 11. Write a C++ program to create a base class called as STUDENT (Name,Regno,age) and using inheritance, create classes Ugstudent and Pgstudent having fields as semester,fees ans stipend. Enter the data for atleast 5 students.Find the average age,semester wise, for all UG and PG students separately. */


#include<iostream.h>
#include<conio.h>
class STUDENT
{
    protected:
        int age,regno;
        char *name;

    public:
        void Readdata()
        {
            cout<<"\nEnter Name, Regno and Age : ";
            cin>>name>>regno>>age;
        }
};
class UGSTUDENT:public STUDENT
{
    int semester;
    float fees,stipend;
    public:
        void ReadUGdata();
        void AvgUGage();
};
void UGSTUDENT::ReadUGdata()
{
    Readdata();
    cout<<"\nEnter semester,fees and stipend : ";
    cin>>semester>>fees>>stipend;
}
void UGSTUDENT::AvgUGage()
{
    int n,sum,count;
    cout<<"\nEnter the number of students : ";
    cin>>n;
    UGSTUDENT x[10];
    for (int i=0; i<n; i++)
        x[i].ReadUGdata();
    cout<<"\n\nSemester\t\tAverage Age\n";
    for (i=1; i<=8; i++)
    {
        sum=count=0;
        for (int j=0; j<n; j++)
            if (x[j].semester == i)
            {
                sum+=x[j].age;
                count++;
            }
        if (sum)
            cout<<'\t'<<i<<"\t\t"<<float(sum)/count<<endl;
        else
            cout<<'\t'<<i<<"\t\tNIL"<<endl;
    }
}
class PGSTUDENT:public STUDENT                                                                                                    {
    int semester;
    float fees,stipend;
    
    public:
        void ReadPGdata();
        void AvgPGage();
};

void PGSTUDENT::ReadPGdata()
{
    Readdata();
    cout<<"\nEnter semester,fees and stipend : ";
    cin>>semester>>fees>>stipend;
}
void PGSTUDENT::AvgPGage()
{
    int n,sum,count;
    cout<<"\nEnter the number of students : ";
    cin>>n;
    PGSTUDENT x[10];
    for (int i=0; i<n; i++)
        x[i].ReadPGdata();
    cout<<"\n\nSemester\t\tAverage Age\n";
    for (i=1; i<=8; i++)
    {
        sum=count=0;
        for (int j=0; j<n; j++)
            if (x[j].semester == i)
            {
                sum+=x[j].age;
                count++;
            }
        if (sum)
            cout<<'\t'<<i<<"\t\t"<<float(sum)/count<<endl;
        else
            cout<<'\t'<<i<<"\t\tNIL"<<endl;
    }
}
void main()
{
    UGSTUDENT x;
    clrscr();
    cout<<"\nEnter the details for UG students : ";
    x.AvgUGage();
    PGSTUDENT y;
    cout<<"\nEnter the details for PG students : ";
    y.AvgPGage();
    getch();
}