结构体c语言成绩查询,用C语言的结构体编辑学生成绩管理系统!

#include #define name_max 100//书的名字的最长字数

#define writer_max 100//作者名字的最长

#define pub_max 100//出版单位最长名字

#define time 100//出版时间

typedef struct books

{

int loading;

char name[name_max];

char writer[writer_max];

int identify;

char pub[pub_max];

char time[time];

int price;

struct books * next;

}book;

//头结点不存储信息

void init(book * head)

{

head->next=null;

}

//打印一些欢迎词之类的。。。。。

void welcome()

{

printf("******欢迎使用@@@@图书馆,哈哈*********\n");

printf("\n\n");

printf("1:图书信息录入功能\n");

printf("2:图书信息浏览功能,显示该书的所有信息\n");

printf("3:图书信息查询功能:按书名查询与按作者名查询\n");

printf("4:图书信息的修改和删除,可对相应数据进行修改和删除\n");

}

//显示一本书的信息

void print_the_book(book * p1)

{

printf("loading number:%d \n",p1->loading);

printf("name: ");

puts(p1->name);

printf(" \n");

printf("writer: ");

puts(p1->writer);

printf(" \n");

printf("identify:%d ***\n",p1->identify);

printf(" \n");

printf("pub: ");

puts(p1->pub);

printf(" \n");

printf("time: ");

puts(p1->time);

printf(" \n");

printf("price:%d ***\n",p1->price);

}

int chongfu(book * head,book * p)

{

book * p1=head->next;

int a=0;

while(p1!=null)

{

if(strcmp(p1->name,p->name)==0)

{

if(strcmp(p1->writer,p->writer)==0)

{

a=1;

break;

}

}

else

p1=p1->next;

}

return a;

}

//录入一些信息。。。。

void luru(book * head)

{

book * p1=head;

book * p2;

//寻找null前的那个点

while(p1->next!=null)

{

p1=p1->next;

}

int a;

do

{

p2=(book *)malloc(sizeof(book));

printf("输入书本信息\n");

printf("登录号\n");

fflush(stdin);

scanf("%d",&p2->loading);

printf("书名\n");

fflush(stdin);

gets(p2->name);

fflush(stdin);

printf("作者\n");

gets(p2->writer);

fflush(stdin);

printf("分类号\n");

scanf("%d",&p2->identify);

fflush(stdin);

printf("出版社\n");

gets(p2->pub);

fflush(stdin);

printf("出版时间\n");

gets(p2->time);

fflush(stdin);

printf("价格\n");

scanf("%d",&p2->price);

p2->next=null;

fflush(stdin);

//加入链表

if(chongfu(head,p2))

printf("录入信息重复\n");

else

{

p1->next=p2;

p1=p2;

}

printf("还想继续录入信息吗?\n(1:继续 0:停止)\n");

scanf("%d",&a);

}while(a==1);

}

void liulan(book * head)

{

book * p1=head->next;

int i=1;

while(p1!=null)

{

printf("*********第%d本书***********\n",i++);

print_the_book(p1);

p1=p1->next;

}

}

//查询。。。。

void chaxun(book * head)

{

printf("按书名查询还是按作者名查询?\n(1:按书名查询 0:按作者名查询)\n");

book * p=head->next;

int a;

scanf("%d",&a);

int num=0;

char cha[name_max];

switch(a)

{

case 1:

printf("输入书名:\n");

gets(cha);

while(p!=null)

{

if(strcmp(p->name,cha)==0)

{

num++;

print_the_book(p);

}

p=p->next;

}

break;

case 2:

printf("输入作者名:\n");

gets(cha);

while(p!=null)

{

if(strcmp(p->writer,cha)==0)

{

num++;

print_the_book(p);

}

p=p->next;

}

}

if(num==0)

printf("无符合书本\n");

}

//修改信息

void xiugai(book * head)

{

printf("输入需要修改书本的名称和作者:\n");

char name_book[name_max];

char writer_book[writer_max];

printf("书本名称:");

gets(name_book);

gets(writer_book);

book * p1=head->next;

int a=0;

while(p1!=null)

{

if(strcmp(p1->name,name_book)==0)

{

if(strcmp(p1->writer,writer_book)==0)

{

a=1;

break;

}

}

}

if(a==0)

printf("没有这本书。。。\n");

else

{

print_the_book(p1);

printf("输入新信息\n");

scanf("%d",&p1->loading);

gets(p1->name);

gets(p1->writer);

scanf("%d",&p1->identify);

gets(p1->pub);

gets(p1->time);

scanf("%d",&p1->price);

}

}

void main()

{

book * head;

head=(book *)malloc(sizeof(book));

init(head);

int contin=1;

while(contin)

{

welcome();

printf("想进行哪项操作?\n");

int a;

scanf("%d",&a);

switch(a)

{

case 1:

luru(head);

break;

case 2:

liulan(head);

break;

case 3:

chaxun(head);

break;

case 4:

xiugai(head);

}

printf("继续使用图书馆还是退出?\n(1:continue 0:exit)\n");

scanf("%d",&contin);

}

}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值