用switch case写一个图书馆管理系统的C程序
问题
如何使用C编程存储图书馆图书相关信息。
算法
Step 1: Declare a structure which holds data members Step 2: declare variables which are used for loop Step 3: use switch case to work on each module Step 4: case 1- for Adding book information Case 2- for Display book information Case 3- for Finding number for books in library Case 4- for EXIT
程序
#include#include #include #include struct library{ char bookname[50]; char author[50]; int noofpages; float price; }; int main(){ struct library lib[100]; char bookname[30]; int i,j, keepcount; i=j=keepcount = 0; while(j!=6){ printf("\n1. Add book information\n"); printf("2.Display book information\n"); printf("3. no of books in the library\n"); printf("4. Exit"); printf ("\n\nEnter one of the above : "); scanf("%d",&j); switch (j){ /* Add book */ case 1: printf ("Enter book name = "); scanf ("%s",lib[i].bookname); printf ("Enter author name = "); scanf ("%s",lib[i].author); printf ("Enter pages = "); scanf ("%d",&lib[i].noofpages); printf ("Enter price = "); scanf ("%f",&lib[i].price); keepcount++; i++; break; case 2: printf("you have entered the following information\n"); for(i=0; i 输出结果 1. Add book information 2.Display book information 3. no of books in the library 4. Exit Enter one of the above : 1 Enter book name = HarryPotter Enter author name = hp Enter pages = 250 Enter price = 350.6 1. Add book information 2.Display book information 3. no of books in the library 4. Exit Enter one of the above : 2 you have entered the following information book name = HarryPotter author name = hp pages = 250 price = 350.600006 1. Add book information 2.Display book information 3. no of books in the library 4. Exit Enter one of the above : 3 No of books in library : 1 1. Add book information 2.Display book information 3. no of books in the library 4. Exit Enter one of the above : 4