16-10-12, 01:22 AM
PHP كود :
#include<iostream.h>
#include<conio.h>
class student
{
private:
double stud_id;
char Name[20];
int Level;
char Adrress[20];
student *next;
public:
void add(student *,student *,student *);
void search(student *,student *,student *,student *);
void del(student *,student *,student *,student *);
private:
int item,a;
char ans;
student *str,*ptr,*ftr,*find,*temp;
};
void student:: add(student *,student *,student *)
{
str=NULL;
do{
ftr=new student;
cout<<"Enter The stud_id :";
cin>>ftr->stud_id;
cout<<"Enter The Name :";
cin>>ftr->Name;
cout<<"Enter The Level :";
cin>>ftr->Level;
cout<<"Enter The Adrress :";
cin>>ftr->Adrress;
ftr->next=NULL;
if(str==NULL)
str=ptr=ftr;
else
{ ptr->next=ftr;
ptr=ftr; }
cout<<"Anther record (y/n) ?";
cin>>ans ;
}while(ans=='y'||ans=='Y');
textcolor(244);
textbackground(0);
cprintf("\r--------------------------------------------------------------------------------");
cprintf("\r....stud_id.............Name................ Level..................Adrress.....") ;
cprintf("\r--------------------------------------------------------------------------------");
ptr=str;
while(ptr!=NULL)
{cout<<"\t"<<ptr->stud_id<<"\t\t "<<ptr->Name<<"\t\t "<<ptr->Level<<"\t\t "<<ptr->Adrress<<endl;
ptr=ptr->next; }
}
void student::search(student *,student *,student *,student *)
{
ptr=str;
cout<<"Enter The stud_id to search"<<endl;
cin>>item;
while(ptr!=NULL)
{
if(item==ptr->stud_id)
{ find=ptr;
break; }
else
{ ptr=ptr->next; }
}
if(find!=NULL)
{textcolor(214);
textbackground(0);
cprintf("\r--------------------------------------------------------------------------------");
cprintf("\r....stud_id.............Name................ Level..................Adrress.....") ;
cprintf("\r--------------------------------------------------------------------------------");
cout<<"\t"<<find->stud_id<<"\t\t "<<find->Name<<"\t\t "<<find->Level<<"\t\t "<<find->Adrress<<endl; }
else
cout<<"Not found\n";
}
void student::del(student *,student *,student *,student *)
{
cout<<"Enter The stud_id to delete \n";
ptr=str;
cin>>a;
if(str->stud_id==a)
{
if(str->stud_id==a&&str->next==NULL)
{ cout<<"it will delete :"<<str->stud_id<<endl ;
cout<<"it empty"<<endl ;
str=NULL;
delete str; }
else
{ str=str->next;
cout<<"it will delete :"<<ptr->stud_id<<endl;
ptr=NULL;
delete ptr; }
}
else
ptr=temp=str;
while(ptr!=NULL)
{
if(ptr->stud_id==a)
{ temp->next=ptr->next;
cout<<"it will delete :"<<ptr->stud_id<<endl;
ptr=NULL;
delete ptr; }
else
temp=ptr;
ptr=ptr->next;
}
ptr=str;
while(ptr!=NULL)
{textcolor(425);
textbackground(0);
cprintf("\r--------------------------------------------------------------------------------");
cprintf("\r....stud_id.............Name................ Level..................Adrress.....") ;
cprintf("\r--------------------------------------------------------------------------------");
cout<<"\t"<<ptr->stud_id<<"\t\t "<<ptr->Name<<"\t\t "<<ptr->Level<<"\t\t "<<ptr->Adrress<<endl;
ptr=ptr->next; }
}
main()
{textbackground(15);
textcolor(0);
clrscr();
cprintf("\r\n************************** Theis program students*******************************\n");
student *str,*ptr,*ftr,*find,*temp;
find=NULL;
char ch,in;
student adel;
adel.add(str,ptr,ftr);
do{
textcolor(4);
textbackground(0);
cprintf("\r\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t*************************************\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t");
cprintf("\r\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t* if you want Add record press A *\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t");
cprintf("\r\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t* if you want Search record press S *\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t");
cprintf("\r\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t* if you want delete record press D *\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t");
cprintf("\r\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t*************************************\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t");
cin>>ch;
switch(ch)
{
case 'a':
adel.add(str,ptr,ftr);
break;
case's':
adel.search(str,ptr,ftr,find);
break;
case'd':
adel.del(str,ptr,ftr,temp);
break;
default:
cout<<"\nunknoun opretur";
}
cout<<"\nif you want agean press R";
}while((in=getch())=='r');
getch();
return 0;
}