c语言图书管理系统_C语言图书管理系统

我是一名编程爱好者,在这里我会一直更新学习教程,所有教程内容均为原创。

#include #include #include #include#define NUM 100typedef struct {   char ISBN[30];            //书号   char book[30];           //书名   char author[30];          //作者   int edition;              //版本号   char press[30];          //出版社名    int year;               //出版年    int price;               //价格 } Bookinfo;Bookinfo books[NUM];int n=0;int Input(Bookinfo dictList[],int n){  char ch;  do  {    printf("请输入书号:\n");    scanf("%s", dictList[n].ISBN);    printf("请输入书名:\n");    scanf("%s", dictList[n].book);    printf("请输入作者:\n");    scanf("%s", dictList[n].author);    printf("请输入版本号:\n");    scanf("%d", &dictList[n].edition);    printf("请输入版出版社名:\n");    scanf("%s", dictList[n].press);    printf("请输入出版年:\n");    scanf("%d", &dictList[n].year);    printf("请输入价格:\n");    scanf("%d", &dictList[n].price);    printf("还要继续输入吗?(Y/N):");    getchar();    scanf("%c", &ch);    n++;  } while (ch != 'n'&&ch != 'N');   return n; }void Display(Bookinfo dictList[],int n)  //打印{    int i;    i=0;    for(i=0;i//遍历数组    {        printf("%s ",dictList[i].ISBN);        printf("%s ",dictList[i].book);        printf("%s ",dictList[i].author);        printf("%d ",dictList[i].edition);        printf("%s ",dictList[i].press);        printf("%d",dictList[i].year);        printf("%d\n",dictList[i].price);    }}int Delete(Bookinfo dictList[],int n,char*book)  //删除{    int i;    int j;    for(i=0;i    {       if(strcmp(dictList[i].book,book)==0)       {           break;       }    }    for(j=i;j-1;j++)    {        dictList[j]=dictList[j+1];    }    return n-1;}void Sort_by_name(Bookinfo dictList[],int n){    Bookinfo a;    int i;    int j;    for(i=0;i    {        for(j=0;j-1;j++)        {            if(strcmp(dictList[j].book,dictList[j+1].book)>0) //从小到打排序            {                a=dictList[j];                dictList[j]=dictList[j+1];                dictList[j+1]=a;            }        }    }}void Sort_by_price(Bookinfo dictList[],int n){    Bookinfo a;    int i;    int j;    for(i=0;i    {        for(j=0;j-1;j++)        {            if(dictList[j].price>dictList[j+1].price)            {                a=dictList[j];                dictList[j]=dictList[j+1];                dictList[j+1]=a;            }        }    }}void Sort_by_year(Bookinfo dictList[],int n){    Bookinfo a;    int i;    int j;    for(i=0;i    {        for(j=0;j-1;j++)        {            if(dictList[j].year>dictList[j+1].year)            {                a=dictList[j];                dictList[j]=dictList[j+1];                dictList[j+1]=a;            }        }    }}void Sort_by_author(Bookinfo dictList[],int n){    Bookinfo a;    int i;    int j;    for(i=0;i    {        for(j=0;j-1;j++)        {            if(strcmp(dictList[j].author,dictList[j+1].author)>0)            {                a=dictList[j];                dictList[j]=dictList[j+1];                dictList[j+1]=a;            }        }    }}void Sort_by_press(Bookinfo dictList[],int n){    Bookinfo a;    int i;    int j;    for(i=0;i    {        for(j=0;j-1;j++)        {            if(strcmp(dictList[j].press,dictList[j+1].press)>0)            {                a=dictList[j];                dictList[j]=dictList[j+1];                dictList[j+1]=a;            }        }    }}int Insert(Bookinfo dictList[],int n,Bookinfo*s)  //插入{    int i;    int j;     for(i=0;i    {       if(strcmp(dictList[i].book,s->book)>0)       {           break;       }      }    for(j=n;j>i;j--)    {       dictList[j]=dictList[j-1];    }    dictList[i]=*s;    return n+1;}int Insert_a_record(Bookinfo dictList[],int n){       Bookinfo a;  //先建立一个结构体变量a,      int b;        printf("请输入书号:\n");    scanf("%s", a.ISBN);  //输入相关的属性    printf("请输入书名:\n");    scanf("%s", a.book);    printf("请输入作者:\n");    scanf("%s", a.author);    printf("请输入版本号:\n");    scanf("%d", &a.edition);    printf("请输入版出版社名:\n");    scanf("%s", a.press);    printf("请输入出版年:\n");    scanf("%d", &a.year);    printf("请输入价格:\n");    scanf("%d", &a.price);       b= Insert( dictList,n,&a);  //调用该函数    return b;}void Query_a_record1(Bookinfo dictList[],int n){    char book[30];    printf("请输入书名:\n");    scanf("%s", book);    int i;    int j;    j=0;    for(i=0;i//遍历数组,判断所有图书里面是否有与zhi相同的    {        if(strcmp(dictList[i].book,book)==0)       {            j++;       }    }    if(j==0) printf("查询无效\n");    else  printf("%d\n",j);}void Query_a_record2(Bookinfo dictList[],int n){    char press[30];    printf("请输入出版社:\n");    scanf("%s",press );    int i;    int j;    j=0;    for(i=0;i    {        if(strcmp(dictList[i].press,press)==0)//遍历数组,判断所有图书里面是否有与zhi相同的       {            j++;       }    }    if(j==0) printf("查询无效\n");    else  printf("一共%d本\n",j);}void Query_a_record3(Bookinfo dictList[],int n){    char author[30];    printf("请输入作者:\n");    scanf("%s",author );    int i;    int j;    j=0;    for(i=0;i    {        if(strcmp(dictList[i].author,author)==0)//遍历数组,判断所有图书里面是否有与zhi相同的       {            j++;       }    }    if(j==0) printf("查询无效\n");    else  printf("一共%d本\n",j);}void Query_a_record4(Bookinfo dictList[],int n){    int year;    printf("请输入出版年:\n");    scanf("%d",&year );    int i;    int j;    j=0;    for(i=0;i//遍历数组,判断所有图书里面是否有与zhi相同的    {        if(dictList[i].year==year)       {            j++;       }    }    if(j==0) printf("查询无效\n");    else  printf("一共%d本\n",j);}void Query_a_record5(Bookinfo dictList[],int n){    int price;    printf("请输入价格:\n");//遍历数组,判断所有图书里面是否有与zhi相同的    scanf("%d",&price );    int i;    int j;    j=0;    for(i=0;i    {        if(dictList[i].price==price)       {            j++;       }    }    if(j==0) printf("查询无效\n");    else  printf("一共%d本\n",j);}void Display_main_menu(){while(1){  printf("1.图书信息输入\n");  printf("2.图书信息输出\n");  printf("3.删除图书信息\n");  printf("4.图书插入1\n");  printf("5.图书插入2\n");  printf("6.图书查询1\n");  printf("7.图书查询2\n");  printf("8.图书查询3\n");  printf("9.图书查询4\n");  printf("10.图书查询5\n");  printf("11.图书排序1\n");  printf("12.图书排序2\n");  printf("13.图书排序3\n");  printf("14.图书排序4\n");  printf("15.图书排序5\n");  printf("0.退出\n");  int a;  scanf("%d",&a);  switch(a)  {   case 1 :        system("cls");        n=Input(books,n);  //输入图书信息,返回图书个数        system("pause");         system("cls");        break;   case 2 :        system("cls");        Display(books,n);  //打印图书信息,遍历数组        system("pause");        system("cls");        break;   case 3 :        system("cls");        char c[30];        printf("请输入要删除的书名");        scanf("%s",c);     //输入书名        n=Delete(books,n,c);  //删除一本图书,返回剩余的图书个数    system("pause");         system("cls");        break;   case 4 :        system("cls");        n=Insert_a_record(books,n);  //插入图书,返回图书个数        system("pause");         system("cls");        break;   case 5 :        system("cls");        Bookinfo a;        printf("请输入书号:\n");        scanf("%s", a.ISBN);    printf("请输入书名:\n");    scanf("%s", a.book);    printf("请输入作者:\n");    scanf("%s", a.author);    printf("请输入版本号:\n");    scanf("%d", &a.edition);    printf("请输入版出版社名:\n");    scanf("%s", a.press);    printf("请输入出版年:\n");    scanf("%d", &a.year);    n=Insert(books,n,&a);        system("pause");         system("cls");        break;     case 6 :            system("cls");            Query_a_record1(books,n);            system("pause");             system("cls");            break;     case 7 :            system("cls");            Query_a_record2(books,n);            system("pause");             system("cls");            break;     case 8 :            system("cls");            Query_a_record3(books,n);            system("pause");             system("cls");            break;     case 9 :            system("cls");            Query_a_record4(books,n);            system("pause");             system("cls");            break;     case 10 :            system("cls");            Query_a_record5(books,n);            system("pause");             system("cls");            break;     case 11 :            system("cls");            Sort_by_name(books,n);            system("pause");             system("cls");            break;     case 12 :            system("cls");            Sort_by_price(books,n);            system("pause");             system("cls");            break;     case 13 :            system("cls");            Sort_by_year(books,n);            system("pause");             system("cls");            break;     case 14 :            system("cls");            Sort_by_author(books,n);            system("pause");             system("cls");            break;     case 15 :            system("cls");            Sort_by_press(books,n);            system("pause");             system("cls");            break;     case 0: return;  } } } int main(){     while(1)     {         printf("1.进图书管理系统\n");         printf("0.退出\n");         int a;        scanf("%d",&a);          switch(a)          {              case 1 :         system("cls");         Display_main_menu();;         system("pause");         system("cls");         break;      case 0 :        return 0;          }     }return 0; }

最后,看完你有什么收获呢? 

9c88465a67f45e42e599f3bf7a8b8885.png

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值