• PUDN用户
    了解作者
  • C/C++
    开发工具
  • 2KB
    文件大小
  • rar
    文件格式
  • 0
    收藏次数
  • 1 积分
    下载积分
  • 560
    下载次数
  • 2005-11-26 14:15
    上传日期
C语言编写的电话计费系统大作业,调用系统时间函数,对电话系统摸拟的很接近
C仿真电话计费系统.rar
  • 电话计费系统.CPP
    9.3KB
  • www.pudn.com.txt
    218B
内容介绍
#include<stdio.h> #include<time.h> #include<math.h> struct call1 {int tel; time_t t1; //先定义这个结构体,这个是系统的函数,就是取时间的。 time_t t2; double charge; double timedi; }; struct call1 c1[50]; struct call2 {int tel; time_t t1; time_t t2; double charge; double timedi; }; struct call2 c2[50]; struct call3 {int tel; time_t t1; time_t t2; double charge; double timedi; }; struct call3 c3[50]; struct income {int k; double time; double tincome;}; struct income in[24]; struct charge {int tel; char name[30]; double timeloc; double timedom; double tcharge;}; struct charge client[50]; double charge1(time_t t1,time_t t2) { double t,charge,n; t=difftime(t2,t1); n=ceil(t/60); if(n<=3) charge=0.22; else charge=0.22+0.11*(n-3); return(charge); } double charge3(time_t t1,time_t t2) {float n,m; double t,charge; t=difftime(t1,t2); n=ceil(t/60);m=ceil(t/6); if(n<=3) charge=0.22+0.03*m; else charge=0.03*m+0.22+0.11*(n-3); return(charge);} void main(void) {int r,s,tel,i=0,j=0,k=0; int holiday[7][2]; time_t temp; double td; int x,y,h,temp1,l,u=0; int v,mon,d,q,m,n,t,f; int a1,a2,a3,b1,b2,b3; struct tm *star; //这个要定义一下,就是前面要有一个指针,使得下面的 double temp2,temp3; holiday[0][0]=1;holiday[0][1]=1; holiday[1][0]=3;holiday[1][1]=8; holiday[2][0]=5;holiday[2][1]=1; holiday[3][0]=5;holiday[3][1]=9; holiday[4][0]=7;holiday[4][1]=1; holiday[5][0]=8;holiday[5][1]=1; holiday[6][0]=10;holiday[6][1]=1; printf("\n welcome to the systerm of telephone!!!"); printf("\n please read those belows:"); while(q!=6) {printf("\n 1:set up basic information of clients"); printf("\n 2:make a call"); printf("\n 3:statistic of income for telecommunication company"); printf("\n 4:the sequence of income"); printf("\n 5:print the charge for clients:"); printf("\n 6:leave!"); printf("\n input your choice:\n"); scanf("%d",&q); if(q==1) {for(x=0;x<50;x++) {printf("\n please input telephone number"); printf("\n if you want leave,input 0 : "); scanf("%d",&l); if(l==0) break; client[x].tel=l; printf("\n please input client's name:"); scanf("%s",client[x].name);} v=x; for(x=0;x<v;x++) {printf("\n tel name"); printf("\n%d %s",client[x].tel,client[x].name);}} if(q==2) {printf("\nchoose the following:"); printf("\n1:local city:"); printf("\n2:domestic:"); printf("\n3:IP:\n"); scanf("%d",&r); if(r==0)break; if(r==1){ u=0; printf("\ninput your tel number:"); scanf("%d",&tel); c1[i].tel=tel; printf("\ninput 4 if begin:"); scanf("%d",&s); if(s==4) {c1[i].t1=time(NULL); //令前面定义的t1取系统时间 printf("\ninput 5 if end:"); scanf("%d",&s); if(s==5) {c1[i].t2=time(NULL); td=difftime(c1[i].t2,c1[i].t1); c1[i].timedi=td; star=localtime(&c1[i].t1); //把这个改成日期 取day用mday,就是月里的天数。而且在取月是,一月是零要注意 printf("\nyou begin at:%02d:%02d:%02d",star->tm_hour,star->tm_min,star->tm_sec); //这里的hour min sec要改为mday year month 就可以了 star=localtime(&c1[i].t2); printf("\nyou end at :%02d:%02d:%02d",star->tm_hour,star->tm_min,star->tm_sec); c1[i].charge=charge1(c1[i].t1,c1[i].t2); for(x=0;x<7;x++) {if((star->tm_mon+1)==holiday[x][0]&&(star->tm_mday)==holiday[x][1]) {c1[i].charge=0.5*c1[i].charge; printf("\nholiday today, your charge is half:"); printf("\n %d %f %f",c1[i].tel,c1[i].timedi,c1[i].charge); u=1;}} if(u==0) printf("\n%d %f %f",c1[i].tel,c1[i].timedi,c1[i].charge); i=i+1;}}} else if(r==2) { u=0; printf("\ninput your tel number:"); scanf("%d",&tel); c2[j].tel=tel; printf("\ninput 4 if begin:"); scanf("%d",&s); if(s==4) {c2[j].t1=time(NULL); printf("\ninput 5 if end:"); scanf("%d",&s); if(s==5) {c2[j].t2=time(NULL); td=difftime(c2[j].t2,c2[j].t1); c2[j].timedi=td; star=localtime(&c2[j].t1); a1=star->tm_hour; a2=star->tm_min; a3=star->tm_sec; printf("\nyou begin at:%02d:%02d:%02d",star->tm_hour,star->tm_min,star->tm_sec); star=localtime(&c2[j].t2); b1=star->tm_hour; b2=star->tm_min; b3=star->tm_sec; printf("\nyou end at :%02d:%02d:%02d",star->tm_hour,star->tm_min,star->tm_sec); if(a1>=0&&a1<7&&b1>=7) {t=3600*7-a1*3600-a2*60-a3; f=b1*3600+b2*60+b3-3600*7; n=ceil(t/6)+1; m=ceil(f/6)+1; c2[j].charge=0.5*0.07*n+0.07*m;} if(a1>=0&&a1<7&&b1<7) {n=ceil(td/6); c2[j].charge=0.5*0.07*n;} if(a1>=7&&b1<24) {n=ceil(td/6); c2[j].charge=0.07*n;} if(a1>=7&&b1>=0&&b1<7) {t=3600*24-a1*3600-a2*60-a3; f=b1*3600+b2*60+b3; n=ceil(t/6)+1; m=ceil(f/6)+1; c2[j].charge=0.07*n+0.5*0.07*m;} for(x=0;x<7;x++) {if((star->tm_mon+1)==holiday[x][0]&&(star->tm_mday)==holiday[x][1]) {n=ceil(td/6); c2[j].charge=0.5*n*0.07; printf("\nholiday today, your charge is half:"); printf("\n%d %f %f",c2[j].tel,c2[j].timedi,c2[j].charge); u=1;}} if(u==0) printf("\n%d %f %f",c2[j].tel,c2[j].timedi,c2[j].charge); j=j+1;}}} if(r==3){u=0; printf("\ninput your tel number:"); scanf("%d",&tel); c3[k].tel=tel; printf("\ninput 4 if begin:"); scanf("%d",&s); if(s==4) {c3[k].t1=time(NULL); printf("\ninput 5 if end:"); scanf("%d",&s); if(s==5) {c3[k].t2=time(NULL); td=difftime(c3[k].t2,c3[k].t1); c3[k].timedi=td; star=localtime(&c3[k].t1); printf("\nyou begin at:%02d:%02d:%02d",star->tm_hour,star->tm_min,star->tm_sec); star=localtime(&c3[k].t2); printf("\nyou end at :%02d:%02d:%02d",star->tm_hour,star->tm_min,star->tm_sec); c3[k].charge=charge3(c3[k].t2,c3[k].t1); for(x=0;x<7;x++) {if((star->tm_mon+1)==holiday[x][0]&&(star->tm_mday)==holiday[x][1]) {c3[k].charge=0.5*c3[k].charge; printf("\nholiday today, your charge is half:"); printf("\n%d %f %f",c3[k].tel,c3[k].timedi,c3[k].charge); u=1;}} if(u==0) printf("\n%d %f %f",c3[k].tel,c3[k].timedi,c3[k].charge); k=k+1;}}}} if(q==3) {for(y=0;y<24;y++) {in[y].time=0; in[y].tincome=0; in[y].k=y; } for(y=0;y<24;y++) { for(x=0;x<i;x++) {star=localtime(&c1[x].t1); h=star->tm_hour; if(h==y) {in[y].time+=c1[x].timedi; in[y].tincome=c1[x].charge;}}} for(y=0;y<24;y++) {for(x=0;x<j;x++) {star=localtime(&c2[x].t1); h=star->tm_hour; if(h==y) {in[y].time+=c2[x].timedi; in[y].tincome+=c2[x].charge;}}} for(y=0;y<24;y++) {for(x=0;x<k;x++) {star=localtime(&c3[x].t1); h=star->tm_hour; if(h==y) {in[y].time+=c3[x].timedi; in[y].tincome+=c3[x].charge;}}} printf("\ntime totaltime totalincome"); printf("\n----------------------------------------------"); for(x=0;x<24;x++) printf("\n%02d %f %f", in[x].k,in[x].time,in[x].tincome);} if(q==4) {for(x=1;x<24;x++) for(y=0;y<23;y++) {if(in[y].time>in[y+1].time) {temp1=in[y].k; in[y].k=in[y+1].k; in[y+1].k=temp1; temp2=in[y].time; in[y].time=in[y+1].time; in[y+1].time=temp2; temp3=in[y].tincome; in[y].tincome=in[y+1].tincome; in[y+1].tincome=temp3;
评论
    相关推荐