求c语言程序设计报告——销售管理系统

2024-11-26 22:43:48
推荐回答(4个)
回答1:

#include
#include
#include
#include
#define Z 5
#define R 4 /*定义宏常量便于程序的一般化*/ /*R表示销售员个数*/
typedef struct /*缩短结构体变量名*/
{
int shangpin[Z]; /*定义结构体便于信息的存储和读写,辨别*/ /*R是表示商品的种类,最后一个为该销售员商品总和*/
}data;
void menu()
{ printf(" *******************************************************\n");
printf(" 0.结束操作\n");
printf(" 1.计算上个月每个人每种产品的销售额\n");
printf(" 2.按销售额对销售员进行排序,输出排序结果\n");
printf(" 3.统计每种产品的总销售额,输出排序结果\n");
printf(" 4.输出统计报表\n");
printf(" ******************************************************\n");
}
void data_read(data *x) /*读入函数使程序简洁*/
{
FILE *fp;
char fname[10];
int i;
printf("您想查询哪个月?\n");
printf("请输入月份:"); /*输入文件名,这样可以进行各个月份信息读入*/
scanf("%s",fname);
strcat(fname,".txt");/*连接文件属性*/
if((fp=fopen(fname,"rb"))==NULL) /*打开文件*/
{
printf("can not open the file\n");
exit(0);
}
for(i=0;i if(fread(x+i,sizeof(data),1,fp)!=1)
printf("读入信息出错!\n");
}
void data_count(data *x) /*计算上个月每个人每种产品的销售额*/
{
FILE *fp;
char fname[10];
int j,t; /*用于控制循环*/
int i,k,s; /*用于定义职工序号,产品序号,产品数量*/
system("cls");
printf("您想计算哪个月?\n");
printf("请输入月份:"); /*输入文件名,这样可以进行各个月份信息写入*/
scanf("%s",fname);
strcat(fname,".txt");
if((fp=fopen(fname,"wb"))==NULL) /*打开文件*/
{
printf("can not open the file\n");
exit(0);
}
for(j=0;j for(t=0;t (x+j)->shangpin[t]=0;
printf("please put the information about the 职工编号,产品编号,销售数量\n"); /*写入信息*/
for(j=0;;j++)
{
scanf("%d%d%d",&i,&k,&s);
if(i==0) /*输入职工为0时结束信息输入*/
break;
if(i>R||i<0||k>Z||k<0)
{
printf("the information error!\n"); /*避免输入信息出错*/
continue;
}
else
(x+i-1)->shangpin[k-1]=(x+i-1)->shangpin[k-1]+s;/*统计各个人的各种产品的数量,-1为了和数组中的序号相匹配*/
}
for(j=0;j if(fwrite((x+j),sizeof(data),1,fp)!=1) /*把信息写入文件中便有以后调用*/
printf("write error!\n");
fclose(fp); /*关闭文件避免信息遗漏*/
}
void range_sxy(data *x) /*按销售额对销售员进行排序,输出排序结果*/
{
FILE *fp;
char fname[10];
int i,k,j,t,bianhao[R]=,z;
system("cls");
printf("你要哪个月的?\n");
printf("请输入月份:"); /*输入文件名,这样可以进行各个月份信息读入*/
scanf("%s",fname);
strcat(fname,".txt");
if((fp=fopen(fname,"rb"))==NULL) /*打开文件*/
{
printf("can not open the file\n");
exit(0);
}
for(i=0;i if(fread(x+i,sizeof(data),1,fp)!=1)
printf("读入信息出错!"); /*读入信息提示*/
for(i=0;i bianhao[i]=i++;
printf("请输入按何种产品排序\n");
scanf("%d",&k);
k=k-1; /*便于与结构体中的数组值对应*/
for(i=0;i {
t=i;
for(j=i+1;j if((x+bianhao[t])->shangpin[k]<(x+bianhao[j])->shangpin[k])/*调用职工各自对应的结构体内的产品数量*/
t=j;
if(t!=i)
{
z=bianhao[i];
bianhao[i]=bianhao[t];
bianhao[t]=z;
}
}
printf("按%d产品对销售员排序为:\n",k+1);
for(i=0;i printf("%5d",bianhao[i]+1);
getch();
fclose(fp);
}
void range_shangpin(data *x) /*统计每种产品的总销售额,输出排序结果*/
{
FILE *fp;
char fname[10];
int i,j,sum[Z]=,bianhao[Z]=,z,t,k;
system("cls");
printf("您想计算哪个月的?\n");
printf("请输入月份:"); /*输入文件名,这样可以进行各个月份信息读入*/
scanf("%s",fname);
strcat(fname,".txt");
if((fp=fopen(fname,"rb"))==NULL) /*打开文件*/
{
printf("can not open the file\n");
exit(0);
}
for(i=0;i if(fread(x+i,sizeof(data),1,fp)!=1)
printf("读入信息出错!");
for(i=0;i for(j=0;j sum[i]=sum[i]+(x+j)->shangpin[i];
for(i=0;i bianhao[i]=i++;
for(i=0;i printf("%3d",bianhao[i]);
for(i=0;i {
t=i;
for(j=i+1;j if(sum[t] t=j;
if(t!=i)
{
k=sum[i];
sum[i]=sum[t];
sum[t]=k;
z=bianhao[i];
bianhao[i]=bianhao[t];
bianhao[t]=z;
}
}
printf("输出产品排序\n");
printf("产品编号 数量\n");
for(i=0;i printf("%-10d%-10d\n",bianhao[i]+1,sum[i]);
getch();
fclose(fp);
}
void data_out(data *x) /*输出统计报表*/
{
FILE *fp;
char fname[10];
int i,j,sum[Z+1]=;
system("cls");
printf("您想计算哪个月?\n");
printf("请输入月份:"); /*输入文件名,这样可以进行各个月份信息读入*/
scanf("%s",fname);
strcat(fname,".txt");
if((fp=fopen(fname,"rb"))==NULL) /*打开文件*/
{
printf("can not open the file\n");
exit(0);
}
for(i=0;i if(fread(x+i,sizeof(data),1,fp)!=1)
printf("读入信息出错!");
for(i=0;i for(j=0;j sum[i]=sum[i]+(x+j)->shangpin[i];
for(i=0;i sum[Z]=sum[Z]+sum[i];
printf("输出统计报表如下:\n"); /*按要求输出统计表*/
printf("产品代号 销售之和 销售员代号\n");
for(i=0;i for(j=0;j printf("%-10d%-10d%-10d\n",j+1,(x+i)->shangpin[j],i+1);
printf("***********************************\n");
for(i=0;i {
if(i==0)
printf("%d产品之和 %-10d 总和 %-10d\n",i+1,sum[i],sum[Z]);
else
printf("%d产品之和 %-10d\n",i+1,sum[i]);
}
getch();
}
void main()
{
int i,choice;
data sxy[R]; /*R表示职工的个数,前面的宏常量*/
for(i=0;;i++)
{
system("cls"); /*清频命令*/
menu(); /*菜单函数提示用户怎样选择*/
printf("你想做什么?\n");
printf("请选择:"); /*输入要进行的操作*/
scanf("%d",&choice);
if(choice==0) /*退出程序*/
break;
else
switch(choice)
{
case 1 : data_count(sxy);break; /*计算上个月每个人每种产品的销售额*/
case 2 : range_sxy(sxy);break; /*按销售额对销售员进行排序,输出排序结果*/
case 3 : range_shangpin(sxy);break; /*统计每种产品的总销售额,输出排序结果*/
case 4 : data_out(sxy);break; /*输出统计报表*/
}
}
}

回答2:

#include
#include
#include
#define N 30

struct production
{
int number;
char name[10];
int inprice;
int outprice;
int quantity;
}production[N];

void welcome()
{
printf(" ^^^^^^^ ^^^^^^^\n");
printf(" --------------------welcome--------------------\n");
printf(" #* *#\n");
printf(" #* sale of production management system *#\n");
printf(" #* *#\n");
printf(" ---------=====!what do you want to do!=====---------\n");
printf("\n");
printf(" **~~ 1 input ~~**\n");
printf(" **~~ 2 insert ~~**\n");
printf(" **~~ 3 search_name ~~**\n");
printf(" **~~ 4 search_number ~~**\n");
printf(" **~~ 5 delete ~~**\n");
printf(" **~~ 6 display ~~**\n");
printf(" **~~ 7 profit ~~**\n");
printf(" **~~ 8 sort ~~**\n");
printf("\n");
printf(" --------<~><~><~><~><~><~><~><~><~><~><~><~>--------\n");
printf("\n");
printf("please input you choice(A number between 1 and 8):\n");
}

void input1(int i)
{
printf("Please input the data:\n");
printf("please input the number:\n");
scanf("%d",&production[i].number);
printf("please input the name:\n");
scanf("%s",&production[i].name);
printf("please input the inprice:\n");
scanf("%d",&production[i].inprice);
printf("please input the outprice:\n");
scanf("%d",&production[i].outprice);
printf("please input the quantity:\n");
scanf("%d",&production[i].quantity);
}

void input()
{
int i,m=0;
char x;
for(i=0;i if(strlen(production[i].name )!=0)
m++;
for(i=m;i{
input1(i);
printf("Do you want to continue inputing new data\n");
x=getch();
if(x=='y'||x=='Y')
continue;
if(x=='n'||x=='N')
break;
}
}

int insert()
{
int i,m=0;
for(i=0;i if(strlen(production[i].name)!=0)
m++;
input1(m);
}
delete
{
char n[10];
int i,j,b=0,m=0;
for(i=0;i if(strlen(production[i].name)!=0)
m++;
printf("Enter the name of the production which you want to delete!");
scanf("%s",&n);
for(i=0;iif(strcmp(production[i].name,n)==0)
{
for(j=i;j<=m;j++)
production[j]=production[j+1];
b=1;
}
if(b==0)
printf("Not find you data!\n");
if(b==1)
printf("Succeed!The data has been deleted!\n");
}

void search_number()
{
int number,i,flag=0;
printf("Please enter number which you want to search:");
scanf("%d",&number);
for(i=0;iif(production[i].number==number)
{
printf("the information of this number:\n");
printf("Number: %d\nName: %s\nInprice: %d\nOutprice: %d\nQuantity: %d\n",production[i].number,production[i].name,production[i].inprice,production[i].outprice,production[i].number);
flag=1;
}
if(flag==0)
printf("The number is not exist !\n");
}

void search_name()
{
char name[20];
int i,flag=0;
printf("Please enter name which you want to search:");
scanf("%s",&name);
for(i=0;iif(strcmp(production[i].name,name))
{
printf("the information of this name:\n");
printf("Number: %d\nName: %s\nInprice: %d\nOutprice: %d\nQuantity: %d\n",production[i].number,production[i].name,production[i].inprice,production[i].outprice,production[i].number);
flag=1;
}
if(flag==0)
printf("The name is not exist !\n");
}

void profit()
{
int p[N],pr=0,i,m=0;
for(i=0;i if(strlen(production[i].name)!=0)
m++;
for(i=0;i{
p[i]=(production[i].outprice-production[i].inprice)*production[i].quantity;
pr=pr+p[i];
printf("Name: %-7s\tNumber: %-7d\tprofit: %-10d\n",production[i].name,production[i].number,p[i]);
}
printf("Total Profit: %d\n",pr);
}

void sort()
{ int i,j,t,s,m=0,b[N],a[N];
for(i=0;i if(strlen(production[i].name)!=0)
m++;
for(i=0;i{
b[i]=production[i].outprice*production[i].quantity;
a[i]=production[i].number;
}
printf("Before sorted:\n");
for(i=0;iprintf("Number: %-5d\tSale: %-10d\n",a[i],b[i]);
for(i=1;i for(j=0;j if(b[j]>b[j+1])
{
t=b[j];
b[j]=b[j+1];
b[j+1]=t;
s=a[j];
a[j]=a[j+1];
a[j+1]=s;
}
printf("After sorted:\n");
for(i=0;iprintf("Number: %-5d\tSale: %-10d\n",a[i],b[i]);
}

void output()
{
int i,m=0;
for(i=0;i if(strlen(production[i].name)!=0)
m++;
printf("Disply all the data below:\n");
for(i=0;i{
printf("The number: %d\n",production[i].number);
printf("The name: %s\n",production[i].name);
printf("The inprice: %d\n",production[i].inprice);
printf("The outprice: %d\n",production[i].outprice);
printf("The quantity: %d\n",production[i].quantity);
printf("\n");
}
}

void main()
{
int c;
welcome();
while(1)
{
scanf("%d",&c);
switch(c)
{
case 0:welcome();break;
case 1:input();printf("You may enter 0 to back to Welcome to look you choices!\n");break;
case 2:insert();printf("You may enter 0 to back to Welcome to look you choices!\n");break;
case 3:search_name();printf("You may enter 0 to back to Welcome to look you choices!\n");break;
case 4:search_number();printf("You may enter 0 to back to Welcome to look you choices!\n");break;
case 6:output();printf("You may enter 0 to back to Welcome to look you choices!\n");break;
case 7:profit();printf("You may enter 0 to back to Welcome to look you choices!\n");break;
case 8:sort();printf("You may enter 0 to back to Welcome to look you choices!\n");break;
}
}

}

回答3:

dai zi haha!

回答4:

/*计算上个月每个人每种产品的销售额。
1)按销售额对销售员进行排序,输出排序结果(销售员代号)
2)统计每种产品的总销售额,对这些产品按从高到底的顺序,输出排序结果(需输出产品的代号和销售额)
3)输出统计报表如下:*/

#include
#include
#include
#include
#define Z 5
#define R 4 /*定义宏常量便于程序的一般化*/ /*R表示销售员个数*/
typedef struct /*缩短结构体变量名*/
{
int shangpin[Z]; /*定义结构体便于信息的存储和读写,辨别*/ /*R是表示商品的种类,最后一个为该销售员商品总和*/
}data;
void menu()
{ printf(" *******************************************************\n");
printf(" 0.结束操作\n");
printf(" 1.计算上个月每个人每种产品的销售额\n");
printf(" 2.按销售额对销售员进行排序,输出排序结果\n");
printf(" 3.统计每种产品的总销售额,输出排序结果\n");
printf(" 4.输出统计报表\n");
printf(" ******************************************************\n");
}
void data_read(data *x) /*读入函数使程序简洁*/
{
FILE *fp;
char fname[10];
int i;
printf("您想查询哪个月?\n");
printf("请输入月份:"); /*输入文件名,这样可以进行各个月份信息读入*/
scanf("%s",fname);
strcat(fname,".txt");/*连接文件属性*/
if((fp=fopen(fname,"rb"))==NULL) /*打开文件*/
{
printf("can not open the file\n");
exit(0);
}
for(i=0;i if(fread(x+i,sizeof(data),1,fp)!=1)
printf("读入信息出错!\n");
}
void data_count(data *x) /*计算上个月每个人每种产品的销售额*/
{
FILE *fp;
char fname[10];
int j,t; /*用于控制循环*/
int i,k,s; /*用于定义职工序号,产品序号,产品数量*/
system("cls");
printf("您想计算哪个月?\n");
printf("请输入月份:"); /*输入文件名,这样可以进行各个月份信息写入*/
scanf("%s",fname);
strcat(fname,".txt");
if((fp=fopen(fname,"wb"))==NULL) /*打开文件*/
{
printf("can not open the file\n");
exit(0);
}
for(j=0;j for(t=0;t (x+j)->shangpin[t]=0;
printf("please put the information about the 职工编号,产品编号,销售数量\n"); /*写入信息*/
for(j=0;;j++)
{
scanf("%d%d%d",&i,&k,&s);
if(i==0) /*输入职工为0时结束信息输入*/
break;
if(i>R||i<0||k>Z||k<0)
{
printf("the information error!\n"); /*避免输入信息出错*/
continue;
}
else
(x+i-1)->shangpin[k-1]=(x+i-1)->shangpin[k-1]+s;/*统计各个人的各种产品的数量,-1为了和数组中的序号相匹配*/
}
for(j=0;j if(fwrite((x+j),sizeof(data),1,fp)!=1) /*把信息写入文件中便有以后调用*/
printf("write error!\n");
fclose(fp); /*关闭文件避免信息遗漏*/
}
void range_sxy(data *x) /*按销售额对销售员进行排序,输出排序结果*/
{
FILE *fp;
char fname[10];
int i,k,j,t,bianhao[R]=,z;
system("cls");
printf("你要哪个月的?\n");
printf("请输入月份:"); /*输入文件名,这样可以进行各个月份信息读入*/
scanf("%s",fname);
strcat(fname,".txt");
if((fp=fopen(fname,"rb"))==NULL) /*打开文件*/
{
printf("can not open the file\n");
exit(0);
}
for(i=0;i if(fread(x+i,sizeof(data),1,fp)!=1)
printf("读入信息出错!"); /*读入信息提示*/
for(i=0;i bianhao[i]=i++;
printf("请输入按何种产品排序\n");
scanf("%d",&k);
k=k-1; /*便于与结构体中的数组值对应*/
for(i=0;i {
t=i;
for(j=i+1;j if((x+bianhao[t])->shangpin[k]<(x+bianhao[j])->shangpin[k])/*调用职工各自对应的结构体内的产品数量*/
t=j;
if(t!=i)
{
z=bianhao[i];
bianhao[i]=bianhao[t];
bianhao[t]=z;
}
}
printf("按%d产品对销售员排序为:\n",k+1);
for(i=0;i printf("%5d",bianhao[i]+1);
getch();
fclose(fp);
}
void range_shangpin(data *x) /*统计每种产品的总销售额,输出排序结果*/
{
FILE *fp;
char fname[10];
int i,j,sum[Z]=,bianhao[Z]=,z,t,k;
system("cls");
printf("您想计算哪个月的?\n");
printf("请输入月份:"); /*输入文件名,这样可以进行各个月份信息读入*/
scanf("%s",fname);
strcat(fname,".txt");
if((fp=fopen(fname,"rb"))==NULL) /*打开文件*/
{
printf("can not open the file\n");
exit(0);
}
for(i=0;i if(fread(x+i,sizeof(data),1,fp)!=1)
printf("读入信息出错!");
for(i=0;i for(j=0;j sum[i]=sum[i]+(x+j)->shangpin[i];
for(i=0;i bianhao[i]=i++;
for(i=0;i printf("%3d",bianhao[i]);
for(i=0;i {
t=i;
for(j=i+1;j if(sum[t] t=j;
if(t!=i)
{
k=sum[i];
sum[i]=sum[t];
sum[t]=k;
z=bianhao[i];
bianhao[i]=bianhao[t];
bianhao[t]=z;
}
}
printf("输出产品排序\n");
printf("产品编号 数量\n");
for(i=0;i printf("%-10d%-10d\n",bianhao[i]+1,sum[i]);
getch();
fclose(fp);
}
void data_out(data *x) /*输出统计报表*/
{
FILE *fp;
char fname[10];
int i,j,sum[Z+1]=;
system("cls");
printf("您想计算哪个月?\n");
printf("请输入月份:"); /*输入文件名,这样可以进行各个月份信息读入*/
scanf("%s",fname);
strcat(fname,".txt");
if((fp=fopen(fname,"rb"))==NULL) /*打开文件*/
{
printf("can not open the file\n");
exit(0);
}
for(i=0;i if(fread(x+i,sizeof(data),1,fp)!=1)
printf("读入信息出错!");
for(i=0;i for(j=0;j sum[i]=sum[i]+(x+j)->shangpin[i];
for(i=0;i sum[Z]=sum[Z]+sum[i];
printf("输出统计报表如下:\n"); /*按要求输出统计表*/
printf("产品代号 销售之和 销售员代号\n");
for(i=0;i for(j=0;j printf("%-10d%-10d%-10d\n",j+1,(x+i)->shangpin[j],i+1);
printf("***********************************\n");
for(i=0;i {
if(i==0)
printf("%d产品之和 %-10d 总和 %-10d\n",i+1,sum[i],sum[Z]);
else
printf("%d产品之和 %-10d\n",i+1,sum[i]);
}
getch();
}
void main()
{
int i,choice;
data sxy[R]; /*R表示职工的个数,前面的宏常量*/
for(i=0;;i++)
{
system("cls"); /*清频命令*/
menu(); /*菜单函数提示用户怎样选择*/
printf("你想做什么?\n");
printf("请选择:"); /*输入要进行的操作*/
scanf("%d",&choice);
if(choice==0) /*退出程序*/
break;
else
switch(choice)
{
case 1 : data_count(sxy);break; /*计算上个月每个人每种产品的销售额*/
case 2 : range_sxy(sxy);break; /*按销售额对销售员进行排序,输出排序结果*/
case 3 : range_shangpin(sxy);break; /*统计每种产品的总销售额,输出排序结果*/
case 4 : data_out(sxy);break; /*输出统计报表*/
}
}
}