文档库 最新最全的文档下载
当前位置:文档库 › C语言课程设计_销售管理系统

C语言课程设计_销售管理系统

/*5、销售管理
问题描述:
已知一公司某公司有4个销售员(编号、姓名、性别),负责销售5种产品(产品代号、产品名称,销售价格)。
设计一程序,完成以下功能:
1) 从键盘输入销售信息:销售员编号、产品编号、销售日期、销售数量(输入时需要判断销售员编号是否存在、
产品编号是否存在、销售数量是否大于0,销售日期日期格式是否合法(格式为:YYYY-MM-DD,如2009-01-02)))
2) 能输出指定时间段内的销售统计报表,格式如下:
销售统计报表
产品代号 销售之和
销售员代号 1 2 3 4 5
1
2
3
4
每种产品之和 总和
3) 根据销售员编号查询销售历史情况
4) 能删除指定销售员、产品、销售日期的记录
提示:
定义一个日期结构体保存日期,具体信息为:年、月、日
判断销售日期的格式是否合法时,需要判断长度是否为10,第5位和第8位是否为'-',字符,将1-4位表示的年份,
6-7位表示的月份,9-10位表示的日期分别转换成整数。
判断是否满足构成日期的条件闰年月份只能是1-12之间的数,如果是闰年,
二月可以是29天否则不能大于28,1,3,5,7,8,10,12月可以是31天,其余只能小于等于30(建议写成函数)。
定义一个结构体数组保存4个销售员信息,具体信息为:编号、姓名、性别
定义一个结构体数组保存5种产品信息,具体信息为:产品代号、产品名称,销售价格
定义一个链表保存销售信息,信息为:销售员编号、产品编号、销售日期、销售数量。每输入一比销售信息时,
在该链表中插入一条记录
输入销售信息时需要查询销售员数组和产品数组,是否存在该销售员和产品
实现第二个功能(销售统计报表)时,需要定义一个二维数组report(5行6列)来保存报表信息,遍历销售链表
,如果销售日期大于开始统计时间小于结束统计时间,
判断其销售员代号在销售员数组中的下标m,以及产品代号在产品数组中的下标,
并将该销售数量累加在report[m][n]元素中,再输入该二维数组
*/
#include /*标准输入输出头文件*/
#include /*库函数头文件*/
#include /*字符串操作头文件*/
#include /*如getch()操作头文件*/
#include /*窗口类操作,系统调用如清屏等*/
#include /*文件读写操作*/

/*销售员信息结构体*/
struct clerk
{
int num;
char name[20];
char sex[6];
} cle[4];

/*产品信息结构体*/
struct product
{
int mark;
char definition[20];
float price;
} prod[5];

/*销售信息结构体*/
struct information
{
int znum;
int

zmark;
char date[10];
int amount;
struct information *next;
};


/******以下是函数原型*******/
void Create_clerk(); /*声明录入销售员资料函数*/
void Create_product(); /*声明录入产品资料函数*/
void display(struct information *head); /*声明显示销售员产品等信息函数*/
void add(struct information *head); /*声明添加销售记录函数*/
void search(struct information *head); /*声明查询销售员销售信息函数*/
void Delete(struct information *head); /*声明删除销售信息函数*/
void dclerk(struct information *head); /*声明按销售员删除销售信息函数*/
void dpro(struct information *head); /*声明按产品删除销售信息函数*/
void dinf(struct information *head); /*声明按销售日期删除销售信息函数*/
void printmess(struct information *head); /*声明显示销售报表函数*/
int write(struct information *head); /*声明保存销售信息*/
int menu_show(); /*声明主菜单函数*/
int menu_select(int sel,struct information * head); /*功能函数*/

/******主函数开始*******/
main()
{

struct information * head; /*定义链表的头节点*/
int size=sizeof(struct information);
head=(struct information *)malloc(size);
head->next=NULL;
system("cls"); /*清屏*/
for(;;) /*无限循环*/
{
menu_select(menu_show(),head);
}
}
/*
根据参数选择相应的功能函数
sel 功能选择代码
head 链表头节点
*/
menu_select(int sel,struct information * head)
{
switch(sel) /*调用主菜单函数,返回值整数作开关语句的条件*/
{
case 0:Create_clerk();break; /*创建销售员个人资料*/
case 1:Create_product();break; /*创建产品资料*/
case 2:add(head);break; /*新建销售信息记录*/
case 3:search(head);break; /*查找销售信息记录*/
case 4:printmess(head);break; /*显示销售报表信息*/
case 5:Delete(head);break; /*删除销售信息记录*/
case 6:display(head);break; /*显示基本信息*/
case 7:write(head);break; /*保存销售信息到文件*/
case 8:exit(0); /*如返回值为6则程序结束*/
}
}

/*菜单函数,函数返回值为整数,代表所选的菜单项*/
int menu_show()
{
char s[80];
int c;
printf("请按任意键继续......\n"); /*提示任意键继续*/
getchar(); /*读入任意字符*/
system("cls"); /*清屏*/
printf("\n\n\n********************销售管理系统*********************\n*\n");
printf("* 0.创建销售员个人资料\n");
printf("* 1.创建产品资料\n");
printf("* 2.输入销售信息\n");
printf("* 3.查询

销售信息\n");
printf("* 4.显示销售信息报表\n");
printf("* 5.删除销售信息 \n");
printf("* 6.查看销售员产品信息 \n");
printf("* 7.保存销售信息 \n");
printf("* 8.退出\n*\n");
printf("*******************************************************\n");
do{
printf("\n 请输入0-8之间的数选择需要的操作:"); /*提示输入选项*/
scanf("%s",&s); /*输入选择项*/
c=atoi(s); /*将输入的字符串转化为整型数*/
}
while(c<0||c>8); /*选择项不在0~4之间重输*/
return c; /*返回选择项,主程序根据该数调用相应的函数*/
}

void Create_clerk()
{
struct clerk *pt1;
int i,ch;
char filename[15];
system("cls"); /*清屏*/
printf("****************************选择界面******************************************\n");
printf("\n 0.键盘输入销售员信息\n");
printf("\n 1.文件读取销售员信息\n");
printf("\n----------------------------------------------------------------\n");
printf("\n 请输入0或1选择需要的操作:");
do{
scanf("%d",&ch);
if(ch!=0&&ch!=1)
printf("\n 输入错误! 请重新输入0或1需要的操作:");
}while(ch!=0&&ch!=1);
if(ch == 1)
{
FILE *fp;
printf("请输入你要读取信息所在的文件名:");
scanf("%s",filename);
if((fp=fopen(filename,"rt"))==NULL)
{
printf("\nCannot open file strike any key exit!\n\n");
exit(1);
}
ch=getchar(); /*用来吸收scanf函数最后输入的回车符*/
for(i=0;i<4;i++)
fscanf(fp,"%d %s %s",&(cle[i].num),&(cle[i].name),&(cle[i].sex));
fclose(fp);
printf("提示:从文件 %s 中成功读取4名销售员基本信息!\n",filename);
}
else
{
printf("****************************输入界面******************************************\n");
printf("\n 销售员的编号 姓名 性别(male或female) (空格隔开)\n");
printf("----------------------------------------------------------------\n");
for(i=0;i<4;i++)
{
pt1=cle+i;
printf("\n第%d个人资料:",i+1);
scanf("%d%s%s",&pt1->num,pt1->name,pt1->sex);
/*****************判断输入信息是否有误***************/
if(strcmp(pt1->sex,"male")==0 || strcmp(pt1->sex,"female")==0 );
else
{
printf("性别输入有误请重新输入");
scanf("%s",&pt1->sex);
}
}
system("cls");
}
}
void Create_product()
{
struct product *pt2;
int j,ch;
char filename[15];
system("cls"); /*清屏*/
printf("****************************选择界面******************************************\n");
printf("\n 0.键盘输入产品信息\n");
printf("\n 1.文件读取产品信息\n");
printf("\n----------------------------------------------------------------\n");
printf("\n 请输入0

或1选择需要的操作:");
do{
scanf("%d",&ch);
if(ch!=0&&ch!=1)
printf("\n 输入错误! 请重新输入0或1需要的操作:");
}while(ch!=0&&ch!=1);
if(ch == 1)
{
FILE *fp;
printf("请输入你要读取信息所在的文件名:");
scanf("%s",filename);
if((fp=fopen(filename,"rt"))==NULL)
{
printf("\nCannot open file strike any key exit!\n\n");
exit(1);
}
ch=getchar(); /*用来吸收scanf函数最后输入的回车符*/
for(j=0;j<5;j++)
fscanf(fp,"%d %s %f",&(prod[j].mark),&(prod[j].definition),&(prod[j].price));
fclose(fp);
printf("提示:从文件 %s 中成功读取5类产品信息!\n",filename);
}
else
{

printf("****************************输入界面******************************************\n");
printf("\n 产品代号,名称, 价格 (逗号隔开)\n");
printf("-------------------------------------------------\n");

for(j=0;j<5;j++)
{
pt2=prod+j;
printf("\n第%d个产品资料: ",j+1);
scanf("%d,%s,%f",&pt2->mark,&pt2->definition,&pt2->price);
}
}
}

void display(struct information *head)
{
int i;
struct information *p=head->next;
printf("************************系统基本信息**********************\n\n\n");
printf("-------------------销售员信息-----------------\n\n");
printf(" 编号 姓名 性别 \n");
for(i=0;i<4;i++)
printf(" %d %s %s\n",cle[i].num,cle[i].name,cle[i].sex);
printf("\n\n-------------------产品信息-------------------\n\n");
printf(" 编号 名称 价格 \n");
for(i=0;i<5;i++)
printf(" %d %s %.2f\n",prod[i].mark,prod[i].definition,prod[i].price);

printf("\n\n-------------------销售记录-------------------\n\n");
printf(" 销售员 产品 销售日期 销售量 \n");
while(p != NULL)
{
printf(" %d %d %s %d\n",p->znum,p->zmark,p->date,p->amount);
p=p->next;
}
getch();
}

/*输入记录,参数为头节点

在函数中实现键盘输入并插入到节点
*/
void add(struct information * head)
{

struct information *temp,*p;
int i=0,chi;
char filename[15],ch;
int size=sizeof(struct information);
p=head;

system("cls"); /*清屏*/
printf("****************************选择界面******************************************\n");
printf("\n 0.键盘输入销售信息\n");
printf("\n 1.文件读取销售信息\n");
printf("\n----------------------------------------------------------------\n");
printf("\n 请输入0或1选择需要的操作:");
do{
scanf("%d",&chi);
if(chi!=0&&chi!=1)
printf("\n 输入错误! 请重新输入0或1选择需要的操作:");
}while(chi!=0&&chi!=1);
if(chi == 0)
{
printf("*********************请输入销售信息*************************\n\n"); /*提示输入记录*/

printf("销售

员编号 产品代号 日期(YYYY-MM-DD) 销售数量(空格隔开)\n");
printf("-----------------------------------------------------------\n");
temp=(struct information *)malloc(size);
while(p->next!=NULL)
{
p=p->next;
}
p->next=temp;
temp->next=NULL;
scanf("%d%d%s%d",&temp->znum,&temp->zmark,&temp->date,&temp->amount); /*输入记录*/
while(judge_date(temp))
{
scanf("%s",temp->date);
printf("修改成功!");
getchar();
}
while(i<4)
{
if(temp->znum==cle[i].num) break;
else i++;
}
if(i==4)
{
printf("无匹配的编号请重新输入\n");
scanf("%d",&p->znum);
}
i=0;
while(i<5)
{
if(temp->zmark==prod[i].mark) break;
else i++;
}
if(i==5)
{
printf("无匹配的产品代号请重新输入\n");
scanf("%d",&temp->zmark);
}
/*输入信息判断结束*/
}
else
{
FILE *fp;i=0;
printf("请输入你要读取信息所在的文件名:");
scanf("%s",filename);
if((fp=fopen(filename,"rt"))==NULL)
{
printf("\nCannot open file strike any key exit!\n\n");
exit(1);
}
ch=getchar(); /*用来吸收scanf函数最后输入的回车符*/
while(ch!=EOF)
{
p=head;
temp=(struct information *)malloc(size);
while(p->next!=NULL)
{
p=p->next;

}
p->next=temp;
temp->next=NULL;i++;
fscanf(fp,"%d %d %s %d",&temp->znum,&temp->zmark,&temp->date,&temp->amount);
ch=fgetc(fp); /*写完再依次继续读*/
}
fclose(fp);
printf("提示:从文件 %s 中成功读取 %d 条销售记录!\n",filename,i);
}
}

int judge_date(struct information *pt)
{
struct information *p=pt;
int moth[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
int month,day,year;
year=(p->date[0]-'0')*1000+(p->date[1]-'0')*100+(p->date[2]-'0')*10+(p->date[3]-'0');
month=(p->date[5]-'0')*10+(p->date[6]-'0');
day=(p->date[8]-'0')*10+(p->date[9]-'0');
if(year%400==0 ||(year%4==0 && year %100 !=0))
moth[2]++;
if(p->date[4]!='-'||p->date[7]!='-')
{
printf("格式输入不对,请重新输入\n");
return 1;
}
else if(day>moth[month] || day<0)
{
printf("日期输入不对,请重新输入\n");
return 1;
}
else if(month>12 ||month<0)
{
printf("月份输入不对,请重新输入\n");
return 1;
}
return 0;
}

/*定义删除函数**/
void Delete(struct information *head)
{
int cel;
system("cls"); /*清屏*/
printf("\n\n********************删除记录系统*********************\n\n");
printf(" 1. 删除销售员的记录\n");
printf(" 2. 删除产品的记录\n");
printf(" 3. 删除销售日期的记录\n");
printf(" 0. 退出\n");
printf("************************************

***********\n");
printf("\n 请输入0-3之间的数选择需要的操作:");
do{
scanf("%d",&cel);
if(cel<0||cel>3)
printf("\n 输入错误! 请重新输入0-3之间的数选择需要的操作:");
}while(cel<0||cel>3);
switch(cel)
{
case 1:dclerk(head);break;
case 2:dpro(head);break;
case 3:dinf(head);break;
case 0:break;
}
return ;
}
/*定义删除指定销售日期的记录函数*/
void dinf(struct information *head)
{
char temp[10];
struct information *p,*followp;
p=head;
followp =head;
printf("请输入要删除记录的销售日期");
scanf("%s",&temp);
while(p!=NULL)
{
if(strcmp(p->date,temp)==0)
{
if(p == head)
{
head = head ->next;
p=p->next;
continue;
}
else
{
followp->next = p->next;
p=p->next;
continue;
}
}
followp=p;
p=p->next;
}
}
/*定义删除指定产品的记录函数*/
void dpro(struct information *head)
{
int a;
struct information *p,*followp;
p=head;
followp =head;
printf("请输入要删除记录的产品编号");
scanf("%d",&a);
while(p!=NULL)
{
if(p->zmark == a)
{
if(p == head)
{
head = head ->next;
p=p->next;
continue;
}
else
{
followp->next = p->next;
p=p->next;
continue;
}
}
followp=p;
p=p->next;
}
}
/*定义删除指定销售员的记录函数*/
void dclerk(struct information *head)
{
struct information *p,*followp;
int temp;
p=head;
followp =head;
printf("请输入要删除记录的销售员编号:");
scanf("%d",&temp);
while(p!=NULL)
{
if(p->znum == temp)
{
if(p == head)
{
head = head ->next;
p=p->next;
continue;
}
else
{
followp->next = p->next;
p=p->next;
continue;
}
}
followp=p;
p=p->next;
}
}

void search(struct information *head)
{
int inum,flag=0;
struct information *ptr=head;
system("cls"); /*清屏*/
printf("\n\n*******************查询界面*****************************\n\n");
printf("请输入要查询的销售员的编号: ");
scanf("%d",&inum);
while(ptr!= NULL)
{
if(ptr->znum==inum)
{
printf("\n 销售员编号:%d 产品代号:%d 销售日期:%s 销售数量%d \n",inum,ptr->zmark,ptr->date,ptr->amount);
flag = 1;
}
ptr = ptr->next;
}
if(flag == 0)
printf(" \n 提示:销售员 %d 没有销售记录信息!\n\n ",inum);
getchar();
}


int write(struct information *head)
{
char filename[15],ch;
struct information *ptr=head->next;
FILE *fp;
printf("请输入你要保存销售信息所在的文件名:");
scanf("%s",filename);
if((fp=fopen(filename,"wt"))==NULL)
{
printf("Cannot open file strike any key exit!");
exit(1);
}
ch=getchar(); /*用来吸收scanf函数最后输入的回车符*/
while(ptr != NULL)
{
fprintf(fp,"%10d

%10d %11s %8d\n",ptr->znum,ptr->zmark,ptr->date,ptr->amount);
ptr=ptr->next;
}
fclose(fp);
printf("保存文件成功!\n");
getch();
return 0;
}


void printmess(struct information *head)
{
int i,j;
char s1[10],s2[10];
int report[5][6]={0};
struct information *ptr=head;
struct clerk *p=cle;
struct product *q=prod;
system("cls"); /*清屏*/
printf("请输入您要查询的起止时间与截止时间(格式为YYYY-XX-DD)(回车间隔)\n");
getchar();
gets(s1);
gets(s2);
while(ptr!=NULL)
{
/*将对应日期内销售数量累加到报表相应位置*/
if((strcmp(ptr->date,s1)>=0)&&(strcmp(ptr->date,s2)<=0))
{
for(i=0;i<4;i++)
{
if(ptr->znum == p[i].num)
break;
}
for(j=0;j<5;j++)
{
if(ptr->zmark == q[j].mark)
break;
}
report[i][j] += ptr->amount;
}
ptr=ptr->next;
}
/*横竖向汇总*/
for(i=0;i<5;i++)
{
for(j=0;j<4;j++)
report[4][i]+=report[j][i];
}

for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
report[i][5] +=report[i][j];
}
printf("****************************销售统计报表****************************************\n");
printf(" 产品代号 销售之和 \n");
printf("销售员代号 ");
for(i=0;i<5;i++)
printf("%10d",q[i].mark);
printf("\n");
for(i=0;i<5;i++)
{
if(i<4)
printf("%10d ",p[i].num);
else
printf("每种产品之和 ");
for(j=0;j<6;j++)
{
printf("%10d",report[i][j]);
}
if(i<4)
printf("\n");
else
printf(" 总和\n");
}
getchar();
}


相关文档
相关文档 最新文档