2022年药店的药品销售统计系统扫描 .pdf
头文件drug.h #define MaxSize 50 typedef struct node char num8; /* 药品编号 */ char name16; /* 药品名称 */ float price; /* 药品单价 */ int count; /* 销售数量 */ float sale; /* 本药品销售额*/ int next; DataType; typedef struct DataType rMaxSize; int length; SequenList; * main.cpp #include drug.h #include #include using namespace std; void RadixSort(SequenList &L); void BubbleSort(SequenList &S); void QuickSort(SequenList &L); void HeapSort(SequenList &H); void main() SequenList k; k.length=1; int choice; fstream in(E:abd.txt,ios:in); while (!in.eof() ink.rk.length.numk.rk.length.namek.rk.length.pricek.rk.length.countk.rk.length.sale; k.length+; in.close(); cout此系统有如下功能endl; cout * endl; cout 1、按药品编号排序endl; cout 2、按药品单价排序endl; 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 1 页,共 6 页 - - - - - - - - - cout 3、按药品销售量排序endl; cout 4、按药品销售额排序endl; cout 0、推出系统endl; cout * endl; cout请输入您的选择:choice; while (choice) switch(choice) case 1:RadixSort(k);break;/ 基数排序case 2:BubbleSort(k);break;/ 冒泡排序case 3:QuickSort(k);break;/ 快速排序case 4:HeapSort(k);break;/ 堆排序default:cout 没有您选择的功能,请确定后重新输入。endl; cout * endl; cout 1、按药品编号排序endl; cout 2、按药品单价排序endl; cout 3、按药品销售量排序endl; cout 4、按药品销售额排序endl; cout 0、推出系统endl; cout * endl; cout请输入您的选择:choice; * RadixSort.cpp 药品编号基数排序* #include drug.h #include using namespace std; void Distribute(DataType *r,int i,int *f,int *e) int j,p; for (j=0;j0) 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 2 页,共 6 页 - - - - - - - - - j=rp.numi-0; if(!fj) fj=p; else rej.next=p; ej=p; /if(m=7) break; else j=rp.numi-A; if(!fj) fj=p; else rej.next=p; ej=p; void Collect(DataType *r,int i,int *f,int *e) int j,t; for(j=0;!fj;j+); r0.next=fj; t=ej; while (j26) for(j=j+1;j25&!fj;+j); if (fj) rt.next=fj; t=ej; rt.next=0; void RadixSort(SequenList &L)/ int f27,e26; int i; for(i=0;i=0;i-) Distribute(L.r,i,f,e); 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 3 页,共 6 页 - - - - - - - - - Collect(L.r,i,f,e); cout按药品编号排序后的结果是:endl; i=L.r0.next; while(i) coutL.ri.numtL.ri.name tL.ri.pricetL.ri.counttL.ri.saleendl; i=L.ri.next; * BubbleSort.cpp 冒泡排序* #include drug.h #include using namespace std; void BubbleSort(SequenList &L) int i,j; DataType temp; for(i=0;iL.length-1;i+) for (j=1;jL.rj+1.price) temp=L.rj; L.rj=L.rj+1; L.rj+1=temp; cout按单价排序后的结果是:endl; for (i=1;iL.length;i+) coutL.ri.numtL.ri.name tL.ri.pricetL.ri.counttL.ri.saleendl; * QuickSort.cpp 快速排序* #include drug.h #include using namespace std; 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 4 页,共 6 页 - - - - - - - - - int Partition(SequenList &L,int low,int high) int pri; L.r0=L.rlow; pri=L.rlow.count; while (lowhigh) while (low=pri) -high; L.rlow=L.rhigh; while(lowhigh&L.rlow.count=pri) +low;L.rhigh=L.rlow; L.rlow=L.r0; return low; void Qsort(SequenList &L,int low,int high) int p; if(lowhigh) p=Partition(L,low,high); Qsort(L,low,p-1); Qsort(L,p+1,high); void QuickSort(SequenList &L) Qsort(L,1,L.length-1); cout按销售量排序后的结果是:endl; for(int i=1;iL.length;i+) coutL.ri.numtL.ri.name tL.ri.pricetL.ri.counttL.ri.saleendl; * HeapSort.cpp 堆排序* #include #include drug.h using namespace std; void HeadAdjust(SequenList &H,int s,int m) int j; 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 5 页,共 6 页 - - - - - - - - - DataType rc=H.rs; for (j=2*s;j=m;j*=2) if(jm&H.rj.saleH.rj.sale) break; H.rs=H.rj; s=j; H.rs=rc; void HeapSort(SequenList &H) DataType temp; int i; for(i=(H.length-1)/2;i0;-i) HeadAdjust(H,i,H.length-1); for(i=H.length-1;i1;-i) temp=H.r1; H.r1=H.ri; H.ri=temp; HeadAdjust(H,1,i-1); cout按销售额排序后的结果是:endl; for(int i=1;iH.length;i+) coutH.ri.numtH.ri.name tH.ri.pricetH.ri.counttH.ri.saleendl; * abd.txt A234 安乃近0.32 100 32.5 B123 阿莫西林0.5 50 60.5 C455 银翘片0.43 20 60.3 D345 金银花0.12 30 50.4 S342 青霉素0.34 10 20.7 D432 诺氟沙星0.64 80 23.5 F872 罗红霉素1.5 35 100.34 J234 吗叮啉0.58 63 96.6 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 6 页,共 6 页 - - - - - - - - -