My photo
Bangalore, Karnataka, India
Extending one hand to help someone has more value rather than joining two hands for prayer

Archives

program to enter the name and email of students using link list

Tuesday, September 1, 2009

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
class student
{
 int roll,fee;
 char name[20],email[20];
 public:
 void getdata();
 void show();
};
 void student::getdata()
  {
    cout<<"enter roll no. "<<endl;
    cin>>roll;
    cout<<"enter name  "<<endl;
    gets(name);
    cout<<"Enter email "<<endl;
    gets(email);
    cout<<"Enter fee "<<endl;
    cin>>fee;
  }
 void student::show()
  {
   cout<<"roll num" << roll<<endl;
   cout<<"name is "<<name<<endl;
   cout<<"email "<<email<<endl;
   cout<<"fee "<<fee<<endl;
  }
 struct node
{
 student info;
 node *link;
};

  class linkedlist
   {
    node *start;
    public:
    linkedlist()
    {
     start=NULL;
    }
    void insertbeg(student);
    void display();
   };

     void linkedlist::insertbeg(student a)
     {
       node *p=new node;
       p->info=a;
       p->link=start;
       start=p;
     }
     void linkedlist:: display()
      {
       node *p=start;
       student n;
       while(p!=NULL)
    {
     n=p->info;
     n.show();
     p=p->link;
     cout<<endl<<endl;
    }
      }

 void main()
  {
   clrscr();
   student m1,m2,m3;
   m1.getdata();
   m2.getdata();
   m3.getdata();
   linkedlist l1;
   l1.insertbeg(m1);
   l1.insertbeg(m2);
   l1.insertbeg(m3);
   cout<<endl<<endl<<endl;
   l1.display();
   getch();
  }

0 comments: