Home
>
开源 文档管理
>
c 学生管理系统文档
c 学生管理系统文档

time:2020-08-01 12:35:03

author:重庆佰鼎科技有限公司

【Font size: big medium smail

本文由重庆佰鼎科技有限公司提供,重点介绍了c 学生管理系统文档相关内容。重庆佰鼎科技有限公司专业提供开源 文档管理,web文档管理系统,ipad 文档管理等多项产品服务。我司的产品因其精良的制作水准,超高的性价比在业内广为称赞,远销国内外。

c 学生管理系统文档//文件命名:StudentSystem.cppc 学生管理系统文档

#include

#include

#include

#include

//创建结构体

struct students

{

int id;

char name[60];

char address[60];

};

//创建链表

struct node

{

struct students data;

struct node *next;

};

struct node *create_students();

void print_students(struct node *h);

void sort_students(struct node *h);

void modify_students(struct node *h);

void delete_students(struct node *h);

void menu();

main(){

struct node *h=NULL;

system("mode con cols=100 lines=30");

int x,i=1;

SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_BLUE|FOREGROUND_INTENSITY);

SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_GREEN|FOREGROUND_RED|FOREGROUND_INTENSITY);

do{

menu();

printf(" 请输入您的选择:");

scanf("%d",&x);

switch (x)

{

case 1:h=create_students();break;

case 2:print_students(h);break;

case 3:sort_students(h);break;

case 4:modify_students(h);break;

case 5:delete_students(h);break;

case 6:printf("欢迎下次访问,再见!!!\n");exit(0);break;

}

}while(x!=5);

return 0;

}

//菜单

void menu(){

printf("\n\n\n **************************************学生学籍信息管理系统************************************** \n\n");

printf(" * * \n\n");

printf(" * * \n\n");

printf(" * 1--- 学生学籍信息录入 --- * \n\n");

printf(" * 2--- 查看学生信息 --- * \n\n");

printf(" * 3--- 学生学籍排序 --- * \n\n");

printf(" * 4--- 修改学生信息 --- * \n\n");

printf(" * 5--- 删除学生信息 --- * \n\n");

printf(" * 6--- 退出系统 --- * \n\n\n\n");

printf(" ************************************************************************************************ \n\n\n\n");

}

//一、输入学生学籍信息

struct node *create_students()

{

FILE *fp;

int x,m=1;

char nam[60],a[60];

struct node *h,*p,*q,*n;

system("cls");

printf("\n\n\n\n\n\n\n\n\n\n\n\n");

printf(" 请输入第%d位学生id(输入-1结束):",m);

scanf("%d",&x);

getchar();

if(x!=-1)

{

printf(" 姓名:");

gets(nam);

printf(" 地址:");

gets(a);

}

if(x!=-1)

{

h=(struct node*)malloc(sizeof(struct node));

h->data.id=x;

strcpy(h->data.name,nam);

strcpy(h->data.address,a);

h->next=NULL;

p=h;

n=p;

}

while(x!=-1)

{

m++;

printf(" 请输入第%d位学生id(输入-1结束):",m);

scanf("%d",&x);

getchar();

if(x!=-1)

{

printf(" 姓名:");

gets(nam);

printf(" 地址:");

gets(a);

}

if(x!=-1)

{

q=(struct node*)malloc(sizeof(struct node));

q->data.id=x;

strcpy(q->data.name,nam);

strcpy(q->data.address,a);

q->next=NULL;

p->next=q;

p=p->next;

}

}

//printf("========打印r链表=========\n");

//printf("测试%d\n",n->data.id);

//while(n!=NULL){

// printf("%d %s %s\n",n->data.id,n->data.name,n->data.address);

// n=n->next;

//}

//printf("========打印r链表结束=========\n");

//存档

//n=n->next;

fp=fopen("book.txt","a");

if(fp==NULL)

{

printf("文件打开失败\n");

exit(1);

}

//fprintf(fp,"\n");

while(n!=NULL)

{

fprintf(fp,"%-20d %-20s %-20s\n",n->data.id,n->data.name,n->data.address);

n=n->next;

}

fclose(fp);

return h;

}

//二、输出所有学生信息

void print_students(struct node *h)

{

h=(struct node*)malloc(sizeof(struct node));

FILE *fp;

struct node *p,*q,*r;

system("cls");

p=h;

int id,i=1,j=1,ok;//统计人数 j,k用排序

char name_stu[60],address_stu[60];

fp=fopen("book.txt","r");

if(fp==NULL)

{

printf("文件打开失败");

}else{

printf("文件打开成功\n");

while(fscanf(fp," %d %s %s",&id,name_stu,address_stu)!=EOF)

{

//printf("\n");

//printf("---第%d次循环\n",i);

//i++;

q=(struct node*)malloc(sizeof(struct node));

//printf("内存申请成功\n");

strcpy(q->data.name,name_stu);

//printf("%s ",q->data.name);

strcpy(q->data.address,address_stu);

//printf("%s ",q->data.address);

q->data.id=id;

//printf("%d\n",q->data.id);

//printf("------------------------\n");

q->next=NULL;

p->next=q;

p=p->next;

//p->next=q;

//p=q;

}

}

//p->next=NULL;

fclose(fp);

r=h;

r=r->next;

printf("序号 学号 姓名 地址\n");

while(r!=NULL){

printf("%d:",j);

j++;

printf(" %d %s %s\n",r->data.id,r->data.name,r->data.address);

r=r->next;

}

printf("输入1查看结束:");

scanf("%d",&ok);

if(ok==1)

{

system("cls");

menu();

}

}

//三、排序功能 思路:读取--修改--保存

void sort_students(struct node *h)

{

system("cls");

//1.读取

h=(struct node*)malloc(sizeof(struct node));

FILE *fp;

struct node *p,*q,*r,*n;

p=h;

//q=h;

int id,i=0,sort,j,k,x;//x用于排序暂时存储

char name_stu[60],address_stu[60],s_name[60],s_address[60];

fp=fopen("book.txt","r");

if(fp==NULL)

{

printf("文件打开失败");

}else{

//printf("文件打开成功\n");

while(fscanf(fp," %d %s %s",&id,name_stu,address_stu)!=EOF)

{

//printf("\n");

//printf("---第%d次循环\n",i);

i++;

q=(struct node*)malloc(sizeof(struct node));

//printf("内存申请成功\n");

strcpy(q->data.name,name_stu);

//printf("%s ",q->data.name);

strcpy(q->data.address,address_stu);

//printf("%s ",q->data.address);

q->data.id=id;

//printf("%d\n",q->data.id);

//printf("------------------------\n");

q->next=NULL;

p->next=q;

p=p->next;

}

}

fclose(fp);

//2.修改----->>实现排序

r=h; //r为主链表

r=r->next;

n=r;

q=r->next;

printf("%d",r->data.id);

printf("%d",q->data.id);

//printf("总长度为:%d\n",i);

while(true)

{

printf("\n\n\n\n\n\n\n\n\n\n\n\n");

printf(" 从小到大排序请按1,从大到小排序请按0:");

scanf("%d",&sort);

if(sort==0 || sort==1){

break;

}else{

printf("您的输入有误");

}

}

//printf("判断成功\n");

//printf("333%d\n",r->data.id);

//printf("333%d\n",q->data.id);

//从小到大排序

if(sort==1){

//printf("-----从小到大排序-----\n");

for(j=0;j

//while(r!=NULL)

{

//printf("=========%d==\n",r->data.id);

for(k=j+1;k

//while(q!=NULL)

{

//printf("--%d-\n",q->data.id);

if((r->data.id)>(q->data.id))

{

x=r->data.id;

strcpy(s_name,r->data.name);

strcpy(s_address,r->data.address);

r->data.id=q->data.id;

strcpy(r->data.name,q->data.name);

strcpy(r->data.address,q->data.address);

q->data.id=x;

strcpy(q->data.name,s_name);

strcpy(q->data.address,s_address);

}

q=q->next;

}

r=r->next;

q=r->next;

}

printf("排序成功\n");

}

//从大到小排序

if(sort==0){

printf("-----从大到小排序-----\n");

for(j=0;j

//while(r!=NULL)

{

//printf("=========%d==\n",r->data.id);

for(k=j+1;k

//while(q!=NULL)

{

//printf("--%d-\n",q->data.id);

if((r->data.id)<(q->data.id))

{

//x=r->data.id;

//r->data.id=q->data.id;

//q->data.id=x;

x=r->data.id;

strcpy(s_name,r->data.name);

strcpy(s_address,r->data.address);

r->data.id=q->data.id;

strcpy(r->data.name,q->data.name);

strcpy(r->data.address,q->data.address);

q->data.id=x;

strcpy(q->data.name,s_name);

strcpy(q->data.address,s_address);

}

q=q->next;

}

r=r->next;

q=r->next;

}

printf("排序成功\n");

}

//printf("========打印r链表=========\n");

//n=r;

//printf("测试%d\n",n->data.id);

//while(n!=NULL){

// printf("%d %s %s\n",n->data.id,n->data.name,n->data.address);

// n=n->next;

//}

//printf("========打印r链表结束=========\n");

//排序存档

//FILE *fp;

fp=fopen("book.txt","w");

if(fp==NULL)

{

printf("文件打开失败\n");

exit(1);

}

//fprintf(fp,"\n");

while(n!=NULL)

{

fprintf(fp,"%-20d %-20s %-20s\n",n->data.id,n->data.name,n->data.address);

n=n->next;

}

fclose(fp);

}

//四、===========修改学生信息======

void modify_students(struct node *h)

{

system("cls");

//变量

int searchId,x,NewId;// x:选项 searchId:按学号搜 n:新学号

char NewName[60],NewAddress[60];

//1.读取文件,并将内容重新放到结构体p中

int id;

char name_stu[60],address_stu[60],s_name[60],s_address[60];

h=(struct node*)malloc(sizeof(struct node));

FILE *fp;

struct node *p,*q,*r,*n;

p=h;

r=p;

n=p;

fp=fopen("book.txt","r");

if(fp==NULL)

{

printf("文件打开失败");

}else{

//printf("文件打开成功\n");

while(fscanf(fp," %d %s %s",&id,name_stu,address_stu)!=EOF)

{

q=(struct node*)malloc(sizeof(struct node));

strcpy(q->data.name,name_stu);c 学生管理系统文档

strcpy(q->data.address,address_stu);

q->data.id=id;

q->next=NULL;

p->next=q;

p=p->next;

}

}

fclose(fp);

//printf("结束\n\n");

//2.找到对应学生

printf("\n\n\n\n\n\n\n\n\n\n\n\n");

printf(" 请输入您所要修改学生的ID:");

scanf("%d",&searchId);

printf("您将选择ID为%d的学生!!!\n",searchId);

r=r->next;

while(r!=NULL)

{

if(searchId==r->data.id){

//初始化变量

NewId=r->data.id;

strcpy(NewName,r->data.name);

strcpy(NewAddress,r->data.address);

printf(">>>>>>>>>>>>%s\n",r->data.name);

printf(">>>>>>>>>>>>%s\n",r->data.address);

while(true)

{

printf(" 请输入您要改的项目(1:学号、2:姓名、3:地址、-1:确认修改):");

scanf("%d",&x);

getchar();

//获取新学号

if(x==1){

printf(" 请输入新学号:");

scanf("%d",&NewId);

getchar();

printf("\n+++++++++%d\n",NewId);

}

//获取新姓名

if(x==2){

printf(" 请输入新姓名:");

gets(NewName);

printf("\n+++++++++%s\n",NewName);

}

//获取新地址

if(x==3){

printf("请输入新地址:");

gets(NewAddress);

printf("\n+++++++++%s\n",NewAddress);

}

//确认修改

if(x==-1){

break;

}

}

//确认修改信息

r->data.id=NewId;

strcpy(r->data.name,NewName);

strcpy(r->data.address,NewAddress);

printf("修改成功!!!\n新学号为:%d 新姓名为:%s 新地址为:%s\n",r->data.id,r->data.name,r->data.address);

break;

}

r=r->next;

}

//存档

n=n->next;

fp=fopen("book.txt","w");

if(fp==NULL)

{

printf("文件打开失败\n");

exit(1);

}

//fprintf(fp,"\n");

while(n!=NULL)

{

fprintf(fp,"%-20d %-20s %-20s\n",n->data.id,n->data.name,n->data.address);

n=n->next;

}

fclose(fp);

}

//五、删除指定学生信息

void delete_students(struct node *h)

{

system("cls");

//变量

int searchId;// x:选项 searchId:按学号搜

//1.读取文件,并将内容重新放到结构体p中

int id;

char name_stu[60],address_stu[60],s_name[60],s_address[60];

h=(struct node*)malloc(sizeof(struct node));

FILE *fp;

struct node *p,*q,*r,*m,*n,*k;//m:用来切割节点保存前一个节点

p=h;

r=p;//查询指针

m=p;//

n=r;//存数据指针

fp=fopen("book.txt","r");

if(fp==NULL)

{

printf("文件打开失败");

}else{

//printf("文件打开成功\n");

while(fscanf(fp," %d %s %s",&id,name_stu,address_stu)!=EOF)

{

q=(struct node*)malloc(sizeof(struct node));

strcpy(q->data.name,name_stu);

strcpy(q->data.address,address_stu);

q->data.id=id;

q->next=NULL;

p->next=q;

p=p->next;

}

}

fclose(fp);

//2.找到对应学生

printf("\n\n\n\n\n\n\n\n\n\n\n\n");

printf(" 请输入您所要删除学生的学生号");

scanf("%d",&searchId);

getchar();

//printf("您将选择ID为%d的学生!!!\n",searchId);

//r=r->next;

//m=r->next;

while(r->next!=NULL)

{

//printf("%d ",r->data.id);

//printf("%d \n",m->data.id);

k=r;

r=r->next;

if(searchId==r->data.id)

{

//printf("YYYYYYYYYYYYYYYYYYY");

k->next=r->next;

free(r);

r=k->next;

break;

}

}

printf(" 删除成功\n");

//输出r链表 测试是否修改成功 为存档做准备

//n=n->next;

//printf("========打印r链表=========\n");

//printf("测试%d\n",n->data.id);

//while(n!=NULL){

// printf("%d %s %s\n",n->data.id,n->data.name,n->data.address);

// n=n->next;

//}

//printf("========打印r链表结束=========\n");

//存档

n=n->next;

fp=fopen("book.txt","w");

if(fp==NULL)

{

printf("文件打开失败\n");

exit(1);

}

//fprintf(fp,"\n");

while(n!=NULL)

{

fprintf(fp,"%-20d %-20s %-20s\n",n->data.id,n->data.name,n->data.address);

n=n->next;

}

fclose(fp);

main();

//扣扣群聊172842597

}

Reprint please indicate:http://www.cnsoftweb.com/wdgl-3528.html