国际、国内、市话的电话号码识别,我没有写。
你想写,只要在我留的函数getcallType里写代码就行,其他不用改。参数:主叫号码 、 被叫号码。返回值:0或1或2,对应(国际、国内、市话)。
另外,输入我没有写验证,测试请规范输入,时间必须2位数hh:mm:ss,你想写验证证,自己添加到我的函数inputInfo中就行。
#include<stdio.h>#include<stdlib.h>
#include<malloc.h>
#define n 6//输入次数
typedef struct callInfo
{
char calldate[11]//通唯正话日期
char callCode[15]//主叫码
char beCallCode[15]//被叫码
char beginTime[10]//起始时间
char endTime[10]//通话结束时间
long callTime//通话时长,单位秒
double callPay//通话费用
int callType//国际长途:0,国内长途:1,市话:2
struct callInfo *next
}CALLINFO
CALLINFO *inputInfo(int con)//输入,参数con:输入的次数 返回首节点
void prfCallInfo(CALLINFO *callInfoHead)//打印链表
long getTime(char *beginTime,char *endTime)//计算通话时长,返回秒数,时间格式:小时:分钟:秒
double getpay(long t,int callType)//计算费用,不足1分钟按1分钟算
int getcallType(char *callCode,char *beCallCode)//通过主叫号码 和 被叫号码,识别通话类别(国际、国内、市话),返回0或1或2。
void orderByPay(CALLINFO *callInfoHead)//排序 话费从高到低
void wirteFile(FILE *fp,CALLINFO *callInfoHead)
int main()
{
CALLINFO *callInfoHead=NULL
FILE *fp=NULL
callInfoHead=(CALLINFO *)malloc(sizeof(CALLINFO))
callInfoHead->next=NULL
fp=fopen("c:\\list2.txt","rt+")
if(fp==NULL)
{
fp=fopen("c:\\list2.txt","w")
}
callInfoHead->next=inputInfo(n)
printf("\n----测试代码所有费用默认按照市话计算----\n")
orderByPay(callInfoHead)
printf("\n----按照话费由高到低游山模排序----\n")
prfCallInfo(callInfoHead)
printf("\n----开始写入文件----\n")
wirteFile(fp,callInfoHead)
return 0
}
void wirteFile(FILE *fp,CALLINFO *callInfoHead)
{
CALLINFO *callInfoNow=NULL
fseek(fp, 0, SEEK_SET)//文件流指针重置到开头
fprintf(fp,"%s %s %s 神缓%s %s\n","日期","主叫号码","被叫号码","起始时间","通话时间")
while(callInfoHead->next!=NULL)
{
callInfoNow=callInfoHead->next
fprintf(fp,"%s %s %s %s %s\n",callInfoNow->calldate,callInfoNow->callCode,callInfoNow->beCallCode,callInfoNow->beginTime,callInfoNow->endTime)
callInfoHead=callInfoHead->next
}
}
void orderByPay(CALLINFO *callInfoHead)//排序 话费从高到低
{
CALLINFO *callInfoNext=NULL,*callInfoNow=NULL,callInfoSave
while(callInfoHead->next!=NULL)
{
callInfoNext=callInfoHead->next->next
callInfoNow=callInfoHead->next
while(callInfoNext!=NULL)
{
if(callInfoNow->callPay<callInfoNext->callPay)//高的往前移动,交换成员值保留链表指针
{
callInfoSave=*callInfoNow
*callInfoNow=*callInfoNext
*callInfoNext=callInfoSave
callInfoNext->next=callInfoNow->next
callInfoNow->next=callInfoSave.next
}
callInfoNext=callInfoNext->next
}
callInfoHead=callInfoHead->next
}
}
void prfCallInfo(CALLINFO *callInfoHead)//打印链表
{
CALLINFO *callInfoNow=NULL
printf("\n通话日期 主叫码 被叫码 起始时间 通话结束时间 通话时长 通话费用\n")
while(callInfoHead->next!=NULL)
{
callInfoNow=callInfoHead->next
printf("%s %s %s %s %s %ld %lf\n",callInfoNow->calldate,callInfoNow->callCode,callInfoNow->beCallCode,callInfoNow->beginTime,callInfoNow->endTime,callInfoNow->callTime,callInfoNow->callPay)
callInfoHead=callInfoHead->next
}
}
CALLINFO *inputInfo(int con)//输入,参数con:输入的次数 返回首节点
{
int i
CALLINFO *callInfo0=NULL,*callInfoTail=NULL,*callInfoNew=NULL
printf("请分别录入%d条通话记录,每行1条\n格式:(通话日期、主叫码、被叫码、起始时间、通话时间)\n",con)
for(i=0i<coni++)
{
callInfoNew=(CALLINFO *)malloc(sizeof(CALLINFO))
scanf("%s%s%s%s%s",callInfoNew->calldate,callInfoNew->callCode,callInfoNew->beCallCode,callInfoNew->beginTime,callInfoNew->endTime) //输入我没有写验证,想写验证添加在这
callInfoNew->callTime=getTime(callInfoNew->beginTime,callInfoNew->endTime)//时间
callInfoNew->callType=getcallType(callInfoNew->callCode,callInfoNew->beCallCode)
callInfoNew->callPay=getpay(callInfoNew->callTime,callInfoNew->callType)//费用
callInfoNew->next=NULL
if(callInfo0==NULL)
callInfo0=callInfoNew
else
callInfoTail->next=callInfoNew
callInfoTail=callInfoNew
}
return callInfo0
}
long getTime(char *beginTime,char *endTime)//计算通话时长,返回秒数,时间格式24制:小时:分钟:秒
{
int h1,m1,s1,h2,m2,s2
long t
h1=(beginTime[0]-'0')*10+beginTime[1]-'0'
m1=(beginTime[3]-'0')*10+beginTime[4]-'0'
s1=(beginTime[6]-'0')*10+beginTime[7]-'0'
h2=(endTime[0]-'0')*10+endTime[1]-'0'
m2=(endTime[3]-'0')*10+endTime[4]-'0'
s2=(endTime[6]-'0')*10+endTime[7]-'0'
t=(h2-h1)*60*60+(m2-m1)*60+(s2-s1)
return t
}
int getcallType(char *callCode,char *beCallCode)//通过主叫号码 和 被叫号码,识别通话类别(国际、国内、市话),返回0或1或2。
{
//我没写,你需要自己写,测试代码默认返回类别2,市话
return 2
}
double getpay(long t,int callType)//计算费用,不足1分钟按1分钟算
{
//(1) 国际长途1.00元/分钟,(2) 国内长途0.60元/分钟,(3) 市话前3分钟0.20元,3分钟以后0.10元/分钟。
double callpay
if(t%60!=0)
t=t/60+1
else
t=t/60
if(callType==0)
callpay=t*1
if(callType==1)
callpay=t*0.6
if(callType==2)
{
if(t<=3)
callpay=t*0.2
else
callpay=3*0.2+(t-3)*0.1
}
return callpay
}
方法一:1找到VS2010的快捷方式:右击——“打开文件位置”
找到VS2010的启动项目devenv.exe:右击——属性——兼容性——特权等级,以管理员权限运行;如果需要每个用户答返搜都以管理员权限运行,还可以“更改所有用户的设置”——特权等级,以管理员权限运行。
然后在项目的打开方式中确保以VS2010为默认打开程序就好了。
2 属性--连接器--清单文件-》UAC执行级别-》requireAdministrator (/level='requireAdministrator')
方法二
清单文件:建立如app.mainfest的清清历单文件,在项目(属性--连接器--清单文件)添加清单文件
<?xml version="1.0" encoding="UTF-8" standalone="世氏yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentityversion="1.0.0.0" processorArchitecture="X86" name="VistaLogoDemo" type="win32"/>
<description>Description of your application</description>
<!-- Identify the application security requirements.-->
<trustInfoxmlns="urn:schemas-microsoft-com:asm.v3">
<security>
<requestedPrivileges>
<requestedExecutionLevellevel="requireAdministrator" uiAccess="false"/>
</requestedPrivileges>
</security>
</trustInfo>
</assembly>
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)