導航:首頁 > 編程大全 > 怎麼做小型資料庫

怎麼做小型資料庫

發布時間:2025-09-25 04:03:07

㈠ 求一個C語言程序。小型資料庫。一個管理系統。功能包括:查詢,修改等等。。帶解釋的 謝謝~!

#include "stdio.h"
#include "stdlib.h"
#include "conio.h"
#include "math.h"
#include "ctype.h"
#include "string.h"

#define MAX 4
#define TERM 6
struct STUD{
unsigned number;
char name[20];
unsigned score[MAX];
float average;
struct STUD *next;
};

struct CLASS{
unsigned no;
unsigned students;
float score[MAX];
float average;
struct STUD *first;
};

//輸出所有學生的成績及名次
void output(struct CLASS *pclass)
{
struct STUD *p;

int n=0;
printf("Class:%u\t number of students:%u\n",pclass->no ,pclass->students );
printf("number name math physics politics "
"english average place\n");
for(n=1,p=pclass->first ;p!=NULL;p=p->next ,++n)
printf("%-8u%-12s%-8u%-8u%-8u%-8u%-10.2f%-d\n",
p->number ,p->name ,p->score[0] ,p->score [1],
p->score [2],p->score [3],p->average ,n);
}

//按平均成績排序
void sort(struct CLASS *pclass)
{
struct STUD *p, *next, *last;
int m,n;
for(m=0;m<pclass->students -1;m++)
for(last=p=pclass->first ,n=0;n<pclass->students-1-m;
n++,last=p,p=p->next)
if(p->average<p->next->average){
next=p->next;
if(p!=pclass->first)
last->next=next;
else
pclass->first=next;
next->next=p;
p=next;
}
}

char *cou[MAX]={"math","phusics","politics","english"};

//將鏈表所有接點寫入文件
void write_file(struct CLASS *pclass,FILE *myfile)
{
struct STUD *p;
for(p=pclass->first;p!=NULL;p=p->next)
fwrite(p,sizeof(struct STUD),1,myfile);

}

//從文件中讀數據重建鏈表
void read_file(struct CLASS *pclass,FILE *myfile)
{
struct STUD buf,*p,*tail;
int n;
for(tail=pclass->first ,n=0;n<pclass->students ;tail=p,++n){
if(fread(&buf,sizeof(struct STUD),1,myfile)!=1){
pclass->students =n;
break;
}
p=(struct STUD *) malloc(sizeof(struct STUD));
*p=buf;
//連接成先進先出鏈表
if(pclass->first==NULL)
pclass->first =p;
else
tail->next =p;
p->next =NULL;

}
}

//增加信息
void insert(struct CLASS *pclass)
{
struct STUD *p,*current,*last;
int k,ch,flag;
do{
p=(struct STUD *) malloc(sizeof(struct STUD));
printf("\ninput number and name of student:");
scanf("%u%s",&p->number ,p->name );
while(1){
for(flag=1,k=0;k<MAX;++k){
printf("\niput %s:",cou[k]);
scanf("%u",&p->score[k]);
if(p->score[k]>100)
flag=0;
}
if(flag) break;
printf("score error\n");
}
p->average =(float)(p->score[0]+p->score[1]+p->score[2]+p->score[3])/4;
//找插入點
for(last=current=pclass->first;current->next&¤t->average>p->average;
last=current,current=current->next );
if(current->next ==NULL&¤t->average>p->average){
p->next =NULL;
current->next =p;
}
else{
p->next =current;
if(current==pclass->first)
pclass->first =p;
else
last->next =p;
}
pclass->students ++;
printf("continue?(y/n)");
while(isspace(ch=getchar()));
}while (ch=='y'||ch=='Y');
}

//刪除學生
void delete_stu(struct CLASS *pclass)
{
unsigned ch;
struct STUD *current,*last,*p;
do{
printf("\ninput number of student:");
scanf("%u",&p->number,&ch);
for(last=current=pclass->first;current!=NULL&¤t->number!=ch;
last=current,current=current->next);
if(current!=NULL){
if(current!=pclass->first)
last->next=current->next;
else
pclass->first=current->next;
free(current);
pclass->students--;
}
else
fprintf(stderr,"error:number of student!\n");
printf("continue?(y/n)");
while(isspace(ch=getchar()));
}while (ch=='y'||ch=='Y');

}

void create(struct CLASS *pclass)
{
struct STUD *p,*tmp=NULL;
int n=0,k,ch,flag;

do{
p=(struct STUD *) malloc(sizeof(struct STUD));
printf("\ninput number and name of student:");
scanf("%u%s",&p->number ,p->name );
while(1){
for(flag=1,k=0;k<MAX;++k){
printf("\niput %s:",cou[k]);
scanf("%u",&p->score[k]);
if(p->score[k]>100)
flag=0;
}
if(flag) break;
printf("score error\n");
}
p->average =(float)(p->score[0]+p->score[1]+p->score[2]+p->score[3])/4;

p->next =pclass->first ;
pclass->first =p;
++n;
printf("continue?(y/n)");
while(isspace(ch=getchar()));
}while (ch=='y'||ch=='Y');
pclass->students =n;
}

//計算平均分
void average(struct CLASS *pclass)
{
static double general[MAX],g;
struct STUD *p;
int i;

for(p=pclass->first;p!=NULL;p=p->next)
for(i=0;i<MAX;++i)
general[i]+=p->score[i];
printf("\n math physics politics english\n");
for(i=0;i<MAX;++i){
pclass->score[i]=general[i]/pclass->students ;
printf("%10.2f",pclass->score[i]);
g+=general[i];
}
pclass->average =g/(MAX*pclass->students );
printf("\ngeneral average:%10.2f\n",pclass->average );

}

void main()
{
struct CLASS cla;
FILE *fp;
int flag=1,k;
char c,*menu[]={
"\n1:insert a student\n",
"2:delete a student\n",
"3:save into file\n",
"4:print class score list\n",
"5:stat average\n",
"0:exit\n",
"\nselect[0-6]:"
};
if((fp=fopen("students.dat","rb"))==NULL){
printf("input number of class:");
scanf("%u",&cla.no);
cla.students=0;
cla.first=0;
create(&cla);
sort(&cla);
}
else{
fread(&cla,sizeof(struct CLASS),1,fp);
cla.first=NULL;
read_file(&cla,fp);
fclose(fp);
}
while(flag){
for(k=0;k<=TERM;k++)
printf("%s",menu[k]);
scanf("%d",&k);
switch (k){
case 1:
insert(&cla);
break;
case 2:
delete_stu(&cla);
break;
case 3:
if((fp=fopen("students.dat","wb"))==NULL){
fprintf(stderr,"error:can't create file students!\n");
return;
}
fwrite(&cla,sizeof(struct CLASS),1,fp);
write_file(&cla,fp);
fclose(fp);
break;
case 4:
output(&cla);
break;
case 5:
average(&cla);
break;
case 0:
printf("save yout change?(y/n)");
scanf("%c%*c",&c);
c=='y'||c=='Y'?(c=1):(c==0);
if(c){
if((fp=fopen("students.dat","wb"))==NULL){
fprintf(stderr,"error:can't create file students!\n");
return;
}
rewind(fp);
fwrite(&cla,sizeof(struct CLASS),1,fp);
write_file (&cla,fp);
fclose(fp);

}
flag=0;
break;
default:
fprintf(stderr,"select error!\n");
}

}
}

㈡ 如果自己要建立一個小型資料庫,你有什麼建議用sql,有哪些方面的資料庫選擇

這個還是看你個人熟悉哪個吧,還有是看是怎麼個用法。
有些資料庫需要搭配應用程序才能更方便使用。
access,mysql。

㈢ 怎樣用excel製作一個小型資料庫表格

步驟:
1、建立左表,在A:E列輸入數據,在F和G列輸入公式。
2、按CTRL+A,復內制;打開2日空白表,按CTRL+A,粘帖;
將容2日表中C:E列數據清除,在C2輸入公式「=VLOOKUP('2日'!A2,'1日'!$A:$F,6,FALSE)」,用右下角填充柄向下復制到C8導入1日期末庫存;
在D和E列輸入2日數據,以顯示2日狀況;3日及以後照此處理。
3、使用「記錄單」(以2日表為例):
1)選中表中任一非空單元格,點選「數據/記錄單」。
2)查找資料:點「上一條」或「下一條」按鈕,找到需要資料;或點「條件」,在「品名」或「價格」框輸入品名或價格,點「上一條」也可查到需要資料。
3)添加項目:點「新建」鈕,在空框輸入品名等有關信息,再點「新建」鈕,即可在2日表添加新項目。
4)刪除項目:找到擬刪項目,點「刪除」鈕,即可刪除2日表已有項目。

㈣ Microsoft Office Access 資料庫向導模板 怎麼用啊

1.進入「Microsoft Office Access 2007」新建窗口,如圖:

閱讀全文

與怎麼做小型資料庫相關的資料

熱點內容
cmd批量移動文件命令 瀏覽:506
300英雄微信充值關閉 瀏覽:406
科魯茲導航如何編程 瀏覽:138
g9008v升級50感受 瀏覽:899
qq群馬甲群主管理分開 瀏覽:414
暗黑2升級亮金武器 瀏覽:417
hpux文件系統 瀏覽:798
企業網站模板大全 瀏覽:494
手機收到靈機數據驗證碼什麼情況 瀏覽:568
afinal框架教程 瀏覽:284
c伺服器開發pdf文件下載 瀏覽:938
外來文件如何管理 瀏覽:185
aspnetpdf下載文件 瀏覽:115
jsp讀取資料庫 瀏覽:663
emacs文件中搜索 瀏覽:468
二手手機在哪個網站買可靠 瀏覽:667
如何把文件框架變大 瀏覽:590
兩資料庫同步 瀏覽:348
怎麼做小型資料庫 瀏覽:350
數控g02圓弧怎麼編程 瀏覽:764

友情鏈接