C语言程序设计学生信息管理系统

C语言程序设计学生信息管理系统,第1张

/

创建日期:2011-04-27

程序名称:链表综合 *** 作

程序作者:子夜星空

备注信息:以前写的。

/

#include <stdioh>

#include <stringh>

#include <stdlibh>

#define SN 2 //科目数

typedef struct student

{

char num[10],

name[10];

float score[SN],

sum,

avg;

struct student next;

}STU;

/输入链表单元内容/

void input(STU p)

{

int i;

printf("please input number:\n");

scanf("%s",p->num);

printf("please input name:\n");

scanf("%s",p->name);

printf("please input %d scores:\n",SN);

p->sum=0;

for(i=0;i<SN;i++)

{

scanf("%f",&p->score[i]);

p->sum+=p->score[i];

}

p->avg=p->sum/SN;

}

/创建一个链表单元/

STU creat_node()

{

STU p;

p=(STU )malloc(sizeof(STU));

if(p == NULL)

{ printf("No enough memory !");

exit(0);

}

input(p);

p->next=NULL;

return p;

}

/创建一个链表/

STU creat_list()

{

STU head=NULL,tail=NULL,p;

char str[4];

printf("List creating\n");

do

{

printf("Do you want to continue (yes/no) :");

scanf("%s",str);

if(strcmp(str,"yes")==0)

{

p=creat_node();

if(head==NULL){head=tail=p;continue;}

tail->next=p;

tail=p;

}

if(strcmp(str,"yes")!=0&&strcmp(str,"no")!=0)

{

printf("You must input 'yes' or 'no'\n");

//getchar();

continue;

}

if(strcmp(str,"no")==0)break;

//getchar();

}while(1);

printf("List create end\n\n");

return head;

}

/输出一个链表单元/

void print_a_node(STU fin)

{

int i;

printf("%s;\t%s;\t%02f;\t%02f\t",fin->num,fin->name,fin->avg,fin->sum);

for(i=0;i<SN;i++)

printf("%02f\t",fin->score[i]);

putchar(10);

}

/输出一个链表头部/

void print_a_head()

{

int i;

printf("number\tname\tavg\tsum\t");

for(i=0;i<SN;i++)

printf("score%d\t",i+1);

putchar(10);

}

/输出 *** 作菜单/

void print_menu_list()

{

printf("======the operation menu list======\n");

printf("[0]-->exit\n[1]-->creat a list\n[2]-->print the list\n[3]-->insert a list node\n[4]-->select by number\n[5]-->select by name\n");

printf("[6]-->delete a list node\n[7]-->update a list node\n[8]-->order the list by score\n[9]-->print the operation menu list\n");

printf("======the operation menu list======\n");

putchar(10);

}

/输出链表/

int print_list(STU stu)

{

STU p=stu;

if(stu==NULL)

{

printf("no records!!!\n");

return (0);

}

print_a_head();

while(p!=NULL)

{

print_a_node(p);

p=p->next;

}

putchar(10);

return (0);

}

/插入链表单元/

void insert(STU stu)

{

STU tail=stu,p;

printf("now insert a list node\n");

while(tail->next!=NULL)

{

tail=tail->next;

}

p=creat_node();

tail->next=p;

printf("Insert end\n\n");

}

/查找链表num/

STU find_num(STU stu, char num[])

{

STU p=stu,pr=NULL;

while(p!=NULL)

{

if(strcmp(p->num,num)==0){pr=p;break;}

p=p->next;

}

return pr;

}

/查找链表name/

STU find_name(STU stu, char name[])

{

STU p=stu,pr=NULL;

while(p!=NULL)

{

if(strcmp(p->name,name)==0){pr=p;break;}

p=p->next;

}

return pr;

}

/删除链表单元/

STU delet(STU stu, char name[])

{

STU p=stu,front=stu;

if((p=find_name(stu,name))!=NULL)

{

printf("the delete record:\n");

print_a_head();

print_a_node(p);

}

else

{

printf("can not find the student!\n");

return stu;

}

p=stu;

while(p!=NULL&&strcmp(p->name,name)!=0)

{

front=p;

p=p->next;

}

if(p==stu&&front==stu)stu=NULL;

else front->next=p->next;

if(p!=NULL)p->next=NULL;

free(p);

printf("delete end\n\n");

return stu;

}

/更新链表单元/

void update(STU stu, char name[])

{

STU fin;

if((fin=find_name(stu,name))!=NULL)

{

printf("before update:\n");

print_a_head();

print_a_node(fin);

}

else

{

printf("can not find the student!\n");

exit(0);

}

printf("please input the new records now\n");

input(fin);

printf("update end\n\n");

}

/链表单元排序/

void order(STU stu)

{

STU pi,pj,max,temp;

int i;

if(stu!=NULL&&stu->next!=NULL)

{

for(pi=stu;pi!=NULL;pi=pi->next)

{

max=pi;

for(pj=pi->next;pj!=NULL;pj=pj->next)

{

if(max->sum<pj->sum)

max=pj;

}

if(max!=pi)

{

strcpy(tempnum,max->num);

strcpy(max->num,pi->num);

strcpy(pi->num,tempnum);

strcpy(tempname,max->name);

strcpy(max->name,pi->name);

strcpy(pi->name,tempname);

tempsum=pi->sum;

pi->sum=max->sum;

max->sum=tempsum;

tempavg=max->avg;

max->avg=pi->avg;

pi->avg=tempavg;

for(i=0;i<SN;i++)

{

tempscore[i]=max->score[i];

max->score[i]=pi->score[i];

pi->score[i]=tempscore[i];

}

}

}

printf("order end\n\n");

}

else

printf("do not need to order\n\n");

}

/释放链表/

void fre(STU stu)

{

STU p=stu,pf;

if(stu==NULL)

{

printf("the list is NULL!\n");

exit(0);

}

while(p!=NULL)

{

pf=p->next;

free(p);

p=pf;

}

if(stu==NULL)

printf("free the list\n");

}

STU menu(STU stu,int cas)

{

STU fin=NULL;

char a[10];

switch(cas)

{

//创建链表

case 1:

if(stu!=NULL)fre(stu);

stu=creat_list();

break;

//输出链表

case 2:

if(stu==NULL){printf("can not do this operation!\n");putchar(10);break;}

print_list(stu);

break;

//插入链表单元

case 3:

if(stu==NULL){printf("can not do this operation!\n");putchar(10);break;}

insert(stu);

break;

//查找输出number

case 4:

if(stu==NULL){printf("can not do this operation!\n");putchar(10);break;}

printf("please input the 'number' you want to find:\n");

scanf("%s",a);

if((fin=find_num(stu,a))!=NULL)

{

print_a_head();

print_a_node(fin);

}

else printf("no found!\n");

break;

//查找输出name

case 5:

if(stu==NULL){printf("can not do this operation!\n");putchar(10);break;}

printf("please input the 'name' you want to find:\n");

scanf("%s",a);

if((fin=find_name(stu,a))!=NULL)

{

print_a_head();

print_a_node(fin);

putchar(10);

}

else printf("no found!\n");

break;

//删除链表单元

case 6:

if(stu==NULL){printf("can not do this operation!\n");putchar(10);break;}

printf("please input the 'name' you want to delete:\n");

scanf("%s",a);

stu=delet(stu,a);

break;

//更新链表单元

case 7:

if(stu==NULL){printf("can not do this operation!\n");putchar(10);break;}

printf("please input the 'name' you want to update:\n");

scanf("%s",a);

update(stu,a);

break;

//链表单元排序

case 8:

if(stu==NULL){printf("can not do this operation!\n");putchar(10);break;}

printf("order by score\n");

order(stu);

break;

//打印链表 *** 作菜单

case 9:

print_menu_list();

break;

default:

printf("can not do this operation!\n");putchar(10);break;

}

return stu;

}

void main()

{

STU stu=NULL;

int cas;

//打印 *** 作提示

print_menu_list();

//用户 *** 作

do

{

printf("press 0~9 to choose operation!\n");

scanf("%d",&cas);

if(cas<0||cas>9){printf("you must press 0 to 9 !\n");continue;}

if(cas!=0)stu=menu(stu,cas);

if(cas==0){printf("operation end !\n\n");fre(stu);}

}while(cas!=0);

//释放链表

fre(stu);

}

#include<stdioh>

#include<malloch>

#include<stringh>

#define LEN sizeof(struct record) /对结构体长度进行宏定义/

void menu();/声明菜单函数/

struct recordinsert(struct record head);/声明添加函数 /

struct recorddelet(struct record head); /声明删除函数 /

struct recordalter(struct record head); /声明修改函数 /

void search(struct record head); /声明查找函数/

void show(struct record head); /声明显示函数/

struct record head; /定义全局结构体指针变量/

int n=0; /定义全局变量/

struct record /声明结构体/

{

char number[10];

char name[20];

char phone[20];

char adress[40];

char postcode[10];

char e_mail[30];

struct record next;

};

/

主函数

/

main()

{

head=NULL;

menu();

rewind(stdin);

}

/

菜单函数

/

void menu()

{

int choice;

printf("\n\t\t 主菜单 ");

printf("\n\t\t 1-添加纪录 2-查询纪录 ");

printf("\n\t\t 3-删除纪录 4-修改记录 ");

printf("\n\t\t 5-显示纪录 6-退出系统 ");

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

printf("\n\t\t请选择:");

scanf("%d",&choice); rewind(stdin);

printf("\n");

switch (choice)

{

case 1:

head=insert(head);

rewind(stdin);

menu();

break;

case 2:

search(head);rewind(stdin);

menu();

break;

case 3:

head=delet(head);

rewind(stdin);

menu();

break;

case 4:

head=alter(head);

rewind(stdin);

menu();

break;

case 5:

show(head);

rewind(stdin);

menu();

break;

default:

printf("\n\t\t谢谢使用!!");

break;

}

}

/

添加函数

/

struct record insert(struct record head)

{

struct record pp,p1,p2;

pp=(struct record )malloc(LEN);

printf("\n\t\t 请输入用户信息 \n");

printf("\n\t\t输入序号:");

scanf("%s",pp->number); rewind(stdin);

printf("\n\t\t输入姓名:");

scanf("%s",pp->name);rewind(stdin);

printf("\n\t\t输入电话号码:");

scanf("%s",pp->phone); rewind(stdin);

printf("\n\t\t输入地址:");

scanf("%s",pp->adress); rewind(stdin);

printf("\n\t\t输入邮编:");

scanf("%s",pp->postcode); rewind(stdin);

printf("\n\t\t输入e-mail:");

scanf("%s",pp->e_mail); rewind(stdin);

if(head==NULL)/在表头插入1/

{

head=pp;

pp->next=NULL;

}

else

{

p1=head;

while((strcmp(pp->number,p1->number)>0)&&(p1->next!=NULL))

{

p2=p1;

p1=p1->next;

}

if(strcmp(pp->number,p1->number)<=0)

{

if(head==p1)

head=pp; /在表头插入2/

else

p2->next=pp;/在表中插入/

pp->next=p1;

}

else /在表尾插入/

{

p1->next=pp;

pp->next=NULL;

}

}

printf("\t添加成功!请继续选择功能键!\n\n");

n=n+1;

return(head);

}

/

删除函数

/

struct recorddelet(struct record head)

{

struct record p1,p2;

char number[10];

printf("\t请输入要删除用户的序号number:");

scanf("%s",&number);rewind(stdin);

if(head==NULL)

{

printf("\n\t通讯录无用户信息记录!!\n");

return(head);

}

p1=head;

while(strcmp(number,p1->number)!=0&&p1->next!=NULL)

{

p2=p1;

p1=p1->next;

}

if(strcmp(number,p1->number)==0)

{

if(p1==head)

{

head=p1->next;

printf("\t删除成功!请继续选择功能键!\n\n");

}

else

{

p2=p1->next;

printf("\t已删 除的用户的序号为:%s\n",number);

printf("\t删除成功!请继续选择功能键!\n\n");

}

n=n-1;

}

else printf("\t通讯录无该用户的信息记录!\n ");

return(head);

}

/

查询函数

/

void search(struct record head)

{

int a;

char f_name[20],f_number[10];

struct record p1,p2;

if(head==NULL)

{

printf("\t通讯录无用户信息记录\n");

return;

}

else

{

printf("\t请你选择你查找的方式:\n\n\t\t1:序号\n\t\t2:姓名\n");

printf("\t\t请选择:");

scanf("%d",&a);rewind(stdin);

switch(a)

{case 1:

printf("\n\t请输入要查找用户的序号number:");

scanf("%s",&f_number);rewind(stdin);

p1=head;

while(strcmp(p1->number,f_number)!=0)

{

if(p1->next==NULL)

{

printf("\n\t通讯录无此用户信息记录\n");

return;

}

else

{

p2=p1->next;

p1=p2;

}

}

printf("\n\t要查找用户的基本信息为:\n");

printf("\t\t序号: %s\n\t\t姓名:%s\n\t\t电话号码:%s",p1->number,p1->name,p1->phone);

printf("\n\t\t地址:%s\n\t\t邮编:%s\n\t\te_mail:%s\n",p1->adress,p1->postcode,p1->e_mail);

break;

case 2:

printf("\n\t请输入要查找用户的姓名name:");

scanf("%s",f_name);rewind(stdin);

p1=head;

while(strcmp(p1->name,f_name)!=0)

{

if(p1->next==NULL)

{

printf("\n\t通讯录无此用户信息记录\n");

return;

}

else

{

p2=p1->next;

p1=p2;

}

}

printf("\n\t要查找用户的基本信息为:\n");

printf("\t\t序号: %s\n\t\t姓名:%s\n\t\t电话号码:%s",p1->number,p1->name,p1->phone);

printf("\n\t\t地址:%s\n\t\t邮编:%s\n\t\te_mail:%s",p1->adress,p1->postcode,p1->e_mail);

break;

}

}

}

/

显示函数

/

void show(struct record head)

{

int i;

struct record p1,p2;

p1=head;

if(head==NULL)

{

printf("\t通讯录无用户信息记录\n");

return;

}

else

{

for(i=1;i<=n;i++)

{

printf("\n\t第%d个用户的基本信息为:",i);

printf("\n\t\t序号: %s 姓名:%s 电话号码:%s \n\t\t地址:%s 邮编:%s e_mail:%s\n"

,p1->number,p1->name,p1->phone,p1->adress,p1->postcode,p1->e_mail);

p2=p1->next;

p1=p2;

}

}

}

/

修改函数

/

struct recordalter(struct recordhead)

{

struct record p1,p2;

int choice1;

char alter_number[10],alter_name[20],alter_phone[20],alter_adress[40],alter_postcode[10],alter_e_mail[30],choice2;

p1=head;

if(head==NULL)

{

printf("通讯录无用户信息记录\n");

return(head);

}

printf("\t请输入要修改的用户的序号number:");

scanf("%s",alter_number);

rewind(stdin);

while(strcmp(p1->number,alter_number)!=0)

{

if(p1->next==NULL)

{

printf("\n\t通讯录无此用户信息记录\n");

return(head);

}

else

{

p2=p1;

p1=p1->next;

}

}

if(strcmp(p1->number,alter_number)!=0)

{

printf("通讯录无用户信息记录\n");

return(head);

}

else

{

printf("\t要修改的用户的基本信息为:\n\t");

printf("\t序号: %s 姓名:%s 电话号码:%s 地址:%s 邮编:%s e_mail:%s\n"

,p1->number,p1->name,p1->phone,p1->adress,p1->postcode,p1->e_mail);

}

while(1)

{

printf("\t你是否要修改的用户的基本信息(y&n)");

scanf("%c",&choice2);

rewind(stdin);

if(choice2=='y')

{

printf("\t请选择你要修改的项目:\n\t");

printf("1:姓名 2:电话号码 3:地址 4:邮编 5:e_mail\n");

printf("\t你选择的序号为: ");

scanf("%d",&choice1);

rewind(stdin);

switch(choice1)

{case 1:printf("\t请输入更改后的姓名");

scanf("%s",alter_name);rewind(stdin);

strcpy(p1->name,alter_name);

continue;

case 2:printf("\t请输入更改后的电话号码");

scanf("%s",alter_phone);rewind(stdin);

strcpy(p1->phone,alter_phone);

continue;

case 3:printf("\t请输入更改后的地址");

scanf("%s",alter_adress);rewind(stdin);

strcpy(p1->adress,alter_adress);

continue;

case 4:printf("\t请输入更改后的邮编");

scanf("%s",&alter_postcode);rewind(stdin);strcpy(p1->postcode,alter_postcode);

continue;

case 5:printf("\t请输入更改后的e_mail");

scanf("%s",alter_e_mail);rewind(stdin);

strcpy(p1->e_mail,alter_e_mail);

continue;

}

printf("\n\t修改后用户的基本信息为:\n\t");

printf("\t序号: %s 姓名:%s 电话号码:%s 地址:%s 邮编:%s e_mail\n"

,p1->number,p1->name,p1->phone,p1->adress,p1->postcode,p1->e_mail);

}

else

{

printf("\n\t修改成功!!\n");

break;

}

}

return(head);

}

以上就是关于C语言程序设计学生信息管理系统全部的内容,包括:C语言程序设计学生信息管理系统、急!!C语言程序设计!! 学生成绩管理系统、等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zz/9696886.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-01
下一篇 2023-05-01

发表评论

登录后才能评论

评论列表(0条)

保存