《软件测试技术及用例设计实训》源.docx_第1页
《软件测试技术及用例设计实训》源.docx_第2页
《软件测试技术及用例设计实训》源.docx_第3页
《软件测试技术及用例设计实训》源.docx_第4页
《软件测试技术及用例设计实训》源.docx_第5页
已阅读5页,还剩7页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

P168源程序:#includevoid main()float A,B,X; scanf(“%f%f%f”,&A,&B,&X);if(A1)&(B=0) X=X/A;if(A=2)|(X1)X=X+1;printf(“%f”,X);P171源程序:1. int testing(intx,inty) 2. 3. intsoftware=0; 4. if(x0)& (y0) 5. 6. software =x+y+10; 7. 8. else 9. 10. software=x+y-10; 11. 12. 13. if(software0)56if(0=i_flag)78i_temp=i_count+100;9break;1011else1213if(1=i_flag)1415i_temp=i_temp*10;1617else1819i_temp=i_temp*20;202122i_count-;2324returni_temp;25 P174源程序:1int _tmain(int argc, _TCHAR* argv)23int x,y; 4scanf(%d%d,&x,&y); 5if(x 0 & y 0)67int i = 1; 8if(x y)910while(x * i)% y != 0)11i+;12printf(%dn,x * i);1314else1516while(y * i)% x != 0)17i+;18printf(%dn,y * i);1920 21return 0;22 P178源程序:int GetMaxDay( int year, int month )int maxday = 0;if ( month = 1 & month = 12 )if ( month = 2 )if ( year % 4 = 0 )if ( year % 100 = 0 )if ( year % 400 = 0 )maxday = 29;elsemaxday = 28;elsemaxday = 29;elsemaxday = 28; elseif ( month = 4 | month = 6 | month = 9 | month = 11 )maxday = 30;elsemaxday = 31;return maxday;P180源程序:Int IsLeap(int year)if (year % 4 = 0)if (year % 100 = 0)if ( year % 400 = 0)leap = 1;elseleap = 0;elseleap = 1;elseleap = 0;return leap;P181源程序:/*作用:计算软件学院教师薪水说明:节选自软件学院教师管理系统源代码*/ 1void CaculateTeacherSalary()23int i;4int j=0;5printf(输入要计算的软件学院教师编号:n);6fflush(stdin);7scanf(%d,&num);8for(i=0;iMAXNUM;i+) 910if(Teacheri.TeacherNo=num) /确定是否为输入的教师号1112j=1; /先赋值,在后面让j同0比较13printf(输入保险金额:);14fflush(stdin);15scanf(%f,&baoxianjin);16printf(输入月效益:);17fflush(stdin);18scanf(%f,&xiaoyi);19TeacherSalaryi=(Teacheri.TeacherBaseSalary+2*Teacheri.TeacherMonthWorkDays+xiaoyi*Teacheri.TeacherWorkYears/100)*0.5-baoxianjin;20printf(%04d号软件学院教师的薪水为:%lf元每月n,Teacheri.TeacherNo,TeacherSalaryi);21break; /找到该教师后,直接跳出循环22 2324if(j=0)25printf(未找到!n);26P182源程序:/*作用:输出软件学院教师信息说明:节选自软件学院教师管理系统源代码*/ 1void PrintTeacherInformation()23 unsigned int i;4if(ActualNum!=0)56printf(共有%d条软件学院教师信息n,ActualNum);7printf(n);8for(i=0;iActualNum;i+)910 printf(第%d个软件学院教师的信息:n,i+1);11printf(编号:%04dn,Teacheri.TeacherNo);12printf(姓名:%sn,Teacheri.TeacherName);13printf(籍贯:%sn,Teacheri.TeacherHometown);14printf(地址:%sn,Teacheri.TeacherAddress);15printf(电话:%sn,Teacheri.TeacherPhone);16printf(生日:%d年%d月%d日n,Teacheri.TeacherBirth.year,Teacheri.TeacherBirth.month,Teacheri.TeacherBirth.day);17printf(工龄:%dn,Teacheri.TeacherWorkYears);18if(Teacheri.TeacherSex=0)19printf(性别:男n);20else if(Teacheri.TeacherSex=1)21printf(性别:女n);22 else 23printf(性别:无n);24printf(基本工资:%fn,Teacheri.TeacherBaseSalary);25printf(月工作天数:%dn,Teacheri.TeacherMonthWorkDays);26switch(Teacheri.TeacherEducation)2728case 1:29printf(教育背景: 高中n);30break;31case 2:32printf(教育背景: 学士n);33break;34case 3:35printf(教育背景: 硕士n);36break;37case 4:38printf(教育背景: 其它n);39break;40case 5:41printf(教育背景:无n);4243printf(*n);44 4546else printf(暂无软件学院教师信息!请重新选择!n);47P187源程序:getit(int m)int I,k;k=sqrt(m);for(i=2;i=k+1)printf(“%d is a selected numbern”,m);elseprintf(“%d is not a selected numbern”,m);P218源程序:#include#includevoid bhdy(int s,int b);void prt();int a4,flag,count;void main() int b1,b2,i,j,k=0,p,c; printf(Game guess your number in mind is # # # #.n); for(i=1;i10&k4;i+) /分别显示四个19确定四个数字的组成 printf(No.%d:your number may be:%d%d%d%dn,+count,i,i,i,i); printf(How many digits have bad correctly guessed:); scanf(%d,&p); /人输入包含几位数字 for(j=0;jp;j+) ak+j=i; /a:存放已确定数字的数组 k+=p; /k:已确定的数字个数 if(k4) /自动算出四位中包的个数 for(j=k;j4;j+) aj=0; i=0; printf(No.%d:your number may be:%d%d%d%dn,+count,a0,a1,a2,a3); printf(How many are in exact positions:); /顺序显示四位数字 scanf(%d,&b1); /人输入有几位位置是正确的 if(b1=4)prt();exit(0); /四位正确,打印结果,结束游戏 for(flag=1,j=0;j3&flag;j+) /实现四个数字的两两(aj,ak交换 for(k=j+1;k4&flag;k+) if(aj!=ak) c=aj;aj=ak;ak=c; /交换aj,ak printf(No.%d:Your number may be: %d%d%d%dn,+count,a0,a1,a2,a3); printf(How many are in exact positins:); scanf(%d,&b2); /输入有几个位置正确 if(b2=4)prt();flag=0; /若全部正确,结束游戏 else if(b2-b1=2)bhdy(j,k); else if(b2-b1=-2) c=aj;aj=ak;ak=c; bhdy(j,k); else if(b2=b1) c=aj;aj=ak;ak=c; else b1=b2; if(flag) printf(You input error!n); void prt() printf(Now your number must be %d%d%d%d.n,a0,a1,a2,a3); printf(Game Overn);void bhdy(int s,int b) int i,c=0,d2; for(i=0;i4;i+) /查找s和b以外的两个元素下标 if(i!=s&i!=b) dc+=i; i=ad1;ad1=ad0; ad0=i; /交换除as和a以外的两个元素 prt(); flag=0;P265源代码:Public class shuzu public int getlargest(int array) throws Exceptionif(0 = array.length)throw new Exception(数组不能为空!);int result = array0;for(int i = 0; i array.length; i+ ) if(result arrayi)result = arrayi;return result; P280源代码:package metroSaleTicket;public class MetroSaleTicket private int inputTotalMoney, countOfOneYuan; /定义允许的地铁路线的“类型”:A类2元 B类4元 private String typeOfTickets = TypeA, TypeB; private String resultOfDeal; public MetroSaleTicket() initial();private void initial() countOfOneYuan = 100; /1元的数量,初始为100个 public MetroSaleTicket(int oneYuan) countOfOneYuan = oneYuan;public String currentState() /当前状态String state = Current Staten + 1 Yuan: + countOfOneYuan;return state;public String operation(String type,String money) /type是用户选择的路线类型,money是用户投币的种类if (money.equalsIgnoreCase(1yuan)/若投入1元 inputTotalMoney= inputTotalMoney+1; countOfOneYuan= countOfOneYuan+1;else if (money.equalsIgnoreCase(5yuan)/若投入5元 inputTotalMoney= inputTotalMoney+5;else if (money.equalsIgnoreCase(10yuan) /若投入10元 inputTotalMoney= inputTotalMoney+10;if(inputTotalMoney=inputTotalMoney-2)/若选择A类票且系统足够找零countOfOneYuan= countOfOneYuan- (inputTotalMoney-2);resultOfDeal = Input Informationn + Type: A; Money: 2Yuan n + currentState(); return resultOfDeal;else if (type.equals(typeOfTickets0) &(countOfOneYuan inputTotalMoney-2) /若选择A类票且系统不够找零 resultOfDeal = Not enough Change!; return resultOfDeal;else if (type.equals(typeOfTickets1) &(inputTotalMoney= inputTotalMoney-4)/若选择B类票且系统足够找零 countOfOneYuan = countOfOneYuan- (inputTotalMoney-4);resultOfDeal = Input Informationn + Type: B; Money: 2Yuan n + currentState(); return resultOfDeal;else if (type.equals(typeOfTickets1) &(countOfOneYuan inputTotalMoney-4) /若选择B类票且系统不够找零 resultOfDeal = Not enough Change!; return resultOfDeal;else / 其他状态 返回异常resultOfDeal = Failure Informationn + Money Error;return resultOfDeal;P293源代码:package metroSaleTicket;import junit.framework.Assert;import junit.framework.TestCase;public class MetroSaleTicketTest extends TestCase private MetroSaleTicket obj;protected void setUp() throws Exception obj = new MetroSaleTicket();/super.setUp();protected void tearDown() throws Exception super.tearDown();/基本路径1public void testOperation1() String except = Not enough money!; Assert.assertEquals(except,obj.operation(TypeA, 1yuan);/基本路径2public void testOperation2() String except = Input Informationn + Type: A; Money: 2Yuan n + Current Staten +1 Yuan: + 97; Assert.assertEquals(except,obj.operation(TypeA, 5yuan);/基本路径2public void testOperation3() String except = Input Informationn +

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

最新文档

评论

0/150

提交评论