⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 design.c

📁 优惠计划是电信企业在市场营销拓展计划和企业利润评估指导下
💻 C
📖 第 1 页 / 共 2 页
字号:
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<conio.h>

struct BasicBill            /*话单信息结构*/   
{
	int custId;             /*客户编码    */
	char userNbr[20];       /*用户号码    */
	double localFee;        /*市话费用    */
	double ldFee;           /*长话费用    */
}*basicBillList=NULL;       /*声明结构体,定义基础账单动态结构体数组*/

struct Cust                 /*客户信息结构*/ 
{           
	int custId;             /*客户编码    */
	char custName[50];      /*客户名称    */
	int localRuleId;        /*市话规则编码*/
    int ldRuleId;           /*长话规则编码*/
	char repartType;        /*结果摊分方式*/
}*custList=NULL;            /*声明结构体,定义客户动态结构体数组*/

struct DisctRule            /*优惠规则结构*/
{
	int ruleId;             /*规则编码    */
	char ruleType;          /*规则类型    */
	int lowerLimit;         /*优惠下限    */
	int upperLimit;         /*优惠上限    */
	double disctRate;       /*优惠折扣率  */
}*disctRuleList=NULL;       /*声明结构体,定义优惠规则动态结构体数组*/

struct UserBill             /*用户帐单*/
{
	int custId;             /*客户编码*/
	char custName[50];      /*客户名称*/ 
	char userNbr[20];       /*用户号码*/
	double localFormerFee;  /*市话原费用*/
	double localDisctFee;   /*市话优惠结果*/
	double ldFormerFee;     /*长话原费用*/  
	double ldDisctFee;      /*长话优惠结果*/
	double disctFee;        /*优惠后费用合计*/
}*userBillList=NULL;        /*声明结构体,定义用户帐单动态结构体数组*/

struct CustBill             /*客户帐单*/
{
	int custId;             /*客户编码*/
	char custName[50];      /*客户名称*/
	double localFee;        /*市话费用小计*/
	double ldFee;           /*长话费用小计*/
	double Fee;             /*费用合计*/ 
}*custBillList=NULL;        /*声明结构体,定义客户帐单动态结构体数组*/

int line1=0;                /*向系统申请的内存空间的数目*/
int line2=0;                /*向系统申请的内存空间的数目*/
int line3=0;                /*向系统申请的内存空间的数目*/
/* 
   
   函数功能:装载基础帐单资料,建立基础帐单结构数组,显示基础帐单
   函数参数:无
   函数返回值:无

*/
void loadBasicBill()        
{	
	FILE *fp;	                                                                    /*文件句柄*/ 
	int line=0;                                                                     /*记录文件的行数*/
	int i=0;                                                                        /*基础帐单结构数组的下标*/
	char ch;                                                                        /*读取字符*/
              
    /*打开文件*/
	if((fp=fopen("BasicBill.txt","r"))==NULL)
	{	
		printf("cannot open file\n");	
		exit(0);
	}
	while(!feof(fp))
	{
		ch=fgetc(fp);
		if(ch=='\n')
			line++;
	}
	line1=line;
	basicBillList=(struct BasicBill *)calloc(line1,sizeof(struct BasicBill));       /*申请动态内存*/
	userBillList=(struct UserBill *)calloc(line1,sizeof(struct UserBill));          /*申请动态内存*/
	rewind(fp);
    /*从fp读入数据*/
	while(!feof(fp))
	{	
		fscanf(fp,"%d %s %lf %lf",
			&basicBillList[i].custId,
			basicBillList[i].userNbr,
			&basicBillList[i].localFee,	
			&basicBillList[i].ldFee
			);

		i++;
	}
	/*关闭文件*/
	fclose(fp);
    /*输出基础帐单*/
	printf("The basicbill:\n\n");
	printf("客户编码  用户号码    市话费用	长话费用 \n");

	for(i=0;i<line1;i++)
		printf("    %d	  %s    %g	%g\n",
		basicBillList[i].custId,
		basicBillList[i].userNbr,
		basicBillList[i].localFee,
		basicBillList[i].ldFee
		);
	printf("\n\n\n");
}
/* 
   
   函数功能:装载客户资料,建立客户结构数组,显示客户初始帐单
   函数参数:无
   函数返回值:无

*/
void loadCustInfo()
{
	FILE *fp;                                                                       /*文件句柄*/
	int line=0;                                                                     /*记录文件的行数*/
	int i=0;                                                                        /*客户结构数组的下标*/
	char ch;                                                                        /*读取字符*/
	/*打开文件*/
	if((fp=fopen("CustInfo.txt","r"))==NULL)
	{
		printf("cannot open file\n");
		exit(0);
	}
	while(!feof(fp))
	{
		ch=fgetc(fp);
		if(ch=='\n')
			line++;
	}
	line2=line;
	custList=(struct Cust *)calloc(line2,sizeof(struct Cust));                      /*申请动态内存*/
	custBillList=(struct CustBill *)calloc(line2,sizeof(struct CustBill));          /*申请动态内存*/
	rewind(fp);
	/*从fp读入数据*/
	while(!feof(fp))
	{
		fscanf(fp,"%d %s %d %d %c",
			&custList[i].custId,
			custList[i].custName,
			&custList[i].localRuleId,
			&custList[i].ldRuleId,            
			&custList[i].repartType
			);
		i++;
	}
	/*关闭文件*/
	fclose(fp);
	/*输出客户信息*/
	printf("The custList:\n\n");
	printf("客户编码  客户名称  市话规则编码  长话规则编码	结果摊分方式\n");
	for(i=0;i<line2;i++)		
		printf("    %d	  %s  	 %d		%d		%c\n",
		custList[i].custId,	
		custList[i].custName,	
		custList[i].localRuleId,	
		custList[i].ldRuleId,    
		custList[i].repartType
		);
	printf("\n\n\n");

}
/* 
   
   函数功能:装载优惠规则,建立优惠规则结构数组,显示优惠规则
   函数参数:无
   函数返回值:无

*/
void loadDisctRule()
{
	FILE *fp;																		/*文件句柄*/
    int line=0;                                                                     /*记录文件的行数*/
	int i=0;                                                                        /*优惠规则结构数组的下标*/
	char ch;                                                                        /*读取字符*/
	/*打开文件*/
	if((fp=fopen("DisictRule.txt","r"))==NULL)
	{
		printf("cannot open file\n");
		exit(0);
	}
	while(!feof(fp))
	{
		ch=fgetc(fp);
		if(ch=='\n')
			line++;
	}
	line3=line;
	disctRuleList=(struct DisctRule *)calloc(line3,sizeof(struct DisctRule));       /*申请动态内存*/
	rewind(fp);
	/*从fp读入数据*/
	while(!feof(fp))
	{
		fscanf(fp,"%d %c %d %d %lf",
			&disctRuleList[i].ruleId,
			&disctRuleList[i].ruleType,
			&disctRuleList[i].lowerLimit,
			&disctRuleList[i].upperLimit,            
			&disctRuleList[i].disctRate
			);
		i++;
	}
	/*关闭文件*/
	fclose(fp);
	/*输出优惠计算规则*/
	printf("The DisctRule:\n\n");
	printf("规则编码 规则类型 优惠下限 优惠上限 优惠折扣率\n");
	for(i=0;i<line3;i++)
		printf("   %d	    %c	  %d	   %d	    %g\n",
		disctRuleList[i].ruleId,	
		disctRuleList[i].ruleType,	
		disctRuleList[i].lowerLimit,	
		disctRuleList[i].upperLimit,    
		disctRuleList[i].disctRate
		);
	printf("\n\n\n");
}
/*    
   函数功能:直接折扣计算优惠
   函数参数:双精度型变量f,表示话费
            结构体变量d,表示话费优惠计算规则编码
   函数返回值:话费优惠结果

*/
double simpleDisct(double f,struct DisctRule d)
{
	return f*d.disctRate;                                                           /*返回打折值*/

}
/* 
   
   函数功能:封顶保底计算优惠
   函数参数:双精度型变量f,表示话费
            结构体变量d,表示话费优惠计算规则编码
   函数返回值:话费优惠结果

*/
double boundDisct(double f,struct DisctRule d)
{
	if(f<d.lowerLimit)
		return d.lowerLimit;                                                        /*返回优惠下限*/
	else if(f>d.upperLimit)
		return d.upperLimit;														/*返回优惠上限*/
	return f;																	    /*返回原话费*/
}
/* 
   
   函数功能:保底打折计算优惠
   函数参数:双精度型变量f,表示话费
            结构体变量d,表示话费优惠计算规则编码
   函数返回值:话费优惠结果

*/
double baseDisct(double f,struct DisctRule d)
{
	if(f<d.lowerLimit)
		return d.lowerLimit;                                                        /*返回优惠下限*/
	else if(f>d.upperLimit)
		return d.upperLimit+(f-d.upperLimit)*d.disctRate;                           /*返回保底打折值*/
	return f;																	    /*返回原话费*/
}
/* 
   
   函数功能:优惠结果摊分
   函数参数:结构体变量c,表示一个客户
            结构体变量cb,表示该客户的帐单
			结构体数组ub[],表示用户帐单
   函数返回值:无

*/
void repartDisctResult(struct Cust c,struct CustBill cb,struct UserBill ub[])
{
	double disct1=0;                                                                /*客户市话优惠额*/
	double disct2=0;                                                                /*客户长话优惠额*/
	double formerFee1=0;                                                            /*客户市话原费用*/
	double formerFee2=0;                                                            /*客户长话原费用*/
	double temp1[100];                                                              /*客户的用户市话原费用*/
	double temp2[100];                                                              /*客户的用户长话原费用*/  
	int i;                                                                          /*用户帐单结构数组的下标*/
	int j=0;                                                                        /*用户原费用temp结构数组的下标*/
	int count=0;                                                                    /*客户的用户数*/

	for(i=0;i<line1;i++)
	{
		if(ub[i].custId==c.custId)                                                  /*查找用户*/
		{	
		formerFee1+=ub[i].localFormerFee;                                           /*计算客户市话原费用*/
		formerFee2+=ub[i].ldFormerFee;                                              /*计算客户长话原费用*/
		temp1[count]=ub[i].localFormerFee;                                          /*存储客户的用户市话原费用*/
		temp2[count]=ub[i].ldFormerFee;                                             /*存储客户的用户长话原费用*/
		count++;                                                                    /*计算客户的用户数*/		
		}
	}
		
	disct1=formerFee1-cb.localFee;                                                  /*计算客户市话优惠额*/
	disct2=formerFee2-cb.ldFee;                                                     /*计算客户长话优惠额*/

	for(i=0;(i<line1)&&(j!=count);i++)	                                            /*各用户分析过后,结束循环*/		
	{
		if(ub[i].custId==c.custId)	                                                /*查找用户*/
		{
			j++;                                                                    /*记录已计算过的用户数*/	
			switch(c.repartType)                                                    /*选择摊分方式*/
			{
			case 'X':                                                               /*平均分摊*/
				ub[i].localDisctFee=temp1[j-1]-(disct1/count);                      /*计算用户的市话优惠结果*/
				ub[i].ldDisctFee=temp2[j-1]-(disct2/count);                         /*计算用户的长话优惠结果*/
				break;
			case 'Y':                                                               /*按比例分摊*/
				ub[i].localDisctFee=temp1[j-1]-(disct1*temp1[j-1]/formerFee1);      /*计算用户的市话优惠结果*/
				ub[i].ldDisctFee=temp2[j-1]-(disct2*temp2[j-1]/formerFee2);         /*计算用户的长话优惠结果*/
				break;
			default:
				printf("RepartType Error!\n");                                      /*处理非法数据*/
			}
		}		
		ub[i].disctFee=ub[i].localDisctFee+ub[i].ldDisctFee;	                    /*用户的优惠后费用合计*/
	}	
}


/* 
   
   函数功能:客户优惠行为分析
   函数参数:结构体数组b[],表示基础帐单
            结构体数组c[],表示客户
			结构体数组d[],表示优惠规则
			结构体数组ub[],表示用户帐单
			结构体数组cb[],表示客户帐单
   函数返回值:无

*/
void analyseCustDisct(struct BasicBill b[],struct Cust c[],struct DisctRule d[],struct UserBill ub[],struct CustBill cb[])
{	
	int l=0;                                                                        /*用户帐单结构数组的下标*/
	int i;                                                                          /*客户结构数组及客户帐单结构数组的下标*/
	int j;                                                                          /*基础帐单结构数组的下标*/
	int k;                                                                          /*优惠规则结构数组的下标*/
	int kind;                                                                       /*用户的话费种数*/
	int count;                                                                      /*客户的用户数*/

	for(i=0;i<line2;i++)	
	{
		count=0;
		/*建立客户账单结构数组*/
		cb[i].custId=c[i].custId;
		strcpy(cb[i].custName,c[i].custName);
		cb[i].localFee=0;
		cb[i].ldFee=0;	
		cb[i].Fee=0;
		for(j=0;j<line1;j++)
		{	
			if(b[j].custId==c[i].custId)                                            /*查找基础帐单*/
			{
				count++;
				/*建立用户账单结构数组*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -