91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

資源簡(jiǎn)介

綜合索引文件和查找算法做的學(xué)生信息管理程序 用C語(yǔ)言寫的 有源代碼 課程設(shè)計(jì)報(bào)告和可執(zhí)行的程序

資源截圖

代碼片段和文件信息

/*文件名:student.cpp*/
#include
#include
#include
#define??MaxRec?100 /*最多記錄個(gè)數(shù)*/
typedef?struct?Index /*定義索引文件結(jié)構(gòu)*/
{ char?num[8]; /*學(xué)號(hào)*/
long?offset; /*主文件中的記錄號(hào)*/

}Index;
typedef?struct?sdata /*定義主文件結(jié)構(gòu)*/
{ char?num[8]; /*學(xué)號(hào)*/
char?name[10]; /*姓名*/
int?sex; /*性別*/
int??age; /*年齡*/
char?addr[30]; /*地址*/
char?dep[20]; /*系別*/
char?spec[20]; /*專業(yè)*/

}Student;
void?DelAll() /*清除主文件和索引文件的全部記錄*/
{
FILE?*mfile*idxfile;
if((mfile=fopen(“main.dat““wb“))==NULL)
{ printf(“>>不能打開主文件\n“);
return;
}
if((idxfile=fopen(“index.dat““wb“))==NULL)
{ printf(“>>不能建立主文件\n“);
return;
}
fclose(mfile);
fclose(idxfile);
}
void?InsertSort(Index?R[]int?n) /*對(duì)R[0..n-1]按遞增有序進(jìn)行直接插入排序*/

{
int?ij;
Index?temp;
for(i=1;i { temp=R[i];
j=i-1;
while(j>=0&&strcmp(temp.numR[j].num)<0)
{ R[j+1]=R[j]; /*將關(guān)鍵字大于R[i].key的記錄后移*/
j--;
}
R[j+1]=temp; /*在j+1處插入R[i]*/

}
}
void?CreatIdxFile() /*建立索引文件*/
{
FILE?*mfile*idxfile;
Index?idx[MaxRec];
Student?st;
int?n=0i;
if((mfile=fopen(“main.dat““rb“))==NULL)
{ printf(“>>不能打開主文件\n“);
return;
}
if((idxfile=fopen(“index.dat““wb“))==NULL)
{ printf(“>>不能建立索引文件\n“);
return;
}
i=0;
while((fread(&stsizeof(Student)1mfile))!=NULL)
{ strcpy(idx[i].numst.num);
idx[i].offset=++n;
i++;
}
InsertSort(idxn);
rewind(idxfile); /*對(duì)idx數(shù)組按no域值排序*/

for(i=0;i fwrite(&idx[i]sizeof(Index)1idxfile);
fclose(mfile);
fclose(idxfile);
}
void?InputMainFile() /*添加一個(gè)主文件記錄*/
{
FILE?*mfile;
Student?st;
mfile=fopen(“main.dat““ab+“);
if(mfile==NULL)
{ printf(“>>不能建立主文件\n“);
return;
}
printf(“>>學(xué)號(hào),姓名,性別,年齡,地址,系別,專業(yè):“);
scanf(“%s%s%d%d%s%s%s“st.numst.name&st.sex&st.agest.addrst.depst.spec);
if(fwrite(&stsizeof(Student)1mfile)!=1)
{ printf(“>>寫主文件錯(cuò)誤\n“);
return;
}
fclose(mfile);
}
void?OutputMainFile() /*輸出主文件全部記錄*/

{
FILE?*mfile;
Student?st;
int?i=0;
mfile=fopen(“main.dat““rb“);
if(mfile==NULL)
{ printf(“>>不能讀主文件\n“);
return;
}
while((fread(&stsizeof(Student)1mfile))!=NULL)
{ printf(“>>記錄號(hào)%d:“++i);
printf(“%s??%s?%d?%d?%s?%s?%s\n“st.numst.namest.sexst.agest.addrst.depst.spec);
}
fclose(mfile);
}
void?OutputIdxFile() /*輸出索引文件全部記錄*/
{
FILE?*idxfile;
Index?irec;
int?i=0;
idxfile=fopen(“index.dat““rb“);
if(idxfile==NULL)
{ printf(“>>不能讀索引文件\n“);
return;
}
while((fread(&irecsizeof(Index)1idxfile))!=NULL)
printf(“>>(學(xué)號(hào):記錄號(hào))?%s:?%d\n“irec.numirec.offset);
fclose(idxfile);
}
void?ReadIndexFile(Index?idx[MaxRec]?int?&len)
/*讀索引文件數(shù)據(jù)存入idx數(shù)組中*/
{
FILE?*idxfile;
int?j;
if((idxfile=fopen(“index.dat““rb“))==NULL)
{ printf(“>>索引文件不能打開\n“);
return;
}
fseek(idxfile02);
j=ftell(idxfile); /*j求出文件長(zhǎng)度*/
rewind(idxfile);
len=j/sizeof(Index); /*len求出文件的記錄個(gè)數(shù)*/
fread(idxsizeof(Index)lenidxfile);
fclose(idxfile);
}

評(píng)論

共有 條評(píng)論

相關(guān)資源