最新C语言药房管理系统.docx
Four short words sum up what has lifted most successful individuals above the crowd: a little bit more.-author-dateC语言药房管理系统C语言药房管理系统#include<stdio.h>#include<stdlib.h>#include<string.h>#include<conio.h>struct medicinechar name20; /药品名称char number50; /药品编号char price50; /单价char inventory50; /库存数量char brand20; /品牌 medicine100; /假设最大数为100. /定义全局变量numint num; int menu_select() char s80; int a;/*定义整形变量*/ system("cls"); printf("tt-您好!您已进入药房管理系统-nn"); printf("ttt1. 输入药品信息n"); printf("ttt2. 查看药品信息n"); printf("ttt3. 修改药品信息n"); printf("ttt4. 按编号查找药品n"); printf("ttt5. 按价格排序 n"); printf("ttt6. 删除药品信息n"); printf("ttt7. 退出n"); printf("tt-nn");doprintf("Enter you choice(17):"); scanf("%s",s); a=atoi(s); while (a<1 | a>7); return a;int addmedicine() printf("ttt-请输入您要保存的信息 -n"); printf("ttt输入药品名称:n"); scanf("%s",medicinenum.name); printf("ttt输入药品编号:n"); scanf("%s",medicinenum.number); printf("ttt单价:n"); scanf("%s",medicinenum.price); printf("ttt品牌:n"); scanf("%s",medicinenum.brand); printf("ttt库存数量 :n"); scanf("%s",medicinenum.inventory); num+; printf("ttt是否继续添加?(Y/N):n"); if(getch()='y' | getch()='Y') addmedicine(); return(0);void modifybyname() /按药品名称修改char c;int i,mark=0;char name20;printf("ntt请输入要修改的药品名称:"); scanf("%s",name);if(num=0)printf("ntt文件中无相关药品");printf("ntt按任意键返回主菜单");getch(); mark+;return; for(i=0;i<num;i+)if(strcmp(medicinei.name,name)=0) printf("ntt以下是您要修改的药品信息"); printf("ntt药品名称: %s",medicinei.name); printf("ntt药品编号: %s",medicinei.number); printf("ntt单价: %s",medicinei.price); printf("ntt品牌: %s",medicinei.brand); printf("ntt库存数量: %s",medicinei.inventory); printf("ntt是否修改(y/n)"); if(getch()='y') printf("nt-请选择修改信息-");printf("nt 1-修改药品名称 ");printf("nt 2-修改药品编号 ");printf("nt 3-修改单价 "); printf("nt 4-修改品牌 ");printf("nt 5-修改库存数量 ");printf("nt-");printf("nt请选择您所要的服务:"); scanf("%s",&c);switch(c) case '1': printf("nt请输入新药品名称: "); scanf("%s",medicinei.name);break; case'2':printf("nt请输入新药品编号: %s"); scanf("%s",medicinei.number);break; case'3':printf("nt请输入新单价: "); scanf("%s",medicinei.price);break; case'4':printf("nt请输入新品牌: "); scanf("%s",medicinei.brand);break; case'5':printf("nt请输入新库存数量: "); scanf("%s",medicinei.inventory);break; if(mark=0)printf("ntt药品信息修改完毕");printf("nt是否继续修改?(Y/N):");if(getch()='y')modifybyname();return; void list() int i; system("cls"); if(num!=0) printf("ttt-已为您显示所有药品信息-n"); for (i=0;i<num;i+) printf("ttt药品名称:%sn",medicinei.name);printf("ttt药品编号:%sn",medicinei.number);printf("ttt单价:%sn",medicinei.price); printf("ntt品牌: %sn",medicinei.brand);printf("ttt库存数量:%sn",medicinei.inventory); if(i+1<num) system("pause"); printf("ttt-n"); else printf("ttt系统中无任何记录n"); printf("ttt按任意键返回主菜单:n"); getch(); return;int searchbyname() int mark=0; int i; printf("ttt- 按药品名称查找 -n"); char name20; printf("ttt请输入药品名称:n"); scanf("%s",name); for(i=0;i<num;i+) if (strcmp(medicinei.name,name)=0) printf("ttt- 以下是您查找的药品信息 -n");printf("ttt药品名称: %s",medicinei.name);printf("ttt药品编号: %s",medicinei.number);printf("ttt单价: %s",medicinei.price); printf("ntt品牌: %s",medicinei.brand);printf("ttt库存数量:%sn",medicinei.inventory);printf("ttt-n");mark+; if(i+1)<num) printf("ttt是否继续查找相同名称的药品信息:(y/n)n"); if(getch()='y' | getch()='Y') continue; else return(0); else printf("ttt请按任意键返回主菜单"); getch(); return(0); if(mark = 0) printf("ttt没有您要查找的药品记录n"); printf("ttt请按任意键返回主菜单n"); getch(); return(0); return 0;int searchbynumber()int mark=0;int i;printf("ttt-按药品编号查找 -n");char number10;printf("ttt请输入药品编号:n");scanf("%s",number);for(i=0;i<num;i+) if (strcmp(medicinei.number,number)=0) printf("ttt-以下是您查找的药品信息 -n"); printf("ttt药品名称: %s",medicinei.name); printf("ttt药品编号: %s",medicinei.number); printf("ttt单价: %s",medicinei.price); printf("ntt品牌: %s",medicinei.brand); printf("ttt库存数量:%sn",medicinei.inventory); printf("ttt-n"); printf("ttt请按任意键返回主菜单n"); mark+; getch(); return(0); if (mark=0) printf("ttt没有改药品的信息n"); printf("ttt请按任意键返回主菜单n"); getch(); return(0);return(0);void deletebynumber()int i,j;int deletemark=0;char number20; printf("ttt请输入要删除药品编号:n"); scanf("%s",number); if(num=0) printf("ttt对不起,系统中无任何记录n"); printf("ttt请按任意键返回主菜单n"); getch(); return; for (i=0;i<num;i+) if (strcmp(medicinei.number,number)=0) printf("ttt以下是您要删除的用户记录:n"); printf("ttt药品名称: %s",medicinei.name); printf("ttt药品编号: %s",medicinei.number); printf("ttt单价: %s",medicinei.price); printf("ntt品牌: %s",medicinei.brand); printf("ttt库存数量:%sn",medicinei.inventory); printf("ttt是否删除?(y/n)"); if (getch()='y' | getch()='Y') for (j=i;j<num-1;j+) medicinej=medicinej+1; num-; deletemark+; printf("ttt删除成功"); printf("ttt是否继续删除?(y/n)"); if (getch()='y' | getch()='Y') deletebynumber(); return; else return; continue; if (deletemark=0) printf("ttt没有该药品的记录"); printf("ttt是否继续删除?(y/n)"); if(getch()='y' | getch()='Y') deletebynumber(); return; return;void deletebyname()int a=0;int findmark=0;int j;int deletemark=0;int i;char name20;printf("ttt请输入要删除药品名称:n");scanf("%s",name);for (i=a;i<num;i+) if(strcmp(medicinei.name,name)=0) printf("ttt以下是您要删除的药品信息:"); findmark+; printf("ttt_"); printf("ttt药品名称: %s",medicinei.name); printf("ttt药品编号: %s",medicinei.number); printf("ttt单价: %s",medicinei.price); printf("ntt品牌: %s",medicinei.brand); printf("ttt库存数量:%sn",medicinei.inventory); printf("ttt_"); printf("ttt是否删除?(y/n)"); if (getch()='y' | getch() = 'Y') for(j=i;j<num-1;j+) medicinej=medicinej+1; num-; deletemark+; printf("ttt删除成功"); if(i+1)<num) printf("ttt是否继续删除相同名称的药品信息?(y/n)"); if (getch()='y') a=i; continue; printf("ttt是否继续删除?(y/n)"); if (getch()='y') deletebyname(); return; if(i+1)<num) printf("ttt是否继续删除相同名称的药品信息?(y/n)"); if (getch()='y' | getch() = 'Y') a=i; continue; elsecontinue;if (deletemark=0)&&(findmark=0) printf("ttt没有该药品的记录"); printf("ttt是否继续删除?(y/n)"); if(getch()='y' | getch() = 'Y') deletebynumber(); return;else if (findmark!=0) printf("ttt没有重名信息"); printf("ttt没有该药品的记录"); printf("ttt是否继续删除?(y/n)"); if(getch()='y' | getch() = 'Y') deletebynumber(); return; int dele() /删除记录char choic; printf("ttt1-按药品编号删除 2-按药品名称删除"); printf("ttt请选择:"); choic=getch();switch (choic) case '1':deletebynumber();break; case '2':deletebyname();break; return(0);int sortbyprice() /按药品单价进行排序 int i,j; struct medicine tmp; for (i=1;i<num;i+) if(strcmp(medicinei.price,medicinei-1.price)<0) tmp=medicinei; j=i-1; do medicinej+1=medicinej; j-; while (strcmp(tmp.price,medicinej.price)<0&&j>=0); medicinej+1=tmp; printf("ttt排序成功,是否显示?(y/n)"); if (getch()='y') list(); return(0);int main() printf("tt-n"); printf("tt-Welcome to management system -n"); printf("tt-Made By 蒋俊杰 李梁伟 郑奈春-n"); printf("tt-n"); printf("请按任意键进入主菜单:)n"); getch(); int selectnum; while(1) selectnum = menu_select(); switch(selectnum) case 1:addmedicine(); /添加药品信息break;case 2: list(); break;case 3: modifybyname(); /修改药品信息 break;case 4: searchbynumber(); /按药品编号查找 break;case 5: sortbyprice(); /按药品单价排序 break;case 6: dele(); break;case 7:printf("BYE BYE!n");system("pause");getchar(); exit(0); getchar(); return 0; -