Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

#include<iostream>

#include<conio.h>
#include<fstream>
#include<stdio.h>
#include<stdlib.h>
#include<string>
#include<Cstdio>
using namespace std;
class Node
{
public:
int roll_no, Phone_no;
string Name,Father_Name;
string Course , quali ;
Node *next_add;

};
class linked_list
{
public:
Node *head = NULL;

void Insert()
{
fstream file;
file.open("Items.txt",ios::app);
int r;
string n;
string c;
string e;
int ph;

cout<<"\n\n Enter Student id";


cin>>r;
cout<<"\n\n Enter Student Name";
cin>>n;
cout<<"\n\n Enter Father Name";
cin>>c;
cout<<"\n\n Enter Student Qualification";
cin>>e;
cout<<"\n\n Enter Student Phone no";
cin>>ph;
Node *new_Node = new Node;
new_Node->roll_no=r;
new_Node->Name=n;
new_Node->Course=c;
new_Node->quali=e;
new_Node->Phone_no=ph;
new_Node->next_add=NULL;

file<<new_Node->roll_no<<"\n"<<endl;
file<<new_Node->Name<<"\n"<<endl;
file<<new_Node->Course<<"\n"<<endl;
file<<new_Node->quali<<"\n"<<endl;
file<<new_Node->Phone_no<<"\n"<<endl;
file.close();
if(head==NULL)
{
head =new_Node;
}
else
{
Node *ptr=head;
while(ptr->next_add != NULL)
{
ptr = ptr->next_add;
}
ptr->next_add=new_Node;
}
cout<<"\n\n new Node Inserted Successfully"<<endl;
}

void Search()
{
if(head==NULL)
{
cout<<"\n\n Linked list is Empty"<<endl;
}
else
{
int r,found=0;
cout<<"\n\n Enter Student id for search"<<endl;
cin>>r;
Node *ptr= head;
while(ptr != NULL)
{
if(r == ptr -> roll_no)
{
cout<<"\n\n Student Id:"<<ptr->roll_no<<endl;
cout<<"\n\n Student Name:"<<ptr->Name<<endl;
cout<<"\n\n Student Father_Name:"<<ptr->Course<<endl;
cout<<"\n\n Student Qualification:"<<ptr->quali<<endl;
cout<<"\n\n Student Phone No:"<<ptr->Phone_no<<endl;
found++;
}

ptr = ptr -> next_add;


}
if(found==0)
{
cout<<"\n\n search Student Id:"<<r<<"can't found"<<endl;
}
}
}

void Count()
{
if(head==NULL)
{
cout<<"Linked list is Empty"<<endl;
}
else
{
int c=0;
Node *ptr=head;
while(ptr!=NULL)
{
c++;
ptr =ptr->next_add;
}
cout<<"\n\n Total Numbers of Records:"<<c<<endl;
}
}

void Update()
{
if(head==NULL)
{
cout<<"Linked list is Empty"<<endl;
}
else
{
int r,found=0;
cout<<"\n\n Enter Student Id for Updation"<<endl;
cin>>r;
Node *ptr=head;
while(ptr!=NULL)
{
if(r == ptr -> roll_no)
{
cout<< "\n\n Enter New Student Id" <<endl;
cin>>ptr->roll_no;
cout<< "\n\n Enter New Student Name" <<endl;
cin>>ptr->Name;
cout<< "\n\n Enter New Student Father Name"
<<endl;
cin>>ptr->Course;

cout<< "\n\n Enter New Student Qualificaton"


<<endl;
cin>>ptr->quali;
cout<< "\n\n Enter New Student PhoneNumber"
<<endl;
cin>>ptr->Phone_no;

cout<<"Record Update Successfully"<<endl;


found++;
}

ptr=ptr->next_add;
}

if(found==0)
{
cout<<" Update Student Id"<<r<<"can't Found"<<endl;

}
}
}
void Delete()
{
if(head==NULL)
{
cout<<"Linked list is Empty"<<endl;
}
else
{
int r,found=0;
cout<<"\n\n Enter Student Id for deletion"<<endl;
cin>>r;
if(r==head->roll_no)
{
Node *ptr=head;
head = head->next_add;
cout<< "Record Deleted Successfully" <<endl;
found++;
delete ptr;
}
else
{
Node *pre=head;
Node *ptr=head->next_add;
while(ptr!=NULL)
{
if(r=ptr->roll_no)
{
pre->next_add = ptr->next_add;

cout<< "Record Deleted Successfully" <<endl;


found++;
delete ptr;
break;
}
pre=ptr;
ptr=ptr->next_add;
}
}
if(found==0)
{
cout<<"Delete Student Id"<<r<<"can't Found"<<endl;

}
}
}

void Show()
{
if(head==NULL)
{
cout<<"\n\n Linked list is Empty"<<endl;
}
else
{
Node *ptr=head;
while(ptr!=NULL)
{
cout<< "\n\n Student Id =" << ptr->roll_no <<endl;
cout<< "\n\n Student Name =" <<ptr->Name<<endl;
cout<< "\n\n Student Father Name =" << ptr->Course <<endl;
cout<< "\n\n Student Course =" <<ptr-> quali <<endl;
cout<< "\n\n Student PhoneNumber =" << ptr->Phone_no <<endl;
ptr=ptr->next_add;
}
}
}

void Showfile()
{
string s1;
string s2;
string s3;
string s4;
string s5;
string s6;
string s7;
string s8;
string s9;
string s10;
string s11;
string s12;

ifstream ln("Items.txt");
getline(ln,s1);
getline(ln,s2);
getline(ln,s3);
getline(ln,s4);
getline(ln,s5);
getline(ln,s6);
getline(ln,s7);
getline(ln,s8);
getline(ln,s9);
getline(ln,s10);
getline(ln,s11);
getline(ln,s12);

cout<< "\n\n\t\t First Student Record is Given Below\n\n" <<endl;


cout<< " \t\t Student Id is =" << s1 <<endl;
cout<< " \t\t Student Name is =" << s2 <<endl;
cout<< " \t\t Student Father Name is =" << s3 <<endl;
cout<< " \t\t Student Qualification is =" << s4 <<endl;
cout<< " \t\t Student PhoneNumber is =" << s5 <<endl;

cout<< "\n\n\t\t Second Student Record is Given Below\n\n" <<endl;


cout<< " \t\t Student Id is =" << s6 <<endl;
cout<< " \t\t Student Name is =" << s7 <<endl;
cout<< " \t\t Student Father Name is =" << s8 <<endl;
cout<< " \t\t Student Qualification is =" << s9 <<endl;
cout<< " \t\t Student PhoneNumber is =" << s10 <<endl;

}
};

int main()
{
linked_list obj;
P:
system("cls");
int choice;
cout<<"\n\n\t\t\t\t.................. WELCOME TO STUDENT MANAGMENT
SYSTEM .....................";

cout<<"\n\t\t\t\t S.No Functions Description";


cout<<"\n\t\t\t\t1 \t Insert Record \t\t Insert Student Record"<<endl;
cout<<"\n\t\t\t\t2 \t Search Record \t\t Search Student Record"<<endl;
cout<<"\n\t\t\t\t3 \t Count Record \t\t Count Student Record"<<endl;

cout<<"\n\t\t\t\t4 \t Update Record \t\t Update Student Record"<<endl;


cout<<"\n\t\t\t\t5 \t Delete Record \t\t Delete Student Record"<<endl;
cout<<"\n\t\t\t\t6 \t Show All Record \t\t Show Student's Record"<<endl;
cout<<"\n\t\t\t\t7 \t Show Record from File \t\t Show Record From File"<<endl;
cout<< "Enter your choice" <<endl;
cin>> choice;
switch(choice)
{
case 1:
system("cls");
obj.Insert();
break;
case 2:
system("cls");
obj.Search();
break;
case 3:
system("cls");
obj.Count();
break;
case 4:
system("cls");
obj.Update();
break;
case 5:
system("cls");
obj.Delete();
break;
case 6:
system("cls");
obj.Show();
break;
case 7:
system("cls");
obj.Showfile();
break;
case 8:
exit(0);
default:
cout<< "\n\n\n Invalid Choice" <<endl;
}
getch();
goto P;
return 0;
}

You might also like