用C语言编写“销售管理系统设计”程序

Python019

用C语言编写“销售管理系统设计”程序,第1张

讲下设计思想吧

便条实际上包含了登陆信息了,所以省去了登陆环节,简单点做到如下几点就可以 了:

1、调用c的图形类创建一菜单,有便条录入、和信息查询两栏,信息查询下面再分各种查询

2、便条录入可以都不用图形界面了,直接按条目输入值,顺序输入即可

3、保存以文件形式,可以在第一次建立个txt文档,以制表符分割开来各个字段,但是每次写入的时候必须按行作为一条数据,可以适当增加需要的字段作为查询统计方便用(每个制表符分割的为一个字段)。

4、查询统计就直接检索这个txt文档,该加总的求平均的用循环去查即可。

5、结果输出即把查到的内容在屏幕上打印出来即可。

其他,如果用c++做就简单多了,没那么多代码写

/*计算上个月每个人每种产品的销售额。

1)按销售额对销售员进行排序,输出排序结果(销售员代号)

2)统计每种产品的总销售额,对这些产品按从高到底的顺序,输出排序结果(需输出产品的代号和销售额)

3)输出统计报表如下:*/

#include <stdio.h>

#include <string.h>

#include <conio.h>

#include <stdlib.h>

#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=0i<Ri++) /*读出信息*/

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=0j<Rj++) /*对商品数量清零*/

for(t=0t<Zt++)

(x+j)->shangpin[t]=0

printf("please put the information about the 职工编号,产品编号,销售数量\n") /*写入信息*/

for(j=0j++)

{

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=0j<Rj++)

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=0i<Ri++) /*读出信息*/

if(fread(x+i,sizeof(data),1,fp)!=1)

printf("读入信息出错!") /*读入信息提示*/

for(i=0i<R)/*用于存储职工编号*/

bianhao[i]=i++

printf("请输入按何种产品排序\n")

scanf("%d",&k)

k=k-1 /*便于与结构体中的数组值对应*/

for(i=0i<Ri++) /*按K种产品对销售员排序,选择法排序*/

{

t=i

for(j=i+1j<Rj++)

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=0i<Ri++)

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=0i<Ri++) /*读出信息*/

if(fread(x+i,sizeof(data),1,fp)!=1)

printf("读入信息出错!")

for(i=0i<Zi++) /*对各种商品求和*/

for(j=0j<Rj++)

sum[i]=sum[i]+(x+j)->shangpin[i]

for(i=0i<Z)/*用于存储商品编号*/

bianhao[i]=i++

for(i=0i<Zi++)

printf("%3d",bianhao[i])

for(i=0i<Zi++) /*对产品从高到低排序,选择法排序*/

{

t=i

for(j=i+1j<Zj++) /*产品变化时,产品编号也随之变化,便于输出*/

if(sum[t]<sum[j])

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=0i<Zi++)

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=0i<Ri++) /*读出信息*/

if(fread(x+i,sizeof(data),1,fp)!=1)

printf("读入信息出错!")

for(i=0i<Zi++) /*对各种商品求和*/

for(j=0j<Rj++)

sum[i]=sum[i]+(x+j)->shangpin[i]

for(i=0i<Zi++) /*求商品总和*/

sum[Z]=sum[Z]+sum[i]

printf("输出统计报表如下:\n") /*按要求输出统计表*/

printf("产品代号 销售之和 销售员代号\n")

for(i=0i<Ri++)

for(j=0j<Zj++)

printf("%-10d%-10d%-10d\n",j+1,(x+i)->shangpin[j],i+1)

printf("***********************************\n")

for(i=0i<Zi++)

{

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=0i++)

{

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 /*输出统计报表*/

}

}

}

请采纳答案,支持我一下。

我这里有一个!

具体的,稍微改一下就可以了!

#include "stdio.h" /*I/O函数*/

#include "stdlib.h" /*其它说明*/

#include "string.h" /*字符串函数*/

#include "conio.h" /*屏幕操作函数*/

#include "mem.h" /*内存操作函数*/

#include "ctype.h" /*字符操作函数*/

#include "alloc.h" /*动态地址分配函数*/

struct score

{

int mingci

char xuehao[8]

char mingzi[20]

float score[6]

}data,info[1000]

int i,j,k=0

char temp[20],ch

FILE *fp,*fp1

void shuru()

{

if((fp=fopen("s_score.txt","ab+"))==NULL)

{

printf("cannot open this file.\n")

getch()exit(0)

}

for(i=0i<=1000i++)

{

printf("\nPlease shuru xuehao:")

gets(data.xuehao)

printf("Please shuru mingzi:")

gets(data.mingzi)

printf("Please shuru yuwen score:")

gets(temp)data.score[0]=atof(temp)

printf("Please shuru shuxue score:")

gets(temp)data.score[1]=atof(temp)

printf("Please input yingyu score:")

gets(temp)data.score[2]=atof(temp)

printf("Please shuru wuli score:")

gets(temp)data.score[3]=atof(temp)

printf("Please shur huaxue score:")

gets(temp)data.score[4]=atof(temp)

data.score[5]=data.score[0]+data.score[1]+data.score[2]+data.score[3]+data.score[4]

fwrite(&data,sizeof(data),1,fp)

printf("another?y/n")

ch=getch()

if(ch=='n'||ch=='N')

break

} fclose(fp)

}

void xianshi()

{

float sint n

if((fp=fopen("s_score.txt","rb+"))==NULL)

{

printf("Cannot reading this file.\n")

exit(0)

}

for(i=0i<=1000i++)

{

if((fread(&info[i],sizeof(info[i]),1,fp))!=1)

break

}

printf("\nxuehao mingzi yuwen shuxue yingyu wuli huauxue zhongfen\n")

for(j=0,k=1j<ij++,k++)

{

info[j].mingci=k

printf("%6s %8s %3.1f %3.1f %3.1f %3.1f %3.1f %3.1f\n",info[j].xuehao,info[j].mingzi,info[j].score[0],info[j].score[1],info[j].score[2],info[j].score[3],info[j].score[4],

info[j].score[5])

}

getch()

fclose(fp)

}

void xiugai()

{

if((fp=fopen("s_score.txt","rb+"))==NULL||(fp1=fopen("temp.txt","wb+"))==NULL)

{

printf("Cannot open this file.\n")

exit(0)

}

printf("\nPLease shuru xiugai xuehao:")

scanf("%d",&i)getchar()

while((fread(&data,sizeof(data),1,fp))==1)

{

j=atoi(data.xuehao)

if(j==i)

{

printf("xuehao:%s\nmingzi:%s\n",data.xuehao,data.mingzi)

printf("Please shuru mingzi:")

gets(data.mingzi)

printf("Please shuru yuwen score:")

gets(temp)data.score[0]=atof(temp)

printf("Please shuru shuxue score:")

gets(temp)data.score[1]=atof(temp)

printf("Please input yingyu score:")

gets(temp)data.score[2]=atof(temp)

printf("Please input wuli score:")

gets(temp)data.score[3]=atof(temp)

printf("Please input huaxue score:")

gets(temp)data.score[4]=atof(temp)

data.score[5]=data.score[0]+data.score[1]+data.score[2]+data.score[3]+data.score[4]

} fwrite(&data,sizeof(data),1,fp1)

}

fseek(fp,0L,0)

fseek(fp1,0L,0)

while((fread(&data,sizeof(data),1,fp1))==1)

{

fwrite(&data,sizeof(data),1,fp)

}

fclose(fp)

fclose(fp1)

}

void chazhao()

{

if((fp=fopen("s_score.txt","rb"))==NULL)

{

printf("\nCannot open this file.\n")

exit(0)

}

printf("\nPLease shuru xuehao chakan:")

scanf("%d",&i)

while(fread(&data,sizeof(data),1,fp)==1)

{

j=atoi(data.xuehao)

if(i==j)

{

printf("xuehao:%s mingzi:%s\nyuwen:%f\n shuxue:%f\n yingyu:%f\n wuli:%f\n huaxue:%f\n ",data.xuehao,data.mingzi,data.score[0],data.score[1],data.score[2],data.score[3],data.score[4],data.score[5])

}getch()

}

}

void shanchu()

{

if((fp=fopen("s_score.txt","rb+"))==NULL||(fp1=fopen("temp.txt","wb+"))==NULL)

{

printf("\nopen score.txt was failed!")

getch()

exit(0)

}

printf("\nPlease input ID which you want to del:")

scanf("%d",&i)getchar()

while((fread(&data,sizeof(data),1,fp))==1)

{

j=atoi(data.xuehao)

if(j==i)

{

printf("Anykey will delet it.\n")

getch()

continue

}

fwrite(&data,sizeof(data),1,fp1)

}

fclose(fp)

fclose(fp1)

remove("s_score.txt")

rename("temp.txt","s_score.txt")

printf("Data delet was succesful!\n")

printf("Anykey will return to main.")

getch()

}

main()

{

while(1)

{

clrscr()/*清屏幕*/

gotoxy(1,1)/*移动光标*/

textcolor(YELLOW)/*设置文本显示颜色为黄色*/

textbackground(BLUE)/*设置背景颜色为蓝色*/

window(1,1,99,99)/* 制作显示菜单的窗口,大小根据菜单条数设计*/

clrscr()

printf("*************welcome to use student manage******************\n")

printf("*************************menu********************************\n")

printf("* ========================================================= * \n")

printf("* 1>shuru 2>xiugai * \n")

printf("* 3>shanchu 4>chazhao * \n")

printf("* 5>xianshi 6>exit * \n")

printf("* * \n")

printf("* --------------------------------------------------------- * \n")

printf(" Please input which you want(1-6):")

ch=getch()

switch(ch)

{

case '1':shuru()break

case '2':xiugai()break

case '3':shanchu()break

case '4':chazhao()break

case '5':xianshi()break

case '6':exit(0)

default: continue

}

}

}