药品管理系统源代码


#include
#include
using namespace std;

#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;
//药品编号基数排序

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)
{
j=r[p].num[i]-'0';
if(!f[j]) f[j]=p;
else r[e[j]].next=p;
e[j]=p;

}
else
{
j=r[p].num[i]-'A';
if(!f[j]) f[j]=p;
else r[e[j]].next=p;
e[j]=p;
}

}
}
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;iL.r[i].next=i+1;
L.r[L.length-1].next=0;
for (i=3;i>=0;i--)
{
Distribute(L.r,i,f,e);
Collect(L.r,i,f,e);
}
cout<<"按药品编号排序后的结果是:"<i=L.r[0].next;
while(i)
{
cout<i=L.r[i].next;
}
}
//冒泡排序

void BubbleSort(SequenList &L)
{
int i,j;
DataType temp;
for(i=0;ifor (j=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<<"按单价排序后的结果是:"<for (i=1;i{
cout<}
}
//快速排序


int Partition(SequenList &L,int low,int high)
{
int pri;
L.r[0]=L.r[low];
pri=L.r[low].count;
while (low{
while (low=pri) --high;
L.r[low]=L.r[high];
while(lowL.r[high]=L.r[low];
}
L.r[low]=L.r[0];
return low;
}
void Qsort(SequenList &L,int low,int high)
{
int p;
if(low{
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<<"按销售量排序后的结果是:"<for(int i=1;i{
cout<}
}
//堆排序


void HeadAdjust(SequenList &H,int s,int m)
{
int j;
DataType rc=H.r[s];
for (j=2*s;j<=m;j*=2)
{
if(jif(rc.sale>H.r[j].sale) break;
H.r[s]=H.r[j];
s=j;
}
H.r[s]=rc;
}
void HeapSort(SequenList &H)
{
DataType temp;
int i;
for(i=(H.length-1)/2;i>0;--i)
HeadAdjust(H,i,H.length-1)

;
for(i=H.length-1;i>1;--i)
{
temp=H.r[1];
H.r[1]=H.r[i];
H.r[i]=temp;
HeadAdjust(H,1,i-1);
}
cout<<"按销售额排序后的结果是:"<for( i=1;i{
cout<}
}



void main()
{
SequenList k;
k.length=1;
int choice;
fstream in("yaopin.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.length].sale;
k.length++;
}
in.close();


cout<<"1、按药品编号排序 "<cout<<"2、按药品单价排序 "<cout<<"3、按药品销售量排序 "<cout<<"4、按药品销售额排序 "<cout<<"0、退出系统 "<
cout<<"请输入编号:"<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<<"没有您选择的功能,请重新输入。"<}

cout<<"1、按药品编号排序 "<cout<<"2、按药品单价排序 "<cout<<"3、按药品销售量排序 "<cout<<"4、按药品销售额排序 "<cout<<"0、退出系统 "<
cout<<"请输入您的选择:"<cin>>choice;
}
}

相关文档
最新文档