超市管理系统C语言程序代码

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。


#include
#include

struct arraysGoods
{
int goods_id; //商品编号
char goods_name[50]; //商品名称
char goods_address[50]; //商品产地
char goods_type[50]; //商品种类
float goods_inputprice; //商品进价
float goods_outputprice; //商品售价
int goods_num; //商品进货量
};
struct arraysGoods GoodsDates[50]={ {2013,"衬衫","北京","c",1.4,2.5,5},{2012,"裤子","上海","b",1.3,2.5,6}, {2011,"短袖","大连","a",1.1,2.5,7}};
struct arraysGoods GoodsDates2[50];

void loginTitle();
void loginManager();
void selectManagerMenu();
void spendPassager();
void spendPassagerMenu();
int tuichuMenu();
void insertGoods();
void printManagerGoods();
void printspendGoods();
void deleteGoods();
void genxinGoods();
void addGoods();
void tongjiMenu();
void chaxunmol();
void paixumol();
void lirunpai();
void kucunpai();
void shuliangMenu();
void xiugaiGoods();
void thetype();
void goods_num();
void goods_type();
void goods_name();
void spendpaixumol();
void spendchaxunmol();
void spendlirunpai();
void spendkucunpai();
void spendgoods_num();
void spendgoods_type();
void spendgoods_name();


void main()
{
loginTitle();//调用登录界面
}

/*登录界面*/
void loginTitle()
{
int numOperator;//操作编号

int flag1 = 1;//循环标志位
/*循环登录界面*/

/*进入系统主界面*/
printf("\n\n\n");
printf(" *************************************** \n");
printf(" ***************************************** \n");
printf(" ** ***** * * ** \n");
printf(" ** * ** * * * * ** \n");
printf(" ** *** * * * * ** \n");
printf(" ** ** * * * * ** \n");
printf(" ** ***** ** * ** ** \n");
printf(" ***************************************** \n");
printf(" *************************************** \n");
printf("\n\n");

printf("\t\t 欢迎使用 SM 超市商品管理系统!(*^__^*) \n");
printf("\n");

do
{
printf("\t\t\t\t1.管理者系统\n\t\t\t\t2.消费者系统\n\t\t\t\t3.退出系统\n");
printf("\n \t \t \t 请输入相应操作编号: ");
scanf("%d",&numOperator);
/*第三步:判断选择登录界面*/
switch(numOperator)
{
case 1:
printf("\n********************************************************************************");
printf(" \t \t \t 《欢迎进入管理者系统!》\n");
loginManager();
break;
case 2:
printf("\n**********************************************

**********************************");
printf(" \t \t \t 《欢迎进入消费者系统!》\n");
spendPassager();
break;
case 3:
tuichuMenu();
flag1=0;
break;
default:
printf("\n\t\t\t>>> 输入操作编号无效,请重新输入!<<<\n\n");
}
/*第四步:判断是否退出系统,如果为真,退出*/
if(flag1 ==0)
{
break;
}
}while(flag1);
}


/*退出系统界面*/
int tuichuMenu()
{
int flag;
printf(" \t \t ***************************************\n");
printf(" \t \t ***感谢您本次的使用,再见!O(∩_∩)O***\n");
printf(" \t \t ***************************************\n");
flag=0;
return flag;
}



/*管理者系统密码管理界面*/
void loginManager()
{
char strname[20];//输入的用户名
char stroldname[20]="1";//原用户名
char strpassword[20];//输入的密码
char stroldpassword[20]="1";//原密码
/*第一步:获取用户名*/
printf("\t\t\t\t请输入用户名: ");
scanf("%s",&strname);
/*第二步:获取密码*/
printf("\t\t\t\t请输入密码: ");
scanf("%s",&strpassword);
/*第三步:比对用户名,密码是否正确,如果返回值为0,相等,登录成功。否则登录失败,返回登录界面*/
if((strcmp(strname,stroldname)==0) && (strcmp(strpassword,stroldpassword)==0))
{
/*第四步:调用管理者系统菜单界面*/
printf("\n\t\t\t\t>>> 登录成功!<<<\n\n");
selectManagerMenu();
}
else
{
/*第四步:调用登录界面*/
printf("\n\t\t\t\t>>> 登录失败!请重新登录!<<<");
loginTitle();
}
}


/*管理者系统菜单界面*/
void selectManagerMenu()
{
int numOperator;//操作编号

int flag = 1;//循环标志位
/*循环登录界面*/
do
{
/*第一步:输出菜单标题*/
printf(" \t\t\t\t 1.录入信息\n \t\t\t\t 2.输出信息\n \t\t\t\t 3.更新模块\n \t\t\t\t 4.统计模块\n \t\t\t\t 5.排序模块\n \t\t\t\t 6.查询模块\n \t\t\t\t 7.退出系统\n");
/*第二步:获取操作编号*/
printf("\t\t\t\t请输入操作编号: ");
scanf("%d",&numOperator);
/*第三步:判断选择菜单*/
switch(numOperator)
{
case 1:
printf("\n\t\t\t\t《请录入商品信息》\n");
insertGoods();
break;
case 2:
printf("\n\t\t\t\t《输出商品信息》\n\n");
printManagerGoods();
break;
case 3:
printf("\n\t\t\t\t《进入更新模块》\n\n");
genxinGoods();
break;
case 4:
printf("\n\t\t\t\t《进入统计模块》\n\n");
tongjiMenu();
break;
case 5:
printf("\n\t\t\t\t《进入排序模块》\n\n");
paixumol();
break;
case 6:
printf("\n\t\t\t\t《进入查询模块》\n\n");
chaxunmol();
break;
case 7:
tuichuMenu();
flag = 0;
break;
default:
printf("\n \t \t \t>>> 输入操作编号无效,请重新输入!<<<\n\n");

}

if(flag == 0 )
{
break;
}

}while(flag);
}



/*消费者系统密码管理界面*/
void spendPassager()
{
char strname[20];//输入的用户名
char stroldname[20]="2";//原用户名
char strpassword[20];//输入的密码
char stroldpassword[20]="2";//原密码
/*第一步:获取用户名*/
printf("\t\t\t\t请输入用户名:");
scanf("%s",&strname);
/*第二步:获取密码*/
printf("\t\t\t\t请输入密码:");
scanf("%s",&strpassword);
/*第三步:比对用户名,密码是否正确,如果返回值为0,相等,登录成功。否则登录失败,返回登录界面*/
if( (strcmp(strname,stroldname)==0) && (strcmp(strpassword,stroldpassword)==0) )
{
/*第四步:调用管理者系统菜单界面*/
printf("\n\t\t\t\t>>> 登录成功!<<<\n");
spendPassagerMenu();
}
else
{
/*第四步:调用登录界面*/
printf("\n\t\t\t\t>>> 登录失败!请重新登录!<<<\n");
loginTitle(); //返回系统进入界面。
}


}



/*消费者系统菜单界面*/
void spendPassagerMenu()
{
int numOperator;//操作编号
int flag = 1;//循环标志位
/*循环登录界面*/
do
{
/*第一步:输出菜单标题*/
printf(" \n\t\t\t\t 1.排序模块\n\t\t\t\t 2.查询模块\n \t\t\t\t 3.退出系统\n");
/*第二步:获取操作编号*/
printf("\t\t\t\t请输入操作编号: ");
scanf("%d",&numOperator);
/*第三步:判断选择菜单*/
switch(numOperator)
{
case 1:
printf("\n \t \t \t \t 《进入排序模块》\n\n");
spendpaixumol();
break;
case 2:
printf("\n \t \t \t \t 《进入查询模块》\n\n");
spendchaxunmol();
break;
case 3:
tuichuMenu();
flag=0;
break;
default:
printf("\n\t\t\t>>> 输入操作编号无效,请重新输入!<<<\n\n");
}

if(flag==0)
{
break;
}

}while(flag);
}



/*录入商品信息*/
void insertGoods()
{
int i;
int check;
for(i=3;i<50;i++)
{
printf("\t\t\t\t请输入商品编号:");
scanf("%d",&GoodsDates[i].goods_id);
printf("\t\t\t\t请输入商品名称:");
scanf("%s",&GoodsDates[i].goods_name);
printf("\t\t\t\t请输入商品产地:");
scanf("%s",&GoodsDates[i].goods_address);
printf("\t\t\t\t请输入商品种类:");
scanf("%s",&GoodsDates[i].goods_type);
printf("\t\t\t\t请输入商品进价:");
scanf("%f",&GoodsDates[i].goods_inputprice);
printf("\t\t\t\t请输入商品单价:");
scanf("%f",&GoodsDates[i].goods_outputprice);
printf("\t\t\t\t请输入商品数量:");
scanf("%d",&GoodsDates[i].goods_num);

printf("\t\t\t\t继续录入选“1”,返回选“0”:");
scanf("%d",&check);

if(check != 1)
{
break;
}

}

printManagerGoods();
}



/*输出商品信息*/
void printManagerGoods()
{
int i,t;

printf("\t\t编号 \t名称 \t类别 \t产地 \t进价 \t单价 \t数量\n");
for(i=0;i<50

;i++)
{
if( GoodsDates[i].goods_id==0 )
{
continue;
}
printf(" \t \t %d \t %s \t %s \t %s \t %-5.2f \t %-5.2f \t %d\n",GoodsDates[i].goods_id,GoodsDates[i].goods_name,GoodsDates[i].goods_address,GoodsDates[i].goods_type,GoodsDates[i].goods_inputprice,GoodsDates[i].goods_outputprice,GoodsDates[i].goods_num);
}

printf("\n\t\t\t\t返回管理者菜单选“0”: ");
scanf("%d",&t);
switch(t)
{
default:selectManagerMenu();
}


}



/*更新商品信息模块*/
void genxinGoods()
{
int flag=1;
int numOperator;//操作编号
do
{
/*第一步:输出菜单标题*/
printf("\n \t\t\t\t 1.修改商品信息\n \t\t\t\t 2.删除商品信息\n \t\t\t\t 3.添加商品信息\n \t\t\t\t 4.返回管理者菜单\n");
/*第二步:获取操作编号*/
printf(" \t\t\t\t 请输入操作编号: ");
scanf("%d",&numOperator);
/*第三步:判断选择菜单*/
switch(numOperator)
{
case 1:
printf("\n\t\t\t\t《进入修改商品信息》\n\n");
xiugaiGoods();
break;
case 2:
printf("\n\t\t\t\t《进入删除商品信息》\n\n");
deleteGoods();
break;
case 3:
printf("\n\t\t\t\t《进入添加商品信息》\n\n");
addGoods();
break;
case 4:
printf("\n\t\t\t\t《管理者菜单》\n");
selectManagerMenu();
flag=0;
break;
default:
printf("\n\t\t\t>>> 输入操作编号无效,请重新输入!<<<\n \n");
}

if(flag=0)
{
break;
}
}while(flag);

}



/*删除商品信息*/
void deleteGoods()
{
int i;
int searchgoods_id;
int t;
printf(" \t\t\t\t 请输入要删除的商品编号: ");
scanf("%d",&searchgoods_id);
for(i=0;i<50;i++)
{
if( GoodsDates[i].goods_id == searchgoods_id )
{
//输出该商品信息
printf("\t\t编号\t名称\t类别\t产地\t进价\t单价\t数量\n");
printf("\t\t%d\t%s\t%s\t%s\t%-5.2f\t%-5.2f\t%d\n",GoodsDates[i].goods_id,GoodsDates[i].goods_name,GoodsDates[i].goods_address,GoodsDates[i].goods_type,GoodsDates[i].goods_inputprice,GoodsDates[i].goods_outputprice,GoodsDates[i].goods_num);

//删除所选商品信息
printf("\n \t \t \t !!警告:数据删除后不可修复!是否继续?\n");
printf("\n\t\t\t\t继续请选“1”,取消请选“0”: ");
scanf("%d",&t);
if( t== 1 )
{
//清空所有数据
GoodsDates[i].goods_id =0;
strcpy(GoodsDates[i].goods_name ,"\0");
strcpy(GoodsDates[i].goods_address,"\0");
strcpy(GoodsDates[i].goods_type,"\0");
GoodsDates[i].goods_inputprice= 0;
GoodsDates[i].goods_outputprice= 0;
GoodsDates[i].goods_num= 0;
}

}
}
printf("\n\t\t\t\t>>删除成功,返回管理者界面<<\n\n");
selectManagerMenu();
}






/*修改商品信息*/
void xiugaiGoods()
{
int searchgoods_id;
int i;
printf(" \t\t\t\t 请输入要修改的商品编号: ");
scanf("%d",&searchgood

s_id);

for(i=0;i<50;i++)
{
if( GoodsDates[i].goods_id == searchgoods_id )
{
//输出该商品信息
printf("\t\t编号\t名称\t类别\t产地\t进价\t单价\t数量\n");
printf(" \t\t%d \t%s \t%s \t%s \t% -5.2f\t% -5.2f\t %d\n",GoodsDates[i].goods_id,GoodsDates[i].goods_name,GoodsDates[i].goods_address,GoodsDates[i].goods_type,GoodsDates[i].goods_inputprice,GoodsDates[i].goods_outputprice,GoodsDates[i].goods_num);

//修改该商品信息
printf(" \t\t\t\t 请输入修改后的商品编号: ");
scanf("%d",&GoodsDates[i].goods_id);
printf(" \t\t\t\t 请输入修改后的商品名称: ");
scanf("%s",&GoodsDates[i].goods_name);
printf(" \t\t\t\t 请输入修改后的商品产地: ");
scanf("%s",&GoodsDates[i].goods_address);
printf(" \t\t\t\t 请输入修改后的商品种类: ");
scanf("%s",&GoodsDates[i].goods_type);
printf(" \t\t\t\t 请输入修改后的商品进价: ");
scanf("%f",&GoodsDates[i].goods_inputprice);
printf(" \t\t\t\t 请输入修改后的商品售价: ");
scanf("%f",&GoodsDates[i].goods_outputprice);
printf(" \t\t\t\t 请输入修改后的商品数量: ");
scanf("%d",&GoodsDates[i].goods_num);

printf("\t\t编号\t名称\t类别\t产地\t进价\t单价\t数量\n");
printf(" \t\t%d \t%s \t%s \t%s \t% -5.2f\t% -5.2f\t %d\n",GoodsDates[i].goods_id,GoodsDates[i].goods_name,GoodsDates[i].goods_address,GoodsDates[i].goods_type,GoodsDates[i].goods_inputprice,GoodsDates[i].goods_outputprice,GoodsDates[i].goods_num);
}
}
printf("\n\t\t\t\t《返回更新模块》\n\n");
genxinGoods();
}




/*添加商品信息*/
void addGoods()
{
int i,j;
int check;
for(i=3;i<50;i++)
{
printf("\n\t\t\t\t 请输入商品编号: ");
scanf("%d",&GoodsDates[i].goods_id);
printf("\t\t\t\t 请输入商品名称: ");
scanf("%s",&GoodsDates[i].goods_name);
printf("\t\t\t\t 请输入商品产地地址: ");
scanf("%s",&GoodsDates[i].goods_address);
printf("\t\t\t\t 请输入商品种类: ");
scanf("%s",&GoodsDates[i].goods_type);
printf("\t\t\t\t 请输入商品进价: ");
scanf("%f",&GoodsDates[i].goods_inputprice);
printf("\t\t\t\t 请输入商品售价: ");
scanf("%f",&GoodsDates[i].goods_outputprice);
printf("\t\t\t\t 请输入商品数量: ");
scanf("%d",&GoodsDates[i].goods_num);

printf("\t\t\t\t 继续录入选“1”,返回选“0”: ");
scanf("%d",&check);
if( check != 1)
{
break;
}
}

printf("\t\t编号\t品称\t类别\t产地\t进价\t单价\t数量\n");

for(j=0;j<50;j++)
{
if( GoodsDates[j].goods_id==0 )
{
continue;
}
printf("\t\t%d\t%s\t%s\t%s\t%-5.2f\t%-5.2f\t%d\n",GoodsDates[j].goods_id,GoodsDates[j].goods_name,GoodsDates[j].goods_address,GoodsDates[j].goods_type,GoodsDates[j].goods_inputprice,GoodsDates[j].goods_outputprice,GoodsDates[j].goods_num);
}


printf("\t\t\t\t 返回上一级选“0

”: ");
genxinGoods();

}




/*统计模块*/
void tongjiMenu()
{
int numOperator;
printf("\t\t\t\t 1.第一类商品\n");
printf("\t\t\t\t 2.第二类商品\n");
printf("\t\t\t\t 3.第三类商品\n");
printf("\t\t\t\t 4.返回首页\n");

printf("\t\t\t\t 请输入相应操作编号: ");
scanf("%d",&numOperator);
switch(numOperator)
{
case 1 :thetype();
break;
case 2 :thetype();
break;
case 3 :thetype();
break;
case 4 :selectManagerMenu();
break;
default:printf("\n\t\t\t>>> 输入错误,系统自动返回!<<<\n\n");
}

}

void thetype()
{
char type[20];
int t;
int i;
printf("\n\t\t\t\t 请输入需要查询的商品种类: ");
scanf("%s",&type);

printf("\n\t\t种类\t编号\t名称\t产地\t进价\t单价\t数量\n");
for(i=0;i<50;i++)
{
if( strcmp(GoodsDates[i].goods_type,type)!=0 )
{
continue;
}
printf("\t\t%s\t%d\t%s\t%s\t%-5.2f\t%-5.2f\t%d \n",GoodsDates[i].goods_type,GoodsDates[i].goods_id,GoodsDates[i].goods_name,GoodsDates[i].goods_address,GoodsDates[i].goods_inputprice,GoodsDates[i].goods_outputprice,GoodsDates[i].goods_num);
}
printf("\t\t\t\t 返回请选“1”: ");
scanf("%d",&t);
if(t) selectManagerMenu();
else printf("\n\t\t\t>>> 输入错误,系统自动返回!<<<\n\n");

}





/*查询模块*/
void chaxunmol()
{
int numOperator;
printf("\t\t\t\t1.按进货量查询\n");
printf("\t\t\t\t2.按商品种类查询\n");
printf("\t\t\t\t3.按商品名称查询\n");
printf("\t\t\t\t4.返回首页\n");

printf("\t\t\t\t请输入相应操作编号: ");
scanf("%d",&numOperator);
switch(numOperator)
{
case 1 :goods_num();
break;
case 2 :goods_type();
break;
case 3 :goods_name();
break;
case 4 :selectManagerMenu();
break;
default:printf("\n\t\t\t>>> 输入错误,系统自动返回!<<<\n\n");
}
}


/*按进货量查询*/
void goods_num()
{
int num;
int i,t;
printf("\t\t\t\t请输入需要查询的商品进货量: ");
scanf("%d",&num);

printf("\n\t\t进货量\t种类\t编号\t名称\t产地\t进价\t单价\n");
for(i=0;i<50;i++)
{
if( GoodsDates[i].goods_num!=num )
{
continue;
}
printf("\t\t%d\t%s\t%d\t%s\t%s\t%-5.2f\t%-5.2f\n",GoodsDates[i].goods_num,GoodsDates[i].goods_type,GoodsDates[i].goods_id,GoodsDates[i].goods_name,GoodsDates[i].goods_address,GoodsDates[i].goods_inputprice,GoodsDates[i].goods_outputprice);
}
printf("\t\t\t\t返回选“1”: ");
scanf("%d",&t);
switch(t)
{
default:selectManagerMenu();
}

}


/*按商品种类查询*/
void goods_type()
{
thetype();
}


/*按商品名称查询*/
void goods_name()
{
char name[50];
int i,t;
printf("\t\t\t\t请输入需要查询的商品名称: ");
scanf("%s",&name);

printf("\n\t\t名称\t编号\t产地\t种类\t进价\t单价\t数量\n");
for(i=0;i<50;i++)
{
if( strcmp( GoodsDates[i]

.goods_name,name ) !=0 )
{
continue;
}
printf("\t\t%s\t%d\t%s\t%s\t%-5.2f\t%-5.2f\t%d\n",GoodsDates[i].goods_name,GoodsDates[i].goods_id,GoodsDates[i].goods_address,GoodsDates[i].goods_type,GoodsDates[i].goods_inputprice,GoodsDates[i].goods_outputprice,GoodsDates[i].goods_num);
}

printf("\t\t\t\t返回选“1”: ");
scanf("%d",&t);
switch(t)
{
default:selectManagerMenu();
}


}



/*排序模块*/
void paixumol()
{
int numOperator;
printf("\t\t\t\t 1.利润排序\n");
printf("\t\t\t\t 2.库存量排序\n");
printf("\t\t\t\t 3.返回首页\n");

printf("\t\t\t\t 请输入相应操作编号: ");
scanf("%d",&numOperator);
switch(numOperator)
{
case 1 :lirunpai();
break;
case 2 :kucunpai();
break;
case 3 :selectManagerMenu();
break;
default:printf("\n\t\t\t>>> 输入错误,系统自动返回!<<<\n\n");
}
}


/*利润排行*/
void lirunpai()
{
int i=0,j,temp1,t;
char temp2[50];
float temp3;
float lirun[50]={0},temp;
printf("\n\t\t----------------------利润排行---------------------\n");

for(i;i<50; i++)
{
if( GoodsDates[i].goods_id==0 )
{
continue;
}
lirun[i]=( GoodsDates[i].goods_outputprice-GoodsDates[i].goods_inputprice )*(GoodsDates[i].goods_num);
}
for(i=0;i<49; i++)
{
for(j=49;j>i; j--)
if( lirun[j-1] < lirun[j] )
{
temp=lirun[j-1],lirun[j-1]=lirun[j],lirun[j]=temp;

temp1=GoodsDates[j-1].goods_id, GoodsDates[j-1].goods_id=GoodsDates[j].goods_id, GoodsDates[j].goods_id=temp1;
strcpy( temp2,GoodsDates[j-1].goods_name),strcpy(GoodsDates[j-1].goods_name,GoodsDates[j].goods_name), strcpy(GoodsDates[j].goods_name,temp2);
strcpy(temp2,GoodsDates[j-1].goods_address), strcpy(GoodsDates[j-1].goods_address,GoodsDates[j].goods_address), strcpy(GoodsDates[j].goods_address,temp2);
strcpy(temp2,GoodsDates[j-1].goods_type),strcpy(GoodsDates[j-1].goods_type,GoodsDates[j].goods_type), strcpy(GoodsDates[j].goods_type,temp2);
temp3=GoodsDates[j-1].goods_inputprice, GoodsDates[j-1].goods_inputprice=GoodsDates[j].goods_inputprice, GoodsDates[j].goods_inputprice=temp3;
temp3=GoodsDates[j-1].goods_outputprice, GoodsDates[j-1].goods_outputprice=GoodsDates[j].goods_outputprice, GoodsDates[j].goods_outputprice=temp3;
temp1=GoodsDates[j-1].goods_num, GoodsDates[j-1].goods_num=GoodsDates[j].goods_num, GoodsDates[j].goods_num=temp1;
}
}

printf("\t\t利润\t编号 \t名称 \t类别 \t产地 \t进价 \t单价 \t数量\n");
for(i=0;i<50;i++)
{
if( GoodsDates[i].goods_id==0 )
{
continue;
}
printf(" \t \t%-5.3f %d\t%s\t%s\t%s\t%-5.2f\t%-5.2f\t%d\n",lirun[i],GoodsDates[i].goods_id,GoodsDates[i].goods_name,GoodsDates[i].goods_address,GoodsDates[i].goods_type,GoodsDates[i].goods_inputprice,GoodsDates[i].goods_outputprice,GoodsDates[i].goods_num);
}

}



/*库存排行*/
void kucunpai()
{

int i=0,j,temp1;
char temp2[50];
float temp3;
printf("\n\t\t----------------------库存排行---------------------\n");

for(i=0;i<49; i++)
{
for(j=49;j>i; j--)
if( GoodsDates[j-1].goods_num < GoodsDates[j].goods_num )
{

temp1=GoodsDates[j-1].goods_id, GoodsDates[j-1].goods_id=GoodsDates[j].goods_id, GoodsDates[j].goods_id=temp1;
strcpy( temp2,GoodsDates[j-1].goods_name),strcpy(GoodsDates[j-1].goods_name,GoodsDates[j].goods_name), strcpy(GoodsDates[j].goods_name,temp2);
strcpy(temp2,GoodsDates[j-1].goods_address), strcpy(GoodsDates[j-1].goods_address,GoodsDates[j].goods_address), strcpy(GoodsDates[j].goods_address,temp2);
strcpy(temp2,GoodsDates[j-1].goods_type),strcpy(GoodsDates[j-1].goods_type,GoodsDates[j].goods_type), strcpy(GoodsDates[j].goods_type,temp2);
temp3=GoodsDates[j-1].goods_inputprice, GoodsDates[j-1].goods_inputprice=GoodsDates[j].goods_inputprice, GoodsDates[j].goods_inputprice=temp3;
temp3=GoodsDates[j-1].goods_outputprice, GoodsDates[j-1].goods_outputprice=GoodsDates[j].goods_outputprice, GoodsDates[j].goods_outputprice=temp3;
temp1=GoodsDates[j-1].goods_num, GoodsDates[j-1].goods_num=GoodsDates[j].goods_num, GoodsDates[j].goods_num=temp1;
}
}

printf("\t \t库存\t编号 \t名称 \t类别 \t产地 \t进价 \t单价\n");
for(i=0;i<50;i++)
{
if( GoodsDates[i].goods_id==0 )
{
continue;
}
printf("\t\t%d %d\t%s\t%s\t%s\t%-5.2f\t%-5.2f\t\n",GoodsDates[i].goods_num,GoodsDates[i].goods_id,GoodsDates[i].goods_name,GoodsDates[i].goods_address,GoodsDates[i].goods_type,GoodsDates[i].goods_inputprice,GoodsDates[i].goods_outputprice);
}


}




/*消费者排序模块*/
void spendpaixumol()
{

int numOperator;
printf(" \t \t \t \t 1.利润排序\n");
printf(" \t \t \t \t 2.库存量排序\n");
printf(" \t \t \t \t 3.返回首页\n");
printf(" \t \t \t \t 请输入相应操作编号: ");
scanf("%d",&numOperator);
switch(numOperator)
{
case 1 :spendlirunpai();
break;
case 2 :spendkucunpai();
break;
case 3 :spendPassagerMenu();
break;
default:printf("\n\t\t\t>>> 输入错误,系统自动返回<<<\n\n");
}
}

/*消费者利润排行*/
void spendlirunpai()
{
int i=0,j,temp1,t;
char temp2[50];
float temp3;
float lirun[50]={0},temp;
printf("\n\t\t----------------------利润排行---------------------\n");

for(i;i<50; i++)
{
if( GoodsDates[i].goods_id==0 )
{
continue;
}
lirun[i]=( GoodsDates[i].goods_outputprice-GoodsDates[i].goods_inputprice )*(GoodsDates[i].goods_num);
}
for(i=0;i<49; i++)
{
for(j=49;j>i; j--)
if( lirun[j-1] < lirun[j] )
{
temp=lirun[j-1],lirun[j-1]=lirun[j],lirun[j]=temp;

temp1=GoodsDates[j-1].goods_id, GoodsDates[j-1].goods_id=GoodsDates[j].goods_id, GoodsDates[j].goods_id=temp1;
strcpy( temp2,GoodsDates[j-1].goods_nam

e),strcpy(GoodsDates[j-1].goods_name,GoodsDates[j].goods_name), strcpy(GoodsDates[j].goods_name,temp2);
strcpy(temp2,GoodsDates[j-1].goods_address), strcpy(GoodsDates[j-1].goods_address,GoodsDates[j].goods_address), strcpy(GoodsDates[j].goods_address,temp2);
strcpy(temp2,GoodsDates[j-1].goods_type),strcpy(GoodsDates[j-1].goods_type,GoodsDates[j].goods_type), strcpy(GoodsDates[j].goods_type,temp2);
temp3=GoodsDates[j-1].goods_inputprice, GoodsDates[j-1].goods_inputprice=GoodsDates[j].goods_inputprice, GoodsDates[j].goods_inputprice=temp3;
temp3=GoodsDates[j-1].goods_outputprice, GoodsDates[j-1].goods_outputprice=GoodsDates[j].goods_outputprice, GoodsDates[j].goods_outputprice=temp3;
temp1=GoodsDates[j-1].goods_num, GoodsDates[j-1].goods_num=GoodsDates[j].goods_num, GoodsDates[j].goods_num=temp1;
}
}

printf("\t\t利润\t编号 \t名称 \t类别 \t产地 \t进价 \t单价 \t数量\n");
for(i=0;i<50;i++)
{
if( GoodsDates[i].goods_id==0 )
{
continue;
}
printf(" \t \t%-5.3f %d\t%s\t%s\t%s\t%-5.2f\t%-5.2f\t%d\n",lirun[i],GoodsDates[i].goods_id,GoodsDates[i].goods_name,GoodsDates[i].goods_address,GoodsDates[i].goods_type,GoodsDates[i].goods_inputprice,GoodsDates[i].goods_outputprice,GoodsDates[i].goods_num);
}
}


/*输出消费者查询的商品*/
void printspendGoods()
{
int i,t;

printf("\n\t\t编号\t名称\t产地\t类别\t进价\t单价\t数量\n");
for(i=0;i<50;i++)
{
if( GoodsDates[i].goods_id==0 )
{
continue;
}
printf("\t\t%d\t%s\t%s\t%s\t%-5.2f\t%-5.2f\t%d\n",GoodsDates[i].goods_id,GoodsDates[i].goods_name,GoodsDates[i].goods_address,GoodsDates[i].goods_type,GoodsDates[i].goods_inputprice,GoodsDates[i].goods_outputprice,GoodsDates[i].goods_num);
}

printf("\t\t\t\t返回上一级选“1”: ");
scanf("%d",&t);
switch(t)
{
default:spendPassagerMenu();
}
}


/*消费者库存排行*/
void spendkucunpai()
{
int i=0,j,temp1;
char temp2[50];
float temp3;
printf("\n\t\t----------------------库存排行---------------------\n");

for(i=0;i<49; i++)
{
for(j=49;j>i; j--)
if( GoodsDates[j-1].goods_num < GoodsDates[j].goods_num )
{

temp1=GoodsDates[j-1].goods_id, GoodsDates[j-1].goods_id=GoodsDates[j].goods_id, GoodsDates[j].goods_id=temp1;
strcpy( temp2,GoodsDates[j-1].goods_name),strcpy(GoodsDates[j-1].goods_name,GoodsDates[j].goods_name), strcpy(GoodsDates[j].goods_name,temp2);
strcpy(temp2,GoodsDates[j-1].goods_address), strcpy(GoodsDates[j-1].goods_address,GoodsDates[j].goods_address), strcpy(GoodsDates[j].goods_address,temp2);
strcpy(temp2,GoodsDates[j-1].goods_type),strcpy(GoodsDates[j-1].goods_type,GoodsDates[j].goods_type), strcpy(GoodsDates[j].goods_type,temp2);
temp3=GoodsDates[j-1].goods_inputprice, GoodsDates[j-1].goods_inputprice=GoodsDates[j].goods_inputprice, GoodsDates[j].goods_inputprice=temp3;
temp3=GoodsDa

tes[j-1].goods_outputprice, GoodsDates[j-1].goods_outputprice=GoodsDates[j].goods_outputprice, GoodsDates[j].goods_outputprice=temp3;
temp1=GoodsDates[j-1].goods_num, GoodsDates[j-1].goods_num=GoodsDates[j].goods_num, GoodsDates[j].goods_num=temp1;
}
}

printf("\t \t库存\t编号 \t名称 \t类别 \t产地 \t进价 \t单价\n");
for(i=0;i<50;i++)
{
if( GoodsDates[i].goods_id==0 )
{
continue;
}
printf("\t\t%d %d\t%s\t%s\t%s\t%-5.2f\t%-5.2f\t\n",GoodsDates[i].goods_num,GoodsDates[i].goods_id,GoodsDates[i].goods_name,GoodsDates[i].goods_address,GoodsDates[i].goods_type,GoodsDates[i].goods_inputprice,GoodsDates[i].goods_outputprice);
}

}



/*消费者查询模块*/
void spendchaxunmol()
{
int numOperator;
printf("\t\t\t\t 1.按进货量查询\n");
printf("\t\t\t\t 2.按商品种类查询\n");
printf("\t\t\t\t 3.按商品名称询询\n");
printf("\t\t\t\t 4.返回首页\n");

printf("\t\t\t\t请输入相应操作编号: ");
scanf("%d",&numOperator);
switch(numOperator)
{
case 1 :spendgoods_num();
break;
case 2 :spendgoods_type();
break;
case 3 :spendgoods_name();
break;
case 4 :spendPassagerMenu();
break;
default:printf("\n\t\t\t>>> 输入错误,系统自动返回<<<\n\n");
}
}



/*消费者按商品数量查询*/
void spendgoods_num()
{

int num;
int i,t;
printf("\n\t\t\t\t请输入需要查询的商品进货量: ");
scanf("%d",&num);

printf("\n\t\t进货量\t种类\t编号\t名称\t产地\t进价\t单价\n");
for(i=0;i<50;i++)
{
if( GoodsDates[i].goods_num!=num )
{
continue;
}
printf("\t\t%d\t %s\t %d\t %s\t %s\t %-5.2f\t %-5.2f\n",GoodsDates[i].goods_num,GoodsDates[i].goods_type,GoodsDates[i].goods_id,GoodsDates[i].goods_name,GoodsDates[i].goods_address,GoodsDates[i].goods_inputprice,GoodsDates[i].goods_outputprice);
}

printf("\t\t\t\t返回上一级选“1”: ");
scanf("%d",&t);
switch(t)
{
default:spendPassagerMenu();
}
}

/*消费者按商品种类查询*/
void spendgoods_type()
{
char type[20];
int i,t;
printf("\n\t\t\t\t请输入需要查询的商品种类: ");
scanf("%s",&type);

printf("\n\t\t种类\t编号\t名称\t产地\t进价\t单价\t数量\n");
for(i=0;i<50;i++)
{
if( strcmp(GoodsDates[i].goods_type,type)!=0 )
{
continue;
}
printf("\t\t%s\t %d\t %s\t %s\t %-5.2f\t %-5.2f\t %d \n",GoodsDates[i].goods_type,GoodsDates[i].goods_id,GoodsDates[i].goods_name,GoodsDates[i].goods_address,GoodsDates[i].goods_inputprice,GoodsDates[i].goods_outputprice,GoodsDates[i].goods_num);
}

printf("\t\t\t\t返回上一级选“1”: ");
scanf("%d",&t);
switch(t)
{
default:spendPassagerMenu();
}
}

/*消费者按商品名称查询*/
void spendgoods_name()
{
char name[50];
int i,t;
printf("\t\t\t\t请输入需要查询的商品名称: ");
scanf("%s",&name);

printf("\n\t\t名称\t编号\t产地\

t种类\t进价\t单价\t数量\n");
for(i=0;i<50;i++)
{
if( strcmp( GoodsDates[i].goods_name,name ) !=0 )
{
continue;
}
printf("\t\t%s\t%d\t%s\t%s\t%-5.2f\t%-5.2f\t%d\n",GoodsDates[i].goods_name,GoodsDates[i].goods_id,GoodsDates[i].goods_address,GoodsDates[i].goods_type,GoodsDates[i].goods_inputprice,GoodsDates[i].goods_outputprice,GoodsDates[i].goods_num);
}

printf("\t\t\t\t返回选“1”: ");
scanf("%d",&t);
switch(t)
{
default:spendPassagerMenu();
}

}

相关文档
最新文档