基本功能:
(1).统计每天公园里的收费情况
(2).可以自动计算应收费用,一次购票人数>=30人,票价4元,<30人票价5 元,可以实现最优价选择(比如,28个人,按5元买28张,不如按4元买30张)。
(3).可以查询一月里任一天的收费情况。
(4).可查询一月里收费最好和最差的一天的情况。
(5).综合一年里的收费最好和最差的月份情况。得出此年入园最旺时段。
我已有了答案
若有人与我同样遇到了这类题,提供给你们
谨参考,编译链接测试成功,源代码如下:
#include"stdlib.h"
#include"stdio.h"
#include"dos.h"
main(){
struct date te;
int shoufei(int renshu);
void tongjishoufei(int month, int day,int cash,int a[][31]);
int chaxun(int month, int day,int a[][31]);
int tianshu(int month,int year);
void chaxunmonth(int month,int a[][31],int year);
void chaxunwangji(int b[]);
void save(int a[][31],int b[]);
void load(int a[][31],int b[]);
void mymy(int dd,int mm,int a[][31]);
int month ,day ,year,mon,i,j,k=1,cash,t,m,renshu,ye,mm,dd,me;
char n;
int a[12][31],b[12];
for(i=0;i<12;i++)
for (j=0;j<31;j++)
a[i][j]=0;
for(i=0;i<12;i++)
b[i]=0;
getdate(&te);
month=te.da_mon;day=te.da_day;
load(a,b);
while(k){
printf("1,计算票价;\n");
printf("\n");printf("\n");
printf("2,查询当天收入;\n");
printf("\n");printf("\n");
printf("3,查询某月收入;\n");
printf("\n");printf("\n");
printf("4,查询旺季;\n");
printf("\n");printf("\n");
printf("5,查询某月某天;\n");
printf("\n");printf("\n");
printf("6,退出!\n");
printf("请输入选项:");
scanf("%c",&n);
me=n-'0';
switch(me)
{case 1:printf("请输入人数");scanf("%d",&renshu);cash=shoufei(renshu);b[month]+=cash;
tongjishoufei(month,day,cash,a);getch();break;
case 2:chaxun(month,day,a);getch();break;
case 3:printf("请输入月年");scanf("%d,%d",&mon,&ye);chaxunmonth(mon,a,ye);getch();break;
case 4:chaxunwangji(b);getch();break;
case 6:save(a,b);printf("退出\n");k=0;break;
case 5:scanf("%d,%d",&mm,&dd);mymy(dd,mm,a);getch();break;
default : printf("请输入正确的选项!(1-5)6为退出!\n");break;
}
}
}
int shoufei(int renshu)
{
if(renshu<24) {printf("5 元 %d 张,总价%d",renshu,5*renshu);printf("\n");return 5*renshu;}
else if(renshu>30) {printf("4 元 %d 张,总价%d",renshu,4*renshu);printf("\n");return 4*renshu;}
else {printf("4 元 %d 张,总价%d",renshu,120);printf("\n");return 120;}
}
void tongjishoufei(int month, int day,int cash,int a[][31])
{
a[month-1][day-1]=a[month-1][day-1]+cash;
}
int chaxun(int month, int day,int a[][31])
{
printf("%d月%d日 总收入 %d",month,day,a[month-1][day-1]);printf("\n"); return 1;
}
int tianshu(int month,int year)
{int uu;
switch(month)
{case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:uu=31 ;break;
case 4:
case 6:
case 9:
case 11:uu=30;break;
case 2:if(year%400==0||year%4==0) uu=29 ;else uu=28;
}
return uu;
}
void chaxunmonth(int month,int a[][31],int year)
{
int yday,k,max,min;
yday=tianshu(month,year);
max=min=a[month-1][0];
for (k=0;k<yday;k++)
{
if (max<a[month-1][k]) max=a[month-1][k];
if (min>a[month-1][k]) min=a[month-1][k];
}
printf("最大收入=%d,最小收入=%d",max,min);printf("\n");printf("\n");
}
void chaxunwangji(int b[])
{int o,max,min,ij,ih;
max=min=b[0];
for (o=0;o<12;o++)
{if(max<b[o]) {max=b[o];ij=o;}
if(min>b[o]) min=b[o];
}
printf("%d月收入最高的月=%d,%d月收入最低的月=%d",ij,max,o,min);printf("\n");printf("\n");
}
void save(int a[][31],int b[])
{
int ia,ib;
FILE *fp;
FILE *fp1;
fp=fopen("data_1","wb");
if(!fp) printf("error save\n");
for(ia=0;ia<12;ia++)
for (ib=0;ib<31;ib++)
if(fwrite(&a[ia][ib],sizeof(int),1,fp)!=1)
printf("file write error\n");
fclose(fp);
fp1=fopen("data_2","wb");
if(!fp1) printf("error save\n");
for(ia=0;ia<12;ia++)
if(fwrite(&b[ia],sizeof(int),1,fp1)!=1)
printf("file write error\n");
fclose(fp1);}
void load(int a[][31] ,int b[])
{
FILE *fp;
FILE *fp1;
int ia=12,ib=31;
fp=fopen("data_1","rb");
if(!fp) printf("error load");
for(ia=0;ia<12;ia++)
for (ib=0;ib<31;ib++)
if(fread(&a[ia][ib],sizeof(int),1,fp)!=1)
{
if(feof(fp)) {fclose(fp);}
printf("error load\n");}
fclose(fp);
fp1=fopen("data_2","rb");
if(!fp1) printf("error load");
for(ia=0;ia<12;ia++)
if(fread(&b[ia],sizeof(int),1,fp1)!=1)
{
if(feof(fp1)) {fclose(fp1);}
printf("error load\n");}
fclose(fp1);}
void mymy(int dd,int mm,int a[][31])
{printf("%d\n",a[mm-1][dd-1]);
}