求一个用c语言链表与文件编写的图书管理系统或者学生信息系统代码加流程图,急等,明天12点之前要

如题所述

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

const unsigned MAXSTUDS = 150; // 学生人数
const unsigned MAXITEMS = 4; // 课程数目

struct student {
unsigned id; // 学号
char name[16];
double scores[MAXITEMS + 2]; // 增加平均成绩和总成绩
}stus[MAXSTUDS];

int num_stus = 0;  // 当前学生人数
char filename[60] = {'\0'}; // 学生数据文件的名称

// 读磁盘数据
void ReadFile() {
int i,an;
FILE *fin;
if(filename[0] == '\0') {
printf("请输入文件名:");
fflush(stdin);
gets(filename);
}
fin = fopen(filename,"rb");
if(fin == NULL) {
printf("不能打开文件:%s\n",filename);
return;
}
if(num_stus > 0) {
do {
printf("新读入的数据将:\n1、追加到现有数据的的尾部\n2、覆盖现有数据\n");
printf("请选择:");
}while(scanf("%d",&an) != 1 || an < 1 || an > 2);
switch(an) {
case 1 : for(i = num_stus; i < MAXSTUDS && !feof(fin); ++i) {
 if(fread(&stus[i],sizeof(struct student),1,fin) != 1)
 break;
 }
num_stus = i;
fclose(fin);
break;
case 2 : for(i = 0; i < MAXSTUDS && !feof(fin); ++i) {
 if(fread(&stus[i],sizeof(struct student),1,fin) != 1)
 break;
 }
num_stus = i;
fclose(fin);
break;
}
}
else {
for(i = 0; i < MAXSTUDS && !feof(fin); ++i)
fread(&stus[i],sizeof(struct student),1,fin);
num_stus = i;
fclose(fin);
}
}

// 数据存盘
void WriteFile() {
int i;
FILE *fout;
if(filename[0] == '\0') {
printf("请输入文件名:");
fflush(stdin);
gets(filename);
}
fout = fopen(filename,"wb");
if(fout == NULL) {
printf("无法打开文件:%s\n",filename);
return;
}
printf("正在写文件:%s......\n",filename);
for(i = 0; i < num_stus; ++i)
fwrite(&stus[i],sizeof(struct student),1,fout);
printf("成功创建文件:%s\n",filename);
}

// 读入学生的信息,总成绩和平均成绩由计算获取
void ReadData(struct student *a,int model) { // model 1:不用读入学号,2:不用读入姓名
int i;
if(model != 1) {
printf("学号:");
scanf("%u",&a->id);
}
if(model != 2) {
fflush(stdin);
printf("姓名:");
gets(a->name);
}
printf("输入%d门成绩(空格隔开):",MAXITEMS);
a->scores[MAXITEMS + 1] = 0;
for(i = 0; i < MAXITEMS; ++i) {
scanf("%lf",&a->scores[i]);
a->scores[MAXITEMS + 1] += a->scores[i];
}
a->scores[MAXITEMS] = a->scores[MAXITEMS + 1] / MAXITEMS;
}

void Browse() {
int i,j,nopass[MAXITEMS];
double score,total[MAXITEMS];
double min[MAXITEMS]; // 各科最差成绩
double max[MAXITEMS]; // 各科最好成绩
if(num_stus == 0) return;
for(i = 0; i < MAXITEMS; ++i) {
min[i] = 100;
max[i] = total[i] = 0;
nopass[i] = 0;
}
for(i = 0; i < 27 + 8 * MAXITEMS; ++i) printf("*");
printf("\n");
for(i = 0; i < num_stus; ++i) {
printf("%05d %6s ",stus[i].id,stus[i].name);
for(j = 0; j < MAXITEMS; ++j) {
score = stus[i].scores[j];
printf("%7.2lf ",score);
total[j] += score;
if(score < min[j]) min[j] = score;
if(score > max[j]) max[j] = score;
if(score < 60) ++nopass[j];
}
printf("%7.2lf %7.2lf\n",stus[i].scores[MAXITEMS],stus[i].scores[MAXITEMS + 1]);
}
for(i = 0; i < 27 + 8 * MAXITEMS; ++i) printf("*");
printf("\n");
printf("   最好成绩  ");
for(i = 0; i < MAXITEMS; ++i) printf("%7.2lf ",max[i]);
printf("\n");
printf("   最差成绩  ");
for(i = 0; i < MAXITEMS; ++i) printf("%7.2lf ",min[i]);
printf("\n");
printf("   平均成绩  ");
for(i = 0; i < MAXITEMS; ++i) printf("%7.2lf ",total[i] / num_stus );
printf("\n");
printf(" 不及格人数  ");
for(i = 0; i < MAXITEMS; ++i) printf("%7d ",nopass[i]);
printf("\n");
for(i = 0; i < 27 + 8 * MAXITEMS; ++i) printf("-");
printf("\n");
}

int HasThis(unsigned id) {
int i;
for(i = 0; i < num_stus; ++i) {
if(stus[i].id == id)
return i;
}
return -1;
}

void Insert() {
int an;
struct student *a;
do {
a = &stus[num_stus];
printf("请输入学号:");
scanf("%u",&a->id);
if(HasThis(a->id) == -1) {
ReadData(a,1);
++num_stus;
do {
fflush(stdin);
printf("0:返回,其他继续。\n");
printf("请选择:");
}while(scanf("%d",&an) != 1);
}
else printf("重复的学号:%u\n",a->id);
}while(an && num_stus < MAXSTUDS - 1);
}

void Query() {
unsigned id;
int j,res;
printf("请输入学号:");
scanf("%u",&id);
res = HasThis(id);
if(res >= 0) {
printf("%05d %6s ",stus[res].id,stus[res].name);
for(j = 0; j < MAXITEMS + 2; ++j)
printf("%7.2lf ",stus[res].scores[j]);
printf("\n");
}
else printf("没有找到学号是:%u 的学生。\n",id);
}

void Sort() {
int i,j,k;
struct student t;
for(i = 0; i < num_stus - 1; ++i) {
k = i;
for(j = i + 1; j < num_stus; ++j) {
if(stus[k].scores[MAXITEMS + 1] < stus[j].scores[MAXITEMS + 1])
k = j;
}
if(k != i) {
t = stus[i];
stus[i] = stus[k];
stus[k] = t;
}
}
}

int Erase() {
int i,res;
unsigned id;
printf("请输入学号:");
scanf("%u",&id);
res = HasThis(id);
if(res == -1) {
printf("没有找到学号是:%u 的学生。\n",id);
return 0;
}
for(i = res; i < num_stus - 1; ++i)
stus[i] = stus[i + 1];
--num_stus;
printf("删除成功。\n");
return 1;
}

int menu_select() {
int com;
char cn[20];
printf("\t1、录入\n");
printf("\t2、浏览\n");
printf("\t3、查询\n");
printf("\t4、排序\n");
printf("\t5、删除\n");
printf("\t6、读文件\n");
printf("\t7、写文件\n");
printf("\t0、退出管理系统\n\n");
printf("\t选择0 - 7:");
for(;;) {
fflush(stdin);
gets(cn);
com = atoi(cn);
if(com < 0 || com > 7) printf("输入错误,重新选择0 - 7:");
else break;
}
return com;
}

void handle_menu() {
for(;;) {
switch(menu_select()) {
case 1 : printf(">> 录入......\n"); Insert(); break;
case 2 : printf(">> 浏览......\n"); Browse(); break;
case 3 : printf(">> 查询......\n"); Query(); break;
case 4 : printf(">> 排序......\n"); Sort(); break;
case 5 : printf(">> 删除......\n"); Erase(); break;
case 6 : printf(">> 读数据文件......\n"); ReadFile(); break;
case 7 : printf(">> 数据存盘......\n");WriteFile(); break;
case 0 : printf(">> 退出管理系统\n"); return; break;
}
}
}

int main() {
handle_menu();
return 0;
}

追问

有没有流程图?

追答

没有。

追问

没有。。。

也采纳你的吧

温馨提示:答案为网友推荐,仅供参考
第1个回答  2016-12-26
/* * * * 学生管理系统 * */ #include #include #include #include typedef struct Day{ int year; int mon; int day; } DAY; typedef struct std_info { int num; char name[81]; int age; int gender; DAY birthday; char address[256]; unsigned long phonenumber; char Email[256]; } STD_DATE; typedef struct node{ STD_DATE student; struct node *next; } LINK_LIST; LINK_LIST *Creatnode(LINK_LIST *head) { LINK_LIST *p,*newnode; p=head; newnode=(LINK_LIST*)malloc(sizeof(LINK_LIST)); printf("学号:"); scanf("%d",&newnode->student.num); while (p) { if (p->student.num==newnode->student.num) { printf("输入学号重复,请重新输入\n"); p=head; printf("学号:"); scanf("%d",&newnode->student.num); continue; } p =p->next; } printf("姓名:"); fflush(stdin); gets(newnode->student.name); printf("年龄:"); scanf("%d",&newnode->student.age); printf("性别(1、男,2、女)选择1或2:"); scanf("%d",&newnode->student.gender); printf("出生年月(YYYY-MM-DD):"); scanf("%d-%d-%d",&newnode->student.birthday.year, &newnode->student.birthday.mon, &newnode->student.birthday.day); fflush(stdin); printf("地址:"); gets(newnode->student.address); printf("电话号码:"); scanf("%lu",&newnode->student.phonenumber); fflush(stdin); printf("E-mail:"); gets(newnode->student.Email); return newnode; } LINK_LIST *CreatLink() { LINK_LIST *head=NULL,*Linkend=NULL,*p=NULL; int n,i; printf("请输入需要录入的学生人数\n"); scanf("%d",&n); for (i=0;inext=p; } else { head=p; } Linkend=p; if (Linkend!=NULL) { Linkend->next=NULL; } } return head; } void printfnode(LINK_LIST *thenode) { if (thenode==NULL) { printf("该信息为空\n"); return; } printf("学 号:%d\n",thenode->student.num); printf("姓 名:%s\n",thenode->student.name); printf("年 龄:%d\n",thenode->student.age); if (thenode->student.gender==1) { printf("性 别:男\n"); } else printf("性 别:女\n"); printf("出生年月:%d年%d月%d日\n",thenode->student.birthday.year, thenode->student.birthday.mon, thenode->student.birthday.day); printf("地 址:%s\n",thenode->student.address); printf("电话号码:%lu\n",thenode->student.phonenumber); printf("E-mail:%s\n",thenode->student.Email); return; } void findnode(LINK_LIST *head) { int type=0; int number=0; char name[81]={0}; LINK_LIST *p; p=head; if (p==NULL) { printf("请先录入学生信息\n"); return; } printf("请选择查询方式\n(1、按学号\n2、按姓名):"); scanf("%d",&type); if (type==1) { printf("请输入学号:"); scanf("%d",&number); while (p) { if (p->student.num==number) { printfnode(p); return; } p=p->next; } printf("没有找到该学号学生信息\n"); return; } else if (type==2) { printf("请输入学生姓名:"); fflush(stdin); gets(name); while (p) { if (strcmp(p->student.name,name)==0) { printfnode(p); return; } p=p->next; } printf("没有找到该%s的学生信息\n",name); } return; } void printfList(LINK_LIST *head) { LINK_LIST *p; p=head; int i=0; if (p==NULL) { printf("请先录入学生信息\n"); return; } while (p) { printf("\n第%d位学生:\n",++i); printfnode(p); p=p->next; } return; } int Insertnode(LINK_LIST *head) { LINK_LIST *p,*newnode=NULL; p=head; if (p==NULL) { printf("请先录入学生信息\n"); return 0; } newnode=Creatnode(head); while (p->next) { p=p->next; } newnode->next=p->next; p->next=newnode; return 1; } int copystd_date(STD_DATE *dest,STD_DATE *source) { dest->num=source->num; memset(dest->name,0,81); memset(dest->address,0,256); memset(dest->Email,0,256); strcpy(dest->name,source->name); strcpy(dest->address,source->address); strcpy(dest->Email,source->Email); dest->age=source->age; dest->birthday.year=source->birthday.year; dest->birthday.mon=source->birthday.mon; dest->birthday.day=source->birthday.day; dest->gender=source->gender; dest->phonenumber=source->phonenumber; return 1; } int Deletenode(LINK_LIST *head,LINK_LIST *delnode) { LINK_LIST *p,*del; del=delnode; p=delnode->next; if (del==NULL) { printf("要删除的信息不存在\n"); return 0; } if (p==NULL) { p=head; while (p->next!=delnode) { p=p->next; } p->next=NULL; free(del); del=NULL; return 1; } del->next=p->next; copystd_date(&del->student,&p->student); free(p); p=NULL; return 1; } void Deletestd(LINK_LIST *head) { LINK_LIST *p; int num=0; int i=0; p=head; printf("请输入要删除第几个学生:"); scanf("%d",&num); for (i=0;inext; } if (p) { Deletenode(head,p); printf("删除成功\n"); } else printf("没有找到该学生"); return; } void title() { printf("*****************************************************\n"); printf("* 学 生 管 理 系 统 *\n"); printf("* 请选择(1~6): *\n"); printf("* 1、输入学生信息 *\n"); printf("* 2、查询信息 *\n"); printf("* 3、浏览学生信息 *\n"); printf("* 4、插入学生信息 *\n"); printf("* 5、删除学生信息 *\n"); printf("* 6、退出系统 *\n"); printf("*****************************************************\n"); return ; } int main() { int num=0; int findnum=0; LINK_LIST *head=NULL; LINK_LIST *p=NULL; while (1) { title(); scanf("%d",&num); switch(num) { case 1: head=CreatLink(); break; case 2: findnode(head);break; case 3: printfList(head);break; case 4: Insertnode(head);break; case 5: Deletestd(head); break; case 6: goto end; break; default:break; } printf("\n请按回车键继续\n"); fflush(stdin); getchar(); system("cls"); } end: while (head) { p=head; head=head->next; free(p); p=NULL; } return 0; }
第2个回答  2016-12-27
哦。突然想起来,还有一个链表的没人要。可以给你看看追问

可是我现在缺流程图,系统反而不缺

追答

有程序还不会画流程图?

实在不行每行代码写一个框。

追问

。。。

不会画啊

作业也不要太正规

相似回答