资源简介
综合索引文件和查找算法做的学生信息管理程序 用C语言写的 有源代码 课程设计报告和可执行的程序
代码片段和文件信息
/*文件名:student.cpp*/
#include
#include
#include
#define MaxRec 100 /*最多记录个数*/
typedef struct Index /*定义索引文件结构*/
{ char num[8]; /*学号*/
long offset; /*主文件中的记录号*/
}Index;
typedef struct sdata /*定义主文件结构*/
{ char num[8]; /*学号*/
char name[10]; /*姓名*/
int sex; /*性别*/
int age; /*年龄*/
char addr[30]; /*地址*/
char dep[20]; /*系别*/
char spec[20]; /*专业*/
}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) /*对R[0..n-1]按递增有序进行直接插入排序*/
{
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]; /*将关键字大于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); /*对idx数组按no域值排序*/
for(i=0;i fwrite(&idx[i]sizeof(Index)1idxfile);
fclose(mfile);
fclose(idxfile);
}
void InputMainFile() /*添加一个主文件记录*/
{
FILE *mfile;
Student st;
mfile=fopen(“main.dat““ab+“);
if(mfile==NULL)
{ printf(“>>不能建立主文件\n“);
return;
}
printf(“>>学号,姓名,性别,年龄,地址,系别,专业:“);
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(“>>写主文件错误\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(“>>记录号%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(“>>(学号:记录号) %s: %d\n“irec.numirec.offset);
fclose(idxfile);
}
void ReadIndexFile(Index idx[MaxRec] int &len)
/*读索引文件数据存入idx数组中*/
{
FILE *idxfile;
int j;
if((idxfile=fopen(“index.dat““rb“))==NULL)
{ printf(“>>索引文件不能打开\n“);
return;
}
fseek(idxfile02);
j=ftell(idxfile); /*j求出文件长度*/
rewind(idxfile);
len=j/sizeof(Index); /*len求出文件的记录个数*/
fread(idxsizeof(Index)lenidxfile);
fclose(idxfile);
}
- 上一篇:MFC视频播放器(带播放列表VC++6.0源代码)
- 下一篇:c++线程安全日志类
相关资源
- 利用C++哈希表的方法实现电话号码查
- 学校超市选址问题(数据结构C语言版
- 数据结构,迷宫问题C语言版源代码
- DSDEMO-C演示(数据结构C语言版 严蔚敏
- 数据结构 图的遍历源代码
- 数据结构实验源代码集
- 实验报告:数据结构长整数四则运算
- 数据结构教程李春葆第五版书中例题
- 吕鑫vc6c++数据结构视频源码
- 数据结构教程李春葆第五版课后答案
- 李春葆课后习题答案(数据结构教材
- 数据结构1800题 题+答案(全)
- 数据结构(C语言版)ppt课件,清华,
- c++常用游戏算法及数据结构设计
- 数据结构超全面复习导图
- 《Data Structures and Algorithm Analysis in C
- 数据结构C语言版教学笔记严蔚敏
- 数据结构C语言版期末考试试题(有答
- 多功能计算器实现C++代码以及代码详
- C语言数据结构银行客户排队
- C语言实现栈操作
- 简易学生管理系统源码 数据结构 大作
- 数据结构与C语言综合习题集
- 数据结构实验——赫夫曼树相关
- C语言进阶源码---基于graphics实现图书
- 数据结构——C++语言描述 陈慧南
- 广东工业大学数据结构课程设计航空
- 数据结构课程设计扑克牌排序
- 数据结构各种算法实现(C++模板),
- (严版C语言版数据结构源码.rar
评论
共有 条评论