搜档网
当前位置:搜档网 › 产品进销存管理系统 代码

产品进销存管理系统 代码

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define ok 1
#define error 0
#define overflow 0
#define SQMOUNTLINK_INIT_SIZE 100
#define SQMOUNTLINKINCREMENT 10
typedef struct date{
int year;
int month;
int day;
}date; //日期
typedef struct productlnode{
char pname[30]; //产品名称
int totalquantity; //产品总量
date goodsdate; //进货日期
int salesquantity; //消除数量
date salestime; //销售时间
struct productlnode *nextproduct;
}productlnode,*plinklist;
typedef struct kindlnode{
productlnode *firstproduct;
char pkindname[30];
}kindlnode;
typedef struct{
kindlnode *kindelem;
int length;
int listsize;
}sqmountlink;
int InitMountList(sqmountlink &L){
//初始化一个空的顺序表挂接链表L
int i;
L.kindelem=(kindlnode*)malloc(SQMOUNTLINK_INIT_SIZE*sizeof(kindlnode));
if(!L.kindelem) exit(overflow);
L.length=0;
L.listsize=SQMOUNTLINK_INIT_SIZE;
for(i=0;i<L.listsize;i++){
(L.kindelem[i]).firstproduct=NULL;
}
return ok;
}//InitMountList

int KindInsert(sqmountlink &L,int n){ //向顺序表挂接链表L中添加N类产品
int i;
kindlnode *newbase;
if(L.length+n>=L.listsize){
newbase=(kindlnode*)realloc(L.kindelem,(L.listsize+n)*sizeof(kindlnode));
if(!newbase) exit(overflow);
L.kindelem=newbase;
L.listsize+=n;
}
printf("需添加的产品类名称:\n");
for(i=0;i<n;i++){
scanf("%s",&L.kindelem[L.length].pkindname);
L.kindelem[L.length].firstproduct=NULL;
L.length++;
}
return ok;
}//KindInsert
int ProductInsert(sqmountlink &L,char pkindname2[],int n){ //向顺序表挂接链表L的某产品类中添加N个产品
plinklist p,q;
int k,j;
for(k=0;k<L.length;k++){
if(strcmp((L.kindelem[k]).pkindname,pkindname2)!=0)
continue;
else
break;
}
if(L.kindelem[k].firstproduct==NULL){
q=(plinklist)malloc(sizeof(productlnode));
printf("输入此产品类所含产品的产品名称、总量、进货日期、销售数量、销售时间:\n");
scanf("%s %d %d,%d,%d %d %d,%d,%d",&(q->pname),&(q->totalquantity),&((q->goodsdate).year),&((q->goodsdate).month),&((q->goodsdate).day),&(q->salesquantity),&((q->salestime).year),&((q->salestime).month),&((q->salestime).day));
q->nextproduct=NULL;
(L.kindelem[k]).firstproduct=q;
for(j=1;j<n;j++){
p=(plinklist)malloc(sizeof(productlnode));
printf("输入此产品类所含产品的产品名称、总量、进货日期、销售数量、销售时间:\n");\
scanf("%s %d %d,%d,%d %d %d,%d,%d",&(p->pname),&(p->totalquantity),&((p->goodsdate).year),&((p->goodsdate).month),&((p->goodsdate).day),&(p->salesquantity),&((p->salestime).year),&((p->salestime).month),&((p->salestime).day));
p->nextproduct=q->next

product;
q->nextproduct=p
;
q=p;
}
}
else{
for(q=L.kindelem[k].firstproduct; ;q=q->nextproduct){
if(!(q->nextproduct))
break;
}
printf("需添加产品的名称、总量、进货日期、销售数量、销售时间:\n");
for(j=0;j<n;j++){
p=(plinklist)malloc(sizeof(productlnode));
scanf("%s %d %d,%d,%d %d %d,%d,%d",&(p->pname),&(p->totalquantity),&((p->goodsdate).year),&((p->goodsdate).month),&((p->goodsdate).day),&(p->salesquantity),&((p->salestime).year),&((p->salestime).month),&((p->salestime).day));
p->nextproduct=q->nextproduct;
q->nextproduct=p;
q=p;
}
}
return ok;
}//ProductInsert
void ProQuantity_add(sqmountlink &L,char pkindname1[],char pname1[],int n){ //添加顺序表挂接链表L的某产品类中的某产品的总量,且需添加的产品总量为n
int i,k;
plinklist p;
for(i=0;i<L.length;i++){
if(strcmp((L.kindelem[i]).pkindname,pkindname1)!=0)
continue;
else
break;
}
if(i<L.length){
for(p=L.kindelem[i].firstproduct;p!=NULL;p=p->nextproduct){
k=strcmp(p->pname,pname1);
if(k==0){
p->totalquantity=p->totalquantity+n;
printf("查看添加后产品的各项输出:%s %d %d,%d,%d %d %d,%d,%d\n",p->pname,p->totalquantity,(p->goodsdate).year,(p->goodsdate).month,(p->goodsdate).day,p->salesquantity,(p->salestime).year,(p->salestime).month,(p->salestime).day);
}
}
}
}//ProQuantity_add
void ProQuantity_subtract(sqmountlink &L,char pkindname4[],char pname4[],int n){ //添加顺序表挂接链表L的某产品类中的某产品销出数量,且销出的数量n
int i,k;
plinklist p;
for(i=0;i<L.length;i++){
if(strcmp((L.kindelem[i]).pkindname,pkindname4)!=0)
continue;
else
break;
}
if(i<L.length){
for(p=L.kindelem[i].firstproduct;p!=NULL;p=p->nextproduct){
k=strcmp(p->pname,pname4);
if(k==0){
p->salesquantity=p->salesquantity+n;
printf("查看添加后产品的各项输出:%s %d %d,%d,%d %d %d,%d,%d\n",p->pname,p->totalquantity,(p->goodsdate).year,(p->goodsdate).month,(p->goodsdate).day,p->salesquantity,(p->salestime).year,(p->salestime).month,(p->salestime).day);
}
}
}
}//ProQuantity_subtract
void Visit(sqmountlink &L,char pkindname3[],char pname3[]){ //在顺序表挂接链表L中,查询属于某产品类的某产品的各项信息
int i,k;
plinklist p;
for(i=0;i<L.length;i++){
if(strcmp((L.kindelem[i]).pkindname,pkindname3)!=0)
continue;
else
break;
}
if(i<L.length){
for(p=L.kindelem[i].firstproduct;p!=NULL;p=p->nextproduct){
k=strcmp(p->pname,pname3);
if(k==0)
break;
}
if(k!=0)
printf("此产品不存在:\n");
else{

printf("输出待查询产品的各项信息:\n");
printf(&quo

t;产品类★产 品★产品总量★进 货 日 期★销售数量★销 售 时 间\n");
printf("%s %s %d %d,%d,%d %d %d,%d,%d\n",(L.kindelem[i]).pkindname,p->pname,p->totalquantity,(p->goodsdate).year,(p->goodsdate).month,(p->goodsdate).day,p->salesquantity,(p->salestime).year,(p->salestime).month,(p->salestime).day);
}
}
}//Visit
void DisplayList(sqmountlink &L){ //显示各产品所属产品类、产品名称、产品总量、进货日期、销售数量、销售时间
int i;
plinklist p;
printf("产品类★产 品★产品总量★进 货 日 期★销售数量★销 售 时 间\n");
for(i=0;i<L.length;i++){
if(!(L.kindelem[i].firstproduct))
printf("%s\n",(L.kindelem[i]).pkindname);
for(p=L.kindelem[i].firstproduct;p;p=p->nextproduct)
printf("%s %s %d %d,%d,%d %d %d,%d,%d\n",(L.kindelem[i]).pkindname,p->pname,p->totalquantity,(p->goodsdate).year,(p->goodsdate).month,(p->goodsdate).day,p->salesquantity,(p->salestime).year,(p->salestime).month,(p->salestime).day);
}
}//DisplayList

void menu_operation(){//操作菜单
printf("┌──────────┐\n");
printf("│输入所要执行的操作:│\n");
printf("│1、产品类添加: │\n");
printf("│2、产品添加: │\n");
printf("│3、产品数量添加: │\n");
printf("│4、产品售出: │\n");
printf("│5、查询产品: │\n");
printf("│0、退出程序: │\n");
printf("└──────────┘\n");
}//mene_operation
/*------------------------------主程序---------------------------*/
void main(void){
int order;
int i,n;
char a[30];
char b[30];
sqmountlink L;
InitMountList(L);
printf("☆输入时间时请按照“年,月,日”格式输入.☆\n");
loop:
menu_operation();
printf("输入命令:");
scanf("%d",&order);
switch(order){
case 1:
printf("需添加产品类的个数:");
scanf("%d",&i);
KindInsert(L,i);
printf("修改后的产品库存管理表:\n");
DisplayList(L);
goto loop;
case 2:
printf("需添加产品所属产品类的名称:");
scanf("%s",&a);
printf("需向此产品类添加产品的个数:");
scanf("%d",&i);
ProductInsert(L,a,i);
printf("修改后的产品库存管理表:\n");
DisplayList(L);
goto loop;
case 3:
printf("输入需添加数量的产品所属产品类的名称:");
scanf("%s",&a);
printf("输入需添加数量的产品的名称:");
scanf("%s",&b);
printf("输入需添加产品的数量:");
scanf("%d",&n);
ProQuantity_add(L,a,b,n);
printf("修改后的产

品库存管理表:\n");
DisplayList(L);
goto loop;
case 4:
printf("输入售出产品所属产品类的名称:");
scanf("%s",&a);
printf("输入售出产品的名称:");
scanf("%s",&b);
printf("输入售出产品的数量:");
scanf("%d",&n);
ProQuantity_subtract(L,a,b,n);
printf("修改后的产品库存管理表:\n");
DisplayList(L);
goto loop;
case 5:
printf("输入待查询产品所属产品类的名称:");
scanf("%s",&a);
printf("输入待查询产品的名称:");
scanf("%s",&b);
Visit(L,a,b);
goto loop;
case 0:
exit(0);
}
}

相关主题