Code Competitions

Coding competition

Thursday, 13 June 2013

program to display student record using nested classes

#include<iostream.h>
#include<conio.h>
class stud_info
{
    private:
    char *name;
    int rn;
    char s[8];
    public:
    void getdata();
    void display();
    class date
    {
        private:
        int mm,dd,yy;
        public:
        void getdata();
        void display();
        class t_age
        {
            private:
            float age;
            public:
            void getdata();
            void display();
        };
    };
};
void stud_info::getdata()
{
    cout<<"enter the student name,sex,roll number ";
    cin>>name;
    cin>>s;
    cin>>rn;

}
void stud_info::display()
{
    cout<<"\nstudent record is "<<name <<" sex "<<s <<" roll number "<<rn;
}
void stud_info::date::getdata()
{
    cout<<"\nenter the date of birth in dd mm yy format ";
    cin>>dd>>mm>>yy;
}
void stud_info::date::display()
{
    cout<<"\nthe date of birth is "<<dd<<" "<<mm<<" "<<yy;
}
void stud_info::date::t_age::getdata()
{
    cout<<"\nenter the age ";
    cin>>age;
}
void stud_info::date::t_age::display()
{
    cout<<"\nthe age of student "<<age;
}
void main()
{
    clrscr();
    class stud_info s;
    class stud_info::date d;
    class stud_info::date::t_age a;
    s.getdata();
    d.getdata();
    a.getdata();
    s.display();
    d.display();
    a.display();
    getch();
}

No comments:

Post a Comment