السلام عليكم ورحمة الله
ياجماعة عندي برنامج يحفظ بيانات الموظفين
طبعا انا خليت الاضفة تكون من النهاية
طلب مننا الدكتور نعيد تكوين الكون بحيث تكون الاضفة من البداية ومن الوسط
الاضافة من البداية سويتها ومشى الحال الحمد لله وكان هذا الكود
this_ptr->next=start this_ptr=start
اما الاضافة من الوسط صراحة ماعرفت لها وهذا هو كود البرنامج
#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<memory.h>
#include<stdlib.h>
typedef struct employee_type
{
int code;
char name[25];
char department[15];
float salary;
struct employee_type *next;
}
node;
node *start,*last_ptr;
void input_inf(void);
void display_inf(void);
void delete_inf(void);
int main()
{
int option;
clrscr();
start=last_ptr=(node*)NULL;
while (1)
{
cout<<"\n Select one of the following options:";
cout<<"\n ____________________________________"<<endl;
cout<<"\n 1 Enter new Employee :";
cout<<"\n 2 Display list of Employee:";
cout<<"\n 3 Exit from program :";
cout<<"\n\n Enter your Option (1-3):";
cin>>option;
switch(option)
{
case 1: input_inf() ;break;
case 2: display_inf() ;break;
case 3: delete_inf; exit(1);
}
}
}
// To Add Employee to list
void input_inf(void)
{
node *this_ptr;
int mcode;
char mname[25];
char mdepartment[15];
float msalary;
//input variable to the structure employee_type or node
cout<<"\n Enter employee's code:"; cin>>mcode;
cout<<"\n Enter employee's name:"; cin>>mname;
cout<<"\n Enter employee's department:"; cin>>mdepartment;
cout<<"\n Enter employee's salary:"; cin>>msalary;
this_ptr=(node*)malloc(sizeof(node));
this_ptr->code=mcode;
strcpy(this_ptr->name,mname);
strcpy(this_ptr->department,mdepartment);
this_ptr->salary=msalary;
this_ptr->next=(node*)NULL;
if(start==(node*)NULL)
start=last_ptr=this_ptr;
else
{last_ptr->next=this_ptr;
last_ptr=this_ptr;}
}
void display_inf(void)
{
int i=1;
node *this_ptr;
if(start==(node*)NULL)
{cout<<"\n list is Empty......";
cout<<"\n press any key to continue";
getch();
return;
}
cout<<"\n List of Employee\n\n";
for(this_ptr=start;this_ptr!=(node*)NULL;this_ptr=this_ptr->next)
{
cout<<"\n Employee's code: "<<i;
cout<<"\n Eployee's code: "<<this_ptr->code;
cout<<"\n Employee's name: "<<this_ptr->name;
cout<<"\n Employee's department: "<<this_ptr->department;
cout<<"\n Employee's salary: "<<this_ptr->salary;
cout<<"\n\n";
cout<<"\n Press any key to continue";
getch();
i++;
}
}
void delete_inf(void)
{node *this_ptr;
while(start!=(node*)NULL)
{
this_ptr=start;
start=start->next;
free(this_ptr);
}
}
