C语言销售管理系统(链表)

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

目录
一、题目与要求........................................ 错误!未定义书签。

二、需求分析 (2)
三、功能实现设计 (2)
四、文件附件 (7)
五、设计总结(课程设计心得与体会) (7)
六、程序源代码 (8)
第1页共12页
一、题目与要求:
1.1
某公司有四个销售员(编号:1-4),负责销售五种产品(编号:1-5)。

每个销售员都将当日出售的每种产品各写一张便条交上来。

每张便条内容有
1、销售员的代号
2、产品的代号
3、这种产品当天的销售额
1.2
每位销售员每天可能上缴0-5张便条。

假设手机到了上个月的所有便条,编写一个处理系统,读取上月的销售情况(自己设定),进行如下处理:
1、计算上个月没人每种产品的销售额
2、按销售额对销售员进行排序,输出排序结果(销售员代号)
3、统计每种产品的总销售额,对这些产品从高到低的顺序输出结果(须
输出产品的代号和销售额)
4、输出统计报表
二、需求分析
我的程序将会运用文件系统,love.txt文件内容作为程序的数据(便条)。

程序运行后首先将原始数据读取并保存到程序的结构体数组当中,然后再分文别类的统计数据;接着提供显示、排序等操作;本来应提供键盘式选择菜单实现功能选择,不过由于时间的原因,暂时还不能实现。

三、功能实现设计
3.1【头文件和预定义】
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
第2页共12页
#include<string.h>
3.2【功能函数声明】
void detail();
voidforeach();
void menu();
void product();
voidreaddata();
void seller();
void show();
void choice();
3.3【数据结构】
原始数据有销售员代号、产品代号和销售额,所以定义一个全局结构体链表,再定义数组sum用于保存分类后的信息。

typedefstruct data
{
intwork_id;
intpro_id;
int sell;
struct data *next;
}data,*list;
listhead,last;
intcout;/*the number of card*/
int sum[4][5]={{0,0,0,0,0},{0,0,0,0,0},{0,0,0,0,0},{0,0,0,0,0}}; 3.4【主函数】
数据初始化函数和主菜单函数
int main()
{
system("graftabl 936") ;/*可以输出中文*/
readdata();
foreach();
menu();
}
3.5【文件读取函数】readdata()
读出便条中的内容,并保存到文件结构体链表中
voidreaddata()
{
FILE *fp;
list q;
head=(list)malloc(sizeof(data));
q=head;
if((fp=fopen("D:\\love.txt","r"))==NULL)/*打开便条文件*/
{
printf("Can't open the file!\n");
第3页共12页
exit(0);
}
for(cout=0;!feof(fp);cout++)
{
last=(list)malloc(sizeof(data));
last->next=NULL;
fscanf(fp,"%d%d%d",&last->work_id,&last->pro_id,&last
->sell);
q->next=last;
q=last;
}
fclose(fp); /*关闭便条文件*/
}3.6【文件读取函数】foreach()
读取的文件的数据,进行表格分类统计。

voidforeach()
{
list p;
for(p=head;p<=last;p=p->next)
sum[p->work_id][p->pro_id]=sum[p->work_id][p->pro_id]+p->sell;
}
3.7【主菜单函数】menu()
显示系统功能菜单,功能自主选择
detail():计算上个月每个人每种产品的销售额
seller():统计每个销售员的总销售额,输出排序
product():统计每种产品的总销售额,输出排序
void menu()
{
intc,i;
ints;
system("cls");
textbackground(5);
textcolor(BLUE);
clrscr(); /*窗口美化*/
for(i=0;i<7;i++)
{
printf("%s",draw[i]);
}
{
printf("\n\n你的选择没有错(1-5):");
第4页共12页
scanf("%d",&c);
if(c<1||c>5)
{
s=1;
getchar();
}
elses=0;
} while(s==1);
switch(c)
{
case 1:
detail();break;
case 2:
seller();break;
case 3:
product();break;
case 4:
show();break;
case 5:
exit(0);
}
}3.8【功能函数】
5-1【每人每种产品销售额统计函数】detail()
计算每个人每种产品的销售额
void detail()
{
inti,j;
for(i=0;i<4;i++)
{
printf("\n\t\t%d seller:\n",i+1);
for(j=0;j<5;j++)
printf("\t\t%d product:%d\n",j+1,sum[i][j]); }
choice();
}3.9【销售员销售业绩排序函数】seller()
统计每个销售员的总销售额,输出排序
void seller()
{
第5页共12页
inti,j,k;
intlove[4]={0,0,0,0};
for(i=0;i<4;i++)
for(j=0;j<5;j++)
love[i]+=sum[i][j];
for(i=0;i<4;i++)
{ k=0;
for(j=0;j<4;j++)
if(love[k]<love[j])k=j;
printf("\t\t the sort_number id %d for seller %d\n",i+1,k+1);love[k]=-1;
}
choice();
}
3.10【总销售额统计函数】void product()
统计每种产品的总销售额,输出排序
void product()
{ inti,j,k;
int p[5]={0,0,0,0,0};
for(j=0;j<5;j++)
for(i=0;i<4;i++)
p[j]+=sum[i][j];
for(j=0;j<5;j++)
{k=0;
for(i=0;i<5;i++)
if(p[k]<p[i])k=i;
printf("\t\tthesort_number id %d for seller %d\n",j+1,k+1,p[k]);p[k]=-1;}
choice();
}3.11【统计报表输出函数】show()
统计每种产品的总销售额,对这些产品按从高到低的顺序输出排序结果(需输出产品代号和销售额)
void show()
{ inti,j;
printf("\n seller \t1 \t2 \t3 \t4 \t5 \tpro_sum");
printf("\n product");
for(i=0;i<4;i++)
{
printf("\n %d \t",i+1);
for(j=0;j<5;j++)
第6页共12页
printf("\t%d" ,sum[i][j]);
printf("\t%d",sum[i][0]+sum[i][1]+sum[i][2]+sum[i][3]+sum[i][4]);
}
printf("\n seller\t");
for(i=0;i<5;i++)
printf("\t%d",sum[0][i]+sum[1][i]+sum[2][i]+sum[3][i]);
choice();
}
3.12【公共函数】
【选择函数】choice()
选择退出系统或则返回主菜单
void choice()
{
int c;
printf("\n input your choic?\n 1>return MENU\n 2>exit progrom \n");
scanf("%d",&c);
if(c==1)
menu();
else
exit(0);
}
四.文件附件
love.txt(便条)文件保存于D盘目录下,该文件中数据如下:
1 1 7
2 5 5
3 4 2
4 2 4
1 3 3
3 4 3
五、设计总结(课程设计心得与体会)
通过这次C程序设计,我掌握了模块化设计方法,能够深入的理解结构化程序设计思想,熟练运用结构化程序设计方法,提高了运用C语言进行程序设计的能力。

此外我还熟悉了,对于文件读写的操作。

更重要的是对程序的调试有了显著的提高。

我发现我对程序的设计越来越感兴趣了,我决定今后在这一方面下一番功夫,取得一些成绩。

调试结果如下:
第7页共12页
六、源程序
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<string.h>
void detail();
voidforeach();
void menu();
void product();
voidreaddata();
void seller();
void show();
void choice();
char *draw[]={
"\n*******************菜单**********************", "\n 1. ADD销售员——产品", "\n 2. 排序销售员", "\n 3. 排序产品", "\n 4. SHOW-格", "\n 5. 退隐江湖",
"\n 8. 你真是太完美了"}; typedefstruct data
{
intwork_id;
intpro_id;
int sell;
第8页共12页
struct data *next;
}data,*list;
listhead,last;
intcout;/*the number of card*/
int sum[4][5]={{0,0,0,0,0},{0,0,0,0,0},{0,0,0,0,0},{0,0,0,0,0}};
int main()
{
system("graftabl 936") ;
readdata();
foreach();
menu();
}
voidreaddata()
{
FILE *fp;
list q;
head=(list)malloc(sizeof(data));
q=head;
if((fp=fopen("D:\\love.txt","r"))==NULL)
{
printf("Can't open the file!\n");
exit(0);
}
for(cout=0;!feof(fp);cout++)
{
last=(list)malloc(sizeof(data));
last->next=NULL;
fscanf(fp,"%d%d%d",&last->work_id,&last->pro_id,&last->sell);
q->next=last;
q=last;
}
fclose(fp);
}
voidforeach()
{
list p;
for(p=head;p<last;p=p->next)
sum[p->work_id][p->pro_id]=sum[p->work_id][p->pro_id]+p->sell; }
void menu()
{
intc,i;
第9页共12页
int w;
system("cls");
/*textbackground(5);
textcolor(BLUE);
clrscr();*/
for(i=0;i<7;i++)
{
printf("%s",draw[i]);
}
{
printf("\n\n你的选择没有错(1-5):");
scanf("%d",&c);
if(c<1||c>5)
{
w=1;
getchar();
}
else w=0;
} while(w==1);
switch(c)
{
case 1:
detail();break;
case 2:
seller();break;
case 3:
product();break;
case 4:
show();break;
case 5:
exit(0);
}
}
voiddetail()
{
inti,j;
for(i=0;i<4;i++)
{
printf("\n\t\t%d seller:\n",i+1);
第10页共12页
printf("\t\t%d product:%d\n",j+1,sum[i][j]);
}
choice();
}
void seller()
{
inti,j,k;
int love[4]={0,0,0,0};
for(i=0;i<4;i++)
for(j=0;j<5;j++)
love[i]+=sum[i][j];
for(i=0;i<4;i++)
{ k=0;
for(j=0;j<4;j++)
if(love[k]<love[j])k=j;
printf("\t\t the sort_number id %d for seller %d\n",i+1,k+1);love[k]=-1;
}
choice();}
void product()
{ inti,j,k;
int p[5]={0,0,0,0,0};
for(j=0;j<5;j++)
for(i=0;i<4;i++)
p[j]+=sum[i][j];
for(j=0;j<5;j++)
{k=0;
for(i=0;i<5;i++)
if(p[k]<p[i])k=i;
printf("\t\tthesort_number id %d for seller %d\n",j+1,k+1,p[k]);p[k]=-1;} choice();
}
void show()
{ inti,j;
printf("\n seller \t1 \t2 \t3 \t4 \t5 \tpro_sum");
printf("\n product");
for(i=0;i<4;i++)
{
printf("\n %d \t",i+1);
第11页共12页
printf("\t%d" ,sum[i][j]);
printf("\t%d",sum[i][0]+sum[i][1]+sum[i][2]+sum[i][3]+sum[i][4]);
}
printf("\n seller\t");
for(i=0;i<5;i++)
printf("\t%d",sum[0][i]+sum[1][i]+sum[2][i]+sum[3][i]);
choice();
}
void choice()
{
int c;
printf("\n input your choic?\n 1>return MENU\n 2>exit progrom \n");
scanf("%d",&c);
if(c==1)
menu();
else
exit(0);
}
第12页共12页。

相关文档
最新文档