منتديات الجلفة لكل الجزائريين و العرب - عرض مشاركة واحدة - قاعدة بيانات بالسي ++
عرض مشاركة واحدة
قديم 2012-12-27, 17:31   رقم المشاركة : 3
معلومات العضو
__الهاوي__
أستــاذ
 
الصورة الرمزية __الهاوي__
 

 

 
إحصائية العضو










افتراضي

أظن الاخت تقصد صنع struct والتعامل معها على شكل قاعدة بيانات، وممكن تسجيل المحتوى على ملف، وبالتالي تصير على شكل قاعدة بيانات، بالطبع لن تكون في مستوى قواعد البيانات العلائقية.
وهذا كود في الانترنيت لقاعدة بيانات باستخدام السي
كود PHP:
#include<stdio.h>
#define SIZE 10

struct name{
   
char first[30];
   
char last[30];
};

struct datehire{
   
char day[2];
   
char month[2];
   
char year[4];
};
struct employee{

       
struct name allname;
       
char id[20];
       
char salary[20];
       
struct datehire alldate;
};
typedef struct employee Employee;

void choice();
void addrecord(Employee *);
void changerecord(Employee *);
void loada(Employee *);
void loadall(Employee *);



main(void){

    
choice();

return 
0;
}

void choice(){

Employee employee_list[SIZE];
int choice;

int rubbish;

do{
     
printf("            <--------Welcome to employee database system-------->      \n\n");
     
printf("            Please choose the number of function that you want->\n\n");
     
printf("            <1>Add Record/Records\n");
     
printf("            <2>Change a Record\n");
     
printf("            <3>Load A record to screen\n");
     
printf("            <4>Load ALL record to screen\n");
     
printf("            <5>Exit\n");
     
printf("\n\n\nPlease enter:->");
     
scanf("%d",&choice);

     switch(
choice){
     case 
1:
            
addrecord(employee_list);
         break;

     case 
2:
            
changerecord(employee_list);
         break;
     case 
3:
            
loada(employee_list);
         break;
     case 
4:
              
loadall(employee_list);
         break;
     case 
5:
         
printf("Exited,thanks you to using our system!\n");
         
printf("press any key and then press the enter to exit\n");
         
scanf("%d",&rubbish);
         break;
     default:
         
printf("Error input!Please input the number between 1-5");
         
scanf("%d",&rubbish);
     }
     
}while (
choice!=5);

}
void addrecord(Employee *employee_list){
int count=0;
int display=0;



      
printf("Enter employee name(First name)->");
      
scanf("%s",employee_list[count].allname.first);
      
      
printf("Enter employee name(Last name)->");
      
scanf("%s",employee_list[count].allname.last);
      
      
printf("Enter the the employee id->");
      
scanf("%s",employee_list[count].id);

      
printf("Enter the employee salary->");
      
scanf("%s",employee_list[count].salary);

      
printf("Please enter the date of hire->");
      
scanf("%s%s%s",&employee_list[count].alldate.day,&employee_list[count].alldate.month,&employee_list[count].alldate.year);

      
printf("\n");


        
printf("The record [%d] employee first name -> %s \n",display+1,employee_list[count].allname.first);
        
printf("The record [%d] employee last name -> %s\n",display+1,employee_list[count].allname.last);
        
printf("The record [%d] employee id ->%s \n",display+1,employee_list[count].id);
        
printf("The record [%d] employee salary -> %s\n",display+1,employee_list[count].salary);
        
printf("The record [%d] employee hire of date-> %s/%s/%s\n",display+1,employee_list[count].alldate.day,employee_list[count].alldate.month,employee_list[count].alldate.year);
        
printf("\n");

        
count=count+1;
        
display=display+1;
        

}



void changerecord(Employee *employee_list){
    
int choice1;
    

    
char check;
      
printf("What record do you want to change?Enter the number of record please->");
      
scanf("%d",&choice1);
      
      
printf("You want to change record %d\n",choice1);
      --
choice1;
      
printf("Enter employee name(First name) to change the orignal record:\n");
      
scanf("%s",employee_list[choice1].allname.first);

      
printf("Enter employee name(Last name) to change the orignal:\n");
      
scanf("%s",employee_list[choice1].allname.last);

      
printf("Enter the the employee id to change the orignal\n");
      
scanf("%s",employee_list[choice1].id);

      
printf("Enter the employee salary to change the orignal\n");
      
scanf("%s",employee_list[choice1].salary);

      
printf("Please enter the date of hire\n");
      
scanf("%s%s%s",&employee_list[choice1].alldate.day,&employee_list[choice1].alldate.month,&employee_list[choice1].alldate.year);

     
        
printf("The orignal have changed,Do you want to check it?Y or N\n");
        
scanf("%s",&check);
        if((
check=='Y')||(check=='y')){
            
printf("The record [%d] first name-> %s \n",choice1+1,employee_list[choice1].allname.first);
            
printf("The record [%d] last name-> %s\n",choice1+1,employee_list[choice1].allname.last);
            
printf("The record [%d] id-> %s\n",choice1+1,employee_list[choice1].id);
            
printf("The record [%d] salary-> %s\n",choice1+1,employee_list[choice1].salary);
            
printf("The record [%d] date of hire-> %s/%s/%s\n",choice1+1,employee_list[choice1].alldate.day,employee_list[choice1].alldate.month,employee_list[choice1].alldate.year);
            
printf("End of change record");
            
printf("\n\n\n\n\n\n");
            
    }
    

      

}
void loada(Employee *employee_list)
{
int choice1;
printf("What record do you want to load to screen?Enter the number of record please->");
scanf("%d",&choice1);
choice1-1;
            
            
printf("%s ",employee_list[choice1].allname.first);
            
printf("%s\n",employee_list[choice1].allname.last);
            
printf("%s\n",employee_list[choice1].id);
            
printf("%s\n",employee_list[choice1].salary);
             
printf("%s/%s/%s\n",employee_list[choice1].alldate.day,employee_list[choice1].alldate.month,employee_list[choice1].alldate.year);

}
void loadall(Employee *employee_list){
 










رد مع اقتباس