تسجيل الدخول

مشاهدة النسخة كاملة : قاعدة بيانات بالسي ++


imana
2012-12-27, 12:16
السلام عليكم

لكل من عنده فكرة عن كيفية عمل قاعدة بيانات بالسي وتنفيذها ارجو الافادة من فضلكم

nasser26
2012-12-27, 12:45
السي هي لغة برمجة وليست قاعدة بيانات

أما قواعد البيانات فهي كثيرة : أوراكل - sql - الأكسس .....الخ

__الهاوي__
2012-12-27, 17:31
أظن الاخت تقصد صنع struct والتعامل معها على شكل قاعدة بيانات، وممكن تسجيل المحتوى على ملف، وبالتالي تصير على شكل قاعدة بيانات، بالطبع لن تكون في مستوى قواعد البيانات العلائقية.
وهذا كود في الانترنيت لقاعدة بيانات باستخدام السي

#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){

}

imana
2012-12-27, 19:28
السي هي لغة برمجة وليست قاعدة بيانات

أما قواعد البيانات فهي كثيرة : أوراكل - sql - الأكسس .....الخ

اجل اعلم انها لغة برمجة اقصد مثلا قاعدة بيانات مصنوعة بالاكسس و اعادة صنعا بالسي وتنفذ بشكل طبيعي
على العموم شكر الللك

imana
2012-12-27, 19:33
أظن الاخت تقصد صنع struct والتعامل معها على شكل قاعدة بيانات، وممكن تسجيل المحتوى على ملف، وبالتالي تصير على شكل قاعدة بيانات، بالطبع لن تكون في مستوى قواعد البيانات العلائقية.
وهذا كود في الانترنيت لقاعدة بيانات باستخدام السي

#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){

}



شكرا لك على التوضيح ...انا عندي قاعدة بيانات وطلب منا انشاءها بالسييي ارد دروس بصفة عامة وشكرا مرة ثانيية

imana
2012-12-28, 22:00
ممكن اجاااااابة ؟؟

__الهاوي__
2012-12-29, 17:22
أختي، لحد الآن طلبك غير واضح، فمن جهة تريدين قاعدة بيانات بالسي، ومن جهة تقولين أن لك قاعدة بيانات ويراد لك أن تنشئيها بالسي، هل هو إنشاء أم ربط؟
إن كان الهدف إنشاء قاعدة بيانات من الصفر، تحوي ما تحويه قواعد البيانات، فهذا مشروع كبير ويلزمه عشرات المبرمجين، أما إن كان ربط قاعدة بارادوكس، أكسس، سيكول سيرفر ، أوراكل...فهنا يلزمك استخدام دوال api جاهزة.
إن كان الهدف هو إنشاء تطبيق لقاعدة بيانات بسيطة من الصفر، هذا التطبيق يسمح بتسجيل البيانات وحفظها على القرص الصلب فهذا ممكن، لكنه مضني باستخدام السي دون بيئة تطوير ide كالدلفي أو فيجوال سي++.
إن كان هناك مثال نصف جاهز فحبذا لو تنشريه هنا حتى تتضح الرؤية.

imana
2012-12-29, 20:58
أختي، لحد الآن طلبك غير واضح، فمن جهة تريدين قاعدة بيانات بالسي، ومن جهة تقولين أن لك قاعدة بيانات ويراد لك أن تنشئيها بالسي، هل هو إنشاء أم ربط؟
إن كان الهدف إنشاء قاعدة بيانات من الصفر، تحوي ما تحويه قواعد البيانات، فهذا مشروع كبير ويلزمه عشرات المبرمجين، أما إن كان ربط قاعدة بارادوكس، أكسس، سيكول سيرفر ، أوراكل...فهنا يلزمك استخدام دوال api جاهزة.
إن كان الهدف هو إنشاء تطبيق لقاعدة بيانات بسيطة من الصفر، هذا التطبيق يسمح بتسجيل البيانات وحفظها على القرص الصلب فهذا ممكن، لكنه مضني باستخدام السي دون بيئة تطوير ide كالدلفي أو فيجوال سي++.
إن كان هناك مثال نصف جاهز فحبذا لو تنشريه هنا حتى تتضح الرؤية.

صحيح فانا لم استطيع اصال ما اريد .....
انا عندي عمل تطبيقي مكون من جداول client-produit-vente وهي مملوءة وقمنا بانشاءها بالاكسيس بشكل عادي
واريد ان اقوم بعملها بالسي فمثلا اضافة موظف او حذفها او تعديل ....
نتمنى تكون فهمتني
هذا مثال بالباسكاال عن نفس العمل
وبارك الله فيييك
aprogram produit;
uses crt;
type
tproduit=record
company,designation:string[25];
mat,qnt:integer;
prix:real;
end;
fproduit=file of tproduit;

var
prod:tproduit;
fich:fproduit;
rep:char;
vmat:integer;
choix:integer;
i:longint;
x:string;
e:string;
p:integer;
trouver:boolean;
c:byte;

procedure ajout;

begin
clrscr;


rep:='O';
while (rep='O') or (rep='o') do

begin
assign (fich,'c:\degio\produit.bak');
{$I-}
reset(fich);

if ioresult > 0 then
rewrite (fich)
else
while not eof(fich) do
read(fich,prod);
{$I+}


begin

clrscr;
with prod do

begin

writeln(' FICHE DE D''ENREGISTREMENT ');

writeln;
writeln;
write(' MATRICULE : ');readln(prod.mat);
writeln;
write(' designation : ');readln(prod.designation);
writeln;
write(' company : ');readln(prod.company);
writeln;
write(' prix : ');readln(prod.prix);
writeln;

write(' qnt : ');readln(prod.qnt);
writeln;
writeln;
end;

write (fich,prod);

write (' Voulez-vous ajouter le designation d''un autre produit : O/N :');
readln(rep);
clrscr;
end;

end;
end;


{ procedure consultationindividuelle;

begin
clrscr;

rep:='O';
while (rep='O') or (rep='o') do
begin

assign(fich,'c:\degio\etudiant.bak');
reset (fich);

writeln(' -------CONSULTATION INDIVIDUELLE-------- ');
writeln;

write (' MATRICULE : ');readln(vmat); clrscr;


while not eof(fich) do


begin
read (fich,prod);

if prod.mat = vmat then

begin


writeln(' -------CONSULTATION INDIVIDUELLE-------- ');

writeln;
writeln;
writeln (' Nom : ',etud.nom);

writeln (' Prenom : ',etud.prenom);

writeln (' Date de naissance : ',etud.datenaiss);
end;
end;

if etud.mat <> vmat then

begin
writeln;
writeln(' MATRICULE INCONNU ');
writeln;
writeln;
end;

write (' Voulez-vous consulter un autre etudiant ? O/N : ');
readln (rep);
clrscr;
end;
end;


procedure consultationgenerale;
var
nom: array[1..25] of string[16];
prenom: array[1..25] of string[25];
som: array[1..25] of string;
mat: array[1..25] of string[4];
date: array[1..25] of string;
e,f,g,h:string;
j,m,n,k:integer;

begin
clrscr;
writeln (' ----------- CONSULTATION GENERALE ------------');
writeln;

assign (fich,'c:\degio\etudiant.bak');
reset(fich);
i:=0;
e:=' ';
while not eof(fich) do

begin
read (fich,etud);

begin
i:=1+i;
mat[i]:=etud.mat;
date[i]:=etud.datenaiss;
nom[i]:=etud.nom;
prenom[i]:=etud.prenom;
som[i]:=nom[i]+e+prenom[i];
end;
end;

for m:= 1 to i-1 do
for n:= m+1 to i do
if som[m] > som[n] then
begin
f:= som[m];
som[m]:=som[n];
som[n]:=f;
g:= mat[m];
mat[m]:=mat[n];
mat[n]:=g;
h:=date[m];
date[m]:=date[n];
date[n]:=h;
end;

writeln;
k:=2;
for m:=1 to i do
begin
write (mat[m]+e);
write(som[m]+e);
writeln(date[m]+e);
k:= k+2;
end;
writeln;
end;

procedure suppression;


Var
etud:tetudiant;
trouver:boolean;
etud1:fetudiant; {Vetd1 sert de fichier intermediaire lors de
la suppression de la donnee}

{ begin {Debut suppression}
{ clrscr;
writeln (' -------------- SUPPRESSION -------------');
writeln;
rep:='O';
while (rep='O') or (rep='o') do
begin
repeat
assign(fich,'c:\degio\etudiant.bak');
{$I-}
{ reset(fich);
{$I+
if IOresult<>0 then
begin
write(' L''etudiant ne figure pas dans notre fichier ');
end;
until IOresult=0;
assign(etud1,'c:\degio\corbeil.bak');
rewrite(etud1);
seek(fich,0);
write(' Entrez le Matricule SVP : ');
readln(vmat);
writeln;
writeln;

trouver:=false;

writeln(' ');
writeln;
writeln;

while not eof(fich) do

read(fich,etud);
if etud.mat= vmat then
begin
trouver:=true;
writeln(' SUPPRIME!!!!!! : ');
writeln;

write(' Nom:'); writeln(etud.nom);
write(' Prenoms:'); writeln(etud.Prenom);
write(' Date de naissance:'); writeln(etud.Datenaiss);
writeln;
writeln;
end;
begin

seek(fich,0);
while not eof(fich) do
begin
read(fich,etud);
if vmat<> etud.mat then
begin
write(etud1,etud);
end;
end;
rewrite(fich);
seek(etud1,0);
while not eof(etud1) do
begin
read(etud1,etud);
write(fich,etud);
end;
close(etud1);
erase(etud1);
end;
write (' Voulez-vous supprimer un autre etudiant ? O/N : ');
readln (rep);
clrscr;
writeln;
end;

end;





procedure Modifier;
var
trouver:boolean;
mat:string;
c:char;
begin

clrscr;


rep:='O';
while (rep='O') or (rep='o') do
begin
assign (fich,'c:\degio\etudiant.bak');
reset(fich);

trouver:=false;


write(' MATRICULE : ');
readln(mat);
writeln;
i:=0;
while(trouver=false) and (not eof(fich)) do
begin
read(fich,etud);
if etud.mat=mat then
while (rep='O') or (rep='o') do
begin

clrscr;

trouver:=true;


writeln(' ---------------------------------------- ');
writeln;
writeln;
write(' 1> Matricule:'); writeln(etud.mat);
write(' 2> Nom:'); writeln(etud.nom);
write(' 3> Prenoms:'); writeln(etud.Prenom);
write(' 4> Date de naissance:'); writeln(etud.Datenaiss);
writeln;
writeln;
writeln(' ---------------------------------------- ');
writeln;
writeln;
writeln(' Entrez le numero de l''information a modifier ');
writeln(' 1> Pour le Matricule');
writeln(' 2> Pour le nom');
writeln(' 3> Pour le prenom');
writeln(' 4> Pour la date de naissance');

writeln;
writeln;
write(' Faites votre choix SVP:');
readln(C);
Case C of
'1': begin
write(' Entrez le nouveau matricule SVP : ');
readln(etud.mat);
end;
'2': begin
write(' Entrez le nouveau nom SVP : ');
readln(etud.nom);
end;
'3': begin
write(' Entrez le nouveu prenom SVP : ');
readln(etud.prenom);
end;
'4': begin
write(' Entrez la nouvelle date de naissance SVP : ');
readln(etud.datenaiss);
end;


end;
clrscr;
write (' Voulez-vous modifier une autre donnees ? O/N : ');
readln (rep);
clrscr;
end;
i:=i+1;
end;
if trouver=true then
begin
Seek(fich,i-1);
write(fich,etud);
end
else

writeln(' MATRICULE INCONNU ');
writeln;
write (' Voulez-vous faire une autre modification ? O/N : ');
writeln;
readln(rep);
end;




end;


{*********************** DEBUT DU PROGRAMME ****************}


begin

clrscr;

rep:='O';
while (rep='O') or (rep='o') do
begin






write (' MENU ');
writeln;
writeln;

writeln (' 1 Ajout ');

writeln (' 2 Modification ');

writeln (' 3 Suppression ');

writeln (' 4 Consultation generale ');

writeln (' 5 Consultation individuelle ');

writeln (' 6 Sortie ');
writeln;
writeln;
repeat

write (' Faites Votre Choix : ');


if choix > 6 then
begin

clrscr;

write(' ERREUR Saisissez un nombre inferieur a 6 ');

end;

{$I- }
readln (choix);
{$I+}
until ioresult=0;
case choix of

1:ajout;
{ 2:modifier;
3:suppression;
4:consultationgenerale;
5:consultationindividuelle;}
6:exit;
end;
write (' Voulez-vous revenir au menu general ? O/N : ');
readln (rep);
clrscr;
end;
close (fich);

end.