药店的药品销售统计系统
时间:2025-04-13
时间:2025-04-13
头文件 drug.h
#define MaxSize 50
typedef struct node
{
char num[8]; /*药品编号*/
char name[16]; /*药品名称*/ float price; /*药品单价*/ int count; /*销售数量*/ float sale; /*本药品销售额*/ int next;
}DataType;
typedef struct
{
DataType r[MaxSize];
int length;
}SequenList;
****************************************** main.cpp
#include "drug.h"
#include <iostream>
#include <fstream>
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()) { in>>k.r[k.length].num>>k.r[k.length].name>>k.r[k.length].price>>k.r[k.length].count>>k.r[k.l } k.length++; ength].sale; in.close(); cout<<"此系统有如下功能"<<endl; cout<<" ************************** "<<endl; cout<<" 1、按药品编号排序 "<<endl; cout<<" 2、按药品单价排序 "<<endl;
} cout<<" 4、按药品销售额排序 "<<endl; cout<<" 0、推出系统 "<<endl; cout<<" ************************** "<<endl; cout<<"请输入您的选择:"<<endl; cin>>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<<"请输入您的选择:"<<endl; cin>>choice;
******************************************
RadixSort.cpp药品编号基数排序
****************************************** #include "drug.h"
#include <iostream>
using namespace std;
void Distribute(DataType *r,int i,int *f,int *e)
{
int j,p; for (j=0;j<=26;j++) f[j]=0; for (p=r[0].next;p;p=r[p].next) { if(i>0)
} } else { } j=r[p].num[i]-'A'; if(!f[j]) f[j]=p; else r[e[j]].next=p; e[j]=p; j=r[p].num[i]-'0'; if(!f[j]) f[j]=p; else r[e[j]].next=p; e[j]=p; //if(m==7) break;
}
void Collect(DataType *r,int i,int *f,int *e)
{
} int j,t; for(j=0;!f[j];j++); r[0].next=f[j]; t=e[j]; while (j<26) { } for(j=j+1;j<25&&!f[j];++j); if (f[j]) { } r[t].next=f[j]; t=e[j]; r[t].next=0;
void RadixSort(SequenList &L)//
{
int f[27],e[26]; int i; for(i=0;i<L.length-1;i++) L.r[i].next=i+1; L.r[L.length-1].next=0; for (i=3;i>=0;i--) { Distribute(L.r,i,f,e);
} cout<<"按药品编号排序后的结果是:"<<endl; i=L.r[0].next; while(i) { cout<<L.r[i].num<<'\t'<<L.r[i].name<<"
\t"<<L.r[i].price<<'\t'<<L.r[i].count<<'\t'<<L.r[i].sale<<endl; i=L.r[i].next;
}
****************************************** BubbleSort.cpp 冒泡排序
****************************************** #include "drug.h"
#include <iostream>
using namespace std;
void BubbleSort(SequenList &L)
{
int i,j; DataType temp; for(i=0;i<L.length-1;i++) for (j=1;j<L.length-i-1;j++) { if (L.r[j].price>L.r[j+1].price) { } temp=L.r[j]; L.r[j]=L.r[j+1]; L.r[j+1]=temp; }
}
cout<<"按单价排序后的结果是:"<<endl;
for (i=1;i<L.length;i++) {
cout<<L.r[i].num<<'\t'<<L.r[i].name<<"
\t"<<L.r[i].price<<'\t'<<L.r[i].count<<'\t'<<L.r[i].sale<<endl; }
}
****************************************** QuickSort.cpp快速排序
****************************************** #include "drug.h"
#include <iostream>
using namespace std;
int Partition(SequenList &L,int low,int high)
{
int pri; L.r[0]=L.r[low]; pri=L.r[low].count; while (low<high) { } L.r[low]=L.r[0]; return low; while (low<high&&L.r[high].count>=pri) --high; L.r[low]=L.r[high]; while(low<high&&L.r[low].count<=pri) ++low; L.r[high]=L.r[low];
}
void Qsort(SequenList &L,int low,int high)
{
} int p; if(low<high) { } 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;i<L.length;i++) { cout<<L.r[i].num<<'\t'<<L.r[i].name<<"
上一篇:第一章 国际贸易导论