病毒测试程序.docx
- 文档编号:9800255
- 上传时间:2023-05-21
- 格式:DOCX
- 页数:27
- 大小:497.42KB
病毒测试程序.docx
《病毒测试程序.docx》由会员分享,可在线阅读,更多相关《病毒测试程序.docx(27页珍藏版)》请在冰点文库上搜索。
病毒测试程序
软件综合课程设计
病毒测试程序
二〇一四年六月
病毒测试程序
1.问题称述
本题的任务是:
当整个网络被感染后,计算有多少台机器被某个特定变种所感染。
输入要求:
输入由若干组测试数据组成。
每组数据的第1行包含2个整数M和N(1≤M,N≤500),接下来是一个M*N的矩阵表示网络的初始感染状态,其中的正、负整数的意义如题目描述中所定义。
下面一行给出一个正整数Q,是将要查询的变种的个数。
接下去的Q行里,每行给出一个变种的类型。
当M或N为0时,表示全部测试结束,不要对该数据做任何处理。
输出要求:
对每一组测试,在一行里输出被某个特定变种所感染的机器数量。
2.程序代码
#include
#include
intiGlobal;//iGlobal:
表示每个二叉树中除叶子节点之外其他节点的数量
typedefstructtagNode
{
intiData;//iData:
二叉树中每个节点存储的数据
intiCount;//iCount:
二叉树中每个数据出现的次数
structtagNode*pLeft;
structtagNode*pRight;
}
Node;
Node*Add(Node*a,Node*pNow,intiVal)
{
if(iGlobal==0)
{
a[0].pLeft=a[0].pRight=NULL;
a[0].iCount=1;
a[0].iData=iVal;
++iGlobal;
}
else
{
if(pNow==NULL)
{
pNow=a+(iGlobal++);
pNow->pLeft=pNow->pRight=NULL;
pNow->iCount=1;
pNow->iData=iVal;
}
else
{
if(iVal
{
pNow->pLeft=Add(a,pNow->pLeft,iVal);
}
elseif(iVal==pNow->iData)
{
++pNow->iCount;
}
else
{
pNow->pRight=Add(a,pNow->pRight,iVal);
}
}
}
returnpNow;
}
Node*Find(Node*a,intiVal)
{
if(a==NULL)
{
returnNULL;
}
else
{
if(iVal
{
returnFind(a->pLeft,iVal);
}
elseif(iVal==a->iData)
{
returna;
}
else
{
returnFind(a->pRight,iVal);
}
}
}
intmain(void)
{
intm,n,i,q,temp;
Node*a=NULL;
Node*p=NULL;
FILE*fp;
if((fp=fopen("data.txt","r"))==NULL)
{
printf("Filenotfound!
\n");
return-1;
}
fscanf(fp,"%d%d",&m,&n);
do
{
iGlobal=0;
if((a=(Node*)malloc(m*n*sizeof(Node)))==NULL)
{
return-1;
}
for(i=0;i { fscanf(fp,"%d",&temp); Add(a,a,temp); } fscanf(fp,"%d",&q); for(i=0;i { fscanf(fp,"%d",&temp); p=Find(a,temp); if(p==NULL) { putchar('0'); } else { printf("%d",p->iCount); } if(i! =q-1) { putchar(''); } else { putchar('\n'); } } if(a! =NULL) { free(a); a=NULL; } fscanf(fp,"%d%d",&m,&n); } while(m! =0&&n! =0); return0; } 3.运行结果 4.设计体会与总结 通过的两周的课程设计的实训,使我初步认识的数据结构,可能在先前的数据结构学习中都是以理论为主,上机操作的机会很少,在这次完成大作业中遇到了各种各样的问题,这次我抽到的题目是《病毒测试程序》,一开始我看到这个题目的时候毫无头绪,不知该从哪里下手,后来通过询问同学,学长了解到了这题的中心的思想是二叉树,我通过翻阅书籍重新温习了二叉数,在编程的过程还是遇到了好多困难,但是我通过问同学,上网XX等方法解决了问题,这充分锻炼了我动手操作能力,这在我今后的工作学习中帮助会很大。 活期储蓄帐目管理 一、问题陈述 活期储蓄处理中,储户开户、销户、存入、支出活动频繁,系统设计要求: 1)能比较迅速地找到储户的帐户,以实现存款、取款记账; 2)能比较简单,迅速地实现插入和删除,以实现开户和销户的需要。 二、需求分析 (1)通过创建文件,存储数据通过用数组形式的方法,用户开户的时候可以自定义账户、密码、姓名和开户金额。 (2)当用户完成开户操作后,使用正确用户姓名、密码登入账号后可以进行存款、取款、修改密码和查询操作。 (3)如果要进行信息删除操作,只要输入正确的账户名和密码就能进行销户。 三、概要设计 在本次的课程设计方案中,数据的存储结构我是通过链表来实现的,所以存储结构我没有采用单链表的方法。 首先数据类型我用完构体来定义,然后数据按照数据结构存储,然后通过以前所学的文件的相关知识把更改的数据写到文件中,这样本次课程设计的方案就完成了。 四、详细设计 (1)数据类型定义 这次的系统是采用链式结构存储储蓄数据的系统结构。 节点定义如下 Structuser { Charname[20]; Intid; Charpassword[8]; Doublemoney } (2)系统主要子程序详细设计 1.用户如果想要开户只要输入姓名和6位密码,然后系统就会提示开户成功 账户开户函数: add(); 2.用户通过输入正确的账户名和密码就能登入管理系统 用户信息输入函数: getuser(); 3.如果用户登入账户,用户可以进行存取款和查询余额的操作,取款时若用户输入的数目超过账户上所存储的金额,系统会提示重新输入的字样。 存款函数: save_money();取款函数: get_money(); 查询余额函数(名字查询): select_name 4.如果用户需要销户账号,需要用户输入账号与密码,若账号存在,则删除该账号 销户函数: del();系统显示函数: display(); 五、程序代码 #include #include #include #include #definefile"temp.txt" structuser { intid; charname[20]; charpassword[6]; doublemoney; }; voidadd() { printf("%30s\n","***用户开户***"); printf("---------------------------------------------\n\n"); structusergetuser(); intcount(); FILE*fp; intnumber; structusertemp; if((fp=fopen(file,"ab"))==NULL) { printf("cannotopenfile! \n"); exit (1); } temp=getuser(); number=count(); temp.id=number+1; fwrite(&temp,sizeof(structuser),1,fp); printf("用户开户成功! \n"); fclose(fp); } intcount() { FILE*fp; intnum; structusertemp; num=0; if((fp=fopen(file,"rb"))==NULL) { printf("cannotopenfile! \n"); exit (1); } while(fread(&temp,sizeof(structuser),1,fp)){ num++; } fclose(fp); returnnum; } voidgetname(char*name) { do { scanf("%s",name); fflush(stdin); if(strlen(name)==0) printf("姓名不能为空! \n");elseif(strlen(name)>=20) printf("姓名不能超过20个字符! \n");else break; printf("重新输入姓名: "); } while (1); } voidgetpassword(char*password) { do { inti,j; charch; for(i=0,j=0;;i++) if((ch=getchar())! ='\n') { if(ch<='9'&&ch>='0') password[i]=ch; else { printf("密码只能是数字! \n");j=1; break; } } else break; password[i]='\0'; if(j==1) continue; if(strlen(password)! =6) printf("密码只能是6位! \n");else break; printf("重新输入密码: "); } while (1); } structusergetuser() { voidgetname(char*name); voidgetpassword(char*password); structusertemp; printf("请输入用户姓名: "); getname(temp.name); printf("请输入用户密码: "); getpassword(temp.password); printf("输入开户金额: "); do { scanf("%lf",&temp.money); fflush(stdin); if((temp.money)<10) printf("开户金额不能小于10\n"); else break; printf("重新输入开户金额: "); } while (1); returntemp; } voidselect_name() { voidgetname(char*name); voidgetpassword(char*password); printf("%30s\n","***按照姓名查询账户余额***"); printf("%8s%15s%15s%10s\n","账号","用户姓名","存款余额");printf("---------------------------------------------\n\n\n"); FILE*fp; structusertemp; charname[20]; charpassword[8]; if((fp=fopen(file,"rb"))==NULL) { printf("cannotopenfile! \n"); exit (1); } printf("输入要查询的姓名: "); getname(name); printf("请输入密码: "); getpassword(password); while(fread(&temp,sizeof(structuser),1,fp)) if(strcmp(temp.name,name)==0&&strcmp(temp.password,password)==0){ printf("NO.%d%20s%.2f\n",temp.id,temp.name,temp.money); } fclose(fp); } voidselect_id() { intcount(); voidgetpassword(char*password); printf("%30s\n","***按照编号查询账户余额***"); printf("%8s%15s%10s\n","编号","用户姓名","存款余额"); printf("---------------------------------------------\n\n"); FILE*fp; structusertemp; inti,maxnum; charpassword[8]; if((fp=fopen(file,"rb"))==NULL) { printf("cannotopenfile! \n"); exit (1); } maxnum=count(); printf("输入要查询账号: "); scanf("%d",&i); printf("输入账号密码: "); scanf("%s",&password); if(i<1||i>maxnum) { printf("你要查询的账号不存在! "); return; } while(fread(&temp,sizeof(structuser),1,fp)) if(temp.id==i&&strcmp(temp.password,password)==0) { printf("NO.%d%20s%.2f\n",temp.id,temp.name,temp.money);} fclose(fp); } voiddisplay() { printf("%30s\n","***用户资料显示***"); printf("%8s%15s%10s\n","账号","用户姓名","存款余额"); printf("---------------------------------------------\n\n"); FILE*fp; structusertemp; if((fp=fopen(file,"rb"))==NULL) { printf("cannotopenfile! \n"); exit (1); } while(fread(&temp,sizeof(structuser),1,fp)) { printf("NO.%d%20s%.2f\n",temp.id,temp.name,temp.money);} fclose(fp); } voidsave_money() { printf("%30s\n","***用户存款业务***"); printf("---------------------------------------------\n\n"); intcount(); voidgetpassword(char*password); FILE*fp; inti,num,mark; structuser*temp; charpassword[8]; num=count(); temp=(structuser*)malloc(num*sizeof(structuser)); if((fp=fopen(file,"rb"))==NULL) { printf("cannotopenfile! \n"); exit (1); } for(i=0;i fread(&temp[i],sizeof(structuser),1,fp); fclose(fp); printf("输入要存款账号: "); scanf("%d",&mark); if(mark<1||mark>num) { printf("你要存款账号不存在! "); return; } printf("输入账号密码: "); scanf("%s",&password); if((fp=fopen(file,"wb"))==NULL) { printf("cannotopenfile! \n"); exit (1); } for(i=0;i { if(temp[i].id==mark) { doublemoney=0; printf("输入要存入的金额: "); scanf("%lf",&money); if(money<=0) { printf("只能为正数! \n"); money=0; } temp[i].money+=money; } fwrite(&temp[i],sizeof(structuser),1,fp); } fclose(fp); free(temp); printf("你存款业务已办妥! \n"); } voidget_money() { printf("%30s\n","***用户取款业务***"); printf("---------------------------------------------\n\n"); intcount(); voidgetpassword(char*password); FILE*fp; inti,num,mark; structuser*temp; charpassword[8]; num=count(); temp=(structuser*)malloc(num*sizeof(structuser)); if((fp=fopen(file,"rb"))==NULL) { printf("cannotopenfile! \n"); exit (1); } for(i=0;i fread(&temp[i],sizeof(structuser),1,fp); fclose(fp); printf("输入要取款账号: "); scanf("%d",&mark); if(mark<1||mark>num) { printf("你要取款账号不存在! ");return; } printf("输入账号密码: "); scanf("%s",&password); if((fp=fopen(file,"wb"))==NULL) { printf("cannotopenfile! \n"); exit (1); } for(i=0;i { if(temp[i].id==mark) { doublemoney=0; printf("输入要取出的金额: ");scanf("%lf",&money); if(money<=0) { printf("只能为正数! \n");money=0; } elseif(money>temp[i].money){ printf("你的余额不足! \n"); money=0; } temp[i].money-=money; } fwrite(&temp[i],sizeof(structuser),1,fp); } fclose(fp); free(temp); printf("你取款业务已办妥! \n"); } voiddel() { intcount(); printf("%30s\n","***注销账户***"); printf("%8s%15s%10s\n","账号","用户姓名","存款余额");printf("---------------------------------------------\n\n"); FILE*fp; structusertemp; inti,maxnum; if((fp=fopen(file,"rb"))==NULL) { printf("cannotopenfile! \n"); exit (1); } maxnum=count(); printf("输入要销户账号: "); scanf("%d",&i); if(i<1||i>maxnum) { printf("你要查询的账号不存在! "); return; } while(fread(&temp,sizeof(structuser),1,fp))//循环读取每一条记录判断是否为要查看的记录 if(temp.id==i&&temp.money==0.00)//余额为0 { temp.id=-1;//算无效帐户 printf("NO.%d%20s%.2f\n",temp.id,temp.name,temp.money);fwrite(&temp,sizeof(structuser),1,fp);//保存修改 printf("账户销户成功\n"); } fclose(fp); } voidprint()//函数功能: 输出界面 { printf("%30s\n","***活期储蓄帐目管理系统***"); printf("---------------------------------------------\n\n"); printf("%8s,%-20s\n","1","用户开户"); printf("%8s,%-20s\n","2","按照姓名查询账户余额"); printf("%8s,%-20s\n","3","按照账号查询账户余额"); printf("%8s,%-20s\n","4","存款"); printf("%8s,%-20s\n","5","取款"); printf("%8s,%-20s\n","6","用户销户"); printf("%8s,%-20s\n","7","显示用户信息
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 病毒 测试 程序