企业文档管理系统
文末附有全部代码哦!!!
一、设计目的与要求
1.设计目的
通过本次课程设计,希望达到如下目的:
综合应用《数据结构与算法》课程所学知识,掌握基本数据的逻辑结构、物理结构和基本操作,灵活应用基本的数据技术;
提高学生使用C语言解决具体问题的能力;
强化模块化程序设计的能力;
引导学生初步掌握软件开发的基本流程,培养团队开发的意识;
训练规范化编码和文档撰写的能力。
2.设计要求
本次课程设计需符合以下技术要求:
规范化编码:变量、函数命名需符合一定规范(可自定义),编码格式良好(缩进等),需对文件、函数进行功能方面的注释,代码具有良好的可读性;
模块化编码:分函数实现子功能,并有能力将子功能按设计要求组合成可执行代码;
交互友好:输入数据有提示,有一定的容错能力;
测试:测试应较全面的覆盖全部可能的执行路径,针对核心代码应多次充分测试。
文档:文档应该结构完整,层次清晰,格式符合标准要求,语句通顺,表述准确,用词得当,图、表组织正确合理。
二、问题描述
1.问题来源
文档没有统一的管理方式,纸质版的容易丢失。文件分散在不同电脑、服务器或系统中,难以统一备份,不清楚员工对文件有过哪些操作,工作出现问题,无法实际追溯,文档存储不在本地,核心资料易泄露;查找缓慢,效率低下;知识库版本管理混乱。
2.解决手段
利用c语言程序编写一个能按照id、名称、密级对文档进行系统存储的程序。
3.应用前景
应用于各种各样的企业部门以及个人。企业可以在需求变化时轻松添加新功能,简化新流程和各部门的管理,还可以分类存储数据,节省时间。
三、需求分析
1.具体实现
- 添加新的文档,本系统的功能模块图如图1所示。
- 查询指定文档的信息,由于量比较大,故需要一个快速的查询方法,本系统的功能模块图如图2所示。
- 修改指定文档的信息,本系统的功能模块图如图3所示。
- 自动保存信息,本系统的功能模块图如图4所示。
2.功能模块图
四、设计
1、设计步骤
- 采用文件读取或者手动录入的形式读取数据。
- 构建至少两棵二叉搜索树加速查找,分别依据其中的ID和文件名字段,查询时可以根据查询选项迅速找到对应位置,添加时需要向两棵树同时添加内容。
- 需要将数据展示出来。
- 设置结构体(ID、名称、密级、所属部门、创建日期、最后修改日期)
2、主要函数说明
五、测试分析
合理数据
六、完整代码
#include<stdlib.h>
#include<time.h>
#include<string.h>
#include<stdio.h>
typedef struct info {
unsigned int tid;
int sd;
char name[256];
time_t crt, cht;
}info;
typedef struct node {
info* data;
struct node* l, * r;
}node;
node idtree, nametree;
node idtree, nametree;
void insert(node* p, info* x, int tp) {
if (!p->data) {
p->data = x;
return;
}
if (tp == 1) {
if (p->data->tid < x->tid) {
if (!p->l) {
p->l = (node*)malloc(sizeof(node));
p->l->data = NULL;
p->l->l = p->l->r = NULL;
}
insert(p->l, x, tp);
}
else {
if (!p->r) {
p->r = (node*)malloc(sizeof(node));
p->r->data = NULL;
p->r->l = p->r->r = NULL;
}
insert(p->r, x, tp);
}
}
else {
if (strcmp(p->data->name, x->name) < 0) {
if (!p->l) {
p->l = (node*)malloc(sizeof(node));
p->l->data = NULL;
p->l->l = p->l->r = NULL;
}
insert(p->l, x, tp);
}
else {
if (!p->r) {
p->r = (node*)malloc(sizeof(node));
p->r->data = NULL;
p->r->l = p->r->r = NULL;
}
insert(p->r, x, tp);
}
}
}
node* finda(node* p, unsigned int tid) {
if (!p || !p->data)
return NULL;
if (p->data->tid == tid)
return p;
if (p->data->tid < tid)
return finda(p->l, tid);
else
return finda(p->r, tid);
}
node* findb(node* p, char name[]) {
if (!p || !p->data)
return NULL;
if (!strcmp(p->data->name, name))
return p;
if (strcmp(p->data->name, name) < 0)
return findb(p->l, name);
else
return findb(p->r, name);
}
void dfs(node* x, FILE* f) {
if (!x || !x->data)
return;
dfs(x->l, f);
fprintf(f, "%u\n%d\n%s\n%lld\n%lld\n", x->data->tid, x->data->sd, x->data->name, x->data->crt, x->data->cht);
dfs(x->r, f);
}
int main() {
idtree.l = idtree.r = idtree.data = NULL;//初始化
nametree.l = nametree.r = nametree.data = NULL;
FILE* rd = fopen("a.txt", "r");//打开数据文件
if (!rd) {
rd = fopen("a.txt", "w");
fclose(rd);
}
info* x = (info*)malloc(sizeof(info));
for (; rd && ~fscanf(rd, "%u %d %s %lld %lld", &x->tid, &x->sd, x->name, &x->crt, &x->cht);) {//读入数据
insert(&idtree, x, 1);//插入id二叉树
insert(&nametree, x, 2);//插入名字二叉树
x = (info*)malloc(sizeof(info));
}
if (rd)
fclose(rd);
free(x);
int y;
for (;;) {
printf("\t\t\t\t\t*---------------------------------------*\n");
printf("\t\t\t\t\t|\t \t|\n");
printf("\t\t\t\t\t|\t \t|\n");
printf("\t\t\t\t\t|\t欢迎访问企业文档管理系统\t|\n");
printf("\t\t\t\t\t|\t 作者:21软工二班九组 \t|\n");
printf("\t\t\t\t\t|\t \t|\n");
printf("\t\t\t\t\t|\t \t|\n");
printf("\t\t\t\t\t*---------------------------------------*\n");
printf("\t\t\t\t\t===================菜单==================\t\n");
printf("\t\t\t\t\t*---------------------------------------*\n");
printf("\t\t\t\t\t|\t\t1.添加新文档\t\t|\n");
printf("\t\t\t\t\t*---------------------------------------*\n");
printf("\t\t\t\t\t|\t\t2.按id查找文档\t\t|\n");
printf("\t\t\t\t\t*---------------------------------------*\n");
printf("\t\t\t\t\t|\t\t3.按文档名字查找\t|\n");
printf("\t\t\t\t\t*---------------------------------------*\n");
printf("\t\t\t\t\t|\t\t4.按id修改文档\t\t|\n");
printf("\t\t\t\t\t*---------------------------------------*\n");
printf("\t\t\t\t\t|\t\t5.按文档名字修改文档\t|\n");
printf("\t\t\t\t\t*---------------------------------------*\n");
printf("\t\t\t\t\t|\t\t6.保存并退出\t\t|\n");
printf("\t\t\t\t\t*---------------------------------------*\n");
scanf("%d", &y);
if (y == 1) {
x = (info*)malloc(sizeof(info));
printf("输入id:\n");
scanf("%u", &x->tid);
printf("输入秘密等级(数字):\n");
scanf("%d", &x->sd);
printf("输入文档名字:\n");
scanf("%s", x->name);
x->crt = x->cht = time(0);
insert(&idtree, x, 1);//将数据插入两种树里面
insert(&nametree, x, 2);
printf("添加成功\n");
}
else if (y == 2) {
unsigned int id;
printf("输入文档id:\n");
scanf("%u", &id);
node* p = finda(&idtree, id);//按id找
if (!p)
printf("这个文档不存在\n");
else {
printf("文档id:%u\n文档秘密等级:%d\n文档名字:%s\n文档创建时间:%lld\n文档修改时间:%lld\n", p->data->tid, p->data->sd, p->data->name, p->data->crt, p->data->cht);
}
}
else if (y == 3) {
char name[256];
printf("输入文档名字:\n");
scanf("%s", name);
node* p = findb(&nametree, name);//按名字找
if (!p)
printf("这个文档不存在\n");
else {
printf("文档id:%u\n文档秘密等级:%d\n文档名字:%s\n文档创建时间:%lld\n文档修改时间:%lld\n", p->data->tid, p->data->sd, p->data->name, p->data->crt, p->data->cht);
}
}
else if (y == 4) {
unsigned int id;
printf("输入文档id:\n");
scanf("%u", &id);
node* p = finda(&idtree, id);
if (!p) {
printf("这个文档不存在\n");
continue;
}
printf("文档id:%u\n文档秘密等级:%d\n文档名字:%s\n文档创建时间:%lld\n文档修改时间:%lld\n", p->data->tid, p->data->sd, p->data->name, p->data->crt, p->data->cht);
printf("输入新的秘密等级(数字):\n");
int res;
scanf("%d", &res);
time_t cht = time(0);
p->data->sd = res;
p->data->cht = cht;
p = findb(&nametree, p->data->name);//修改完后要把名字二叉树里的一起修改了
p->data->sd = res;
p->data->cht = cht;
printf("修改成功\n");
}
else if (y == 5) {
char name[256];
printf("输入文档名字:\n");
scanf("%s", name);
node* p = findb(&nametree, name);
if (!p) {
printf("这个文档不存在\n");
continue;
}
printf("文档id:%u\n文档秘密等级:%d\n文档名字:%s\n文档创建时间:%lld\n文档修改时间:%lld\n", p->data->tid, p->data->sd, p->data->name, p->data->crt, p->data->cht);
printf("输入新的秘密等级(数字):\n");
int res;
scanf("%d", &res);
time_t cht = time(0);
p->data->sd = res;
p->data->cht = cht;
p = finda(&idtree, p->data->tid);//同上
p->data->sd = res;
p->data->cht = cht;
printf("修改成功\n");
}
else
break;
}
FILE* w = fopen("a.txt", "w");
dfs(&idtree, w);//历遍二叉树将数据保存进文件
fclose(w);
}
七、设计体会与小结
- 课程设计是培养学生综合运用所学知识,发现,提出,分析和解决实际问题,锻炼实践能力的重要环节,是对学生实际工作能力的具体训练和考察过程。随着科学技术发展的日新月异,当今计算机应用在是生活中可以说得是无处不在。因此作为二十一世纪的大学来说掌握计算机开发技术十分重要的。
- 我的题目是企业文档管理系统的设计,对于我们这些新手来说,这是很大的考验,我一千次一万次的问自己,怎么才能找到课堂所学与实际应用的最佳结合点?怎么才能让自己的程序在篇幅上简单,在使用价值上丰富?怎样让自己的业余更靠近专业?怎样让自己的计划更具有序性,而不会忙无一用?机会是老师,学校,以及无数代教育工作者给的,而能力是自己的,耐性是需要的。经过自己的琢磨,听取了师姐,师兄们的建议,还查阅了很多书籍,才做到了心中有数才了解了 C 语言课程设计的真正用意﹣﹣培养自学能力养成程序编辑的好习惯。我从来不相信车到山前必有路的说法,认为那只是懒惰者自寻懒惰的借口,我要积极,要把握,要努力。