软件测试文档南昌航空大学实验报告2019 年 10 月 20 日课程名称:软件质量保证与测试实验名称:测试程序的设计班级: 112032 27姓名:肖心远同组人:指导教师评定:签名:一、实验目的完成测试用程序的编写,为接下来的测试实验做准备。
二、实验要求(1)设计程序的语言可以选择C、C++、JAVA等;(2)保证程序语法正确(3)记录实验数据并书写实验报告题目要求:题目一:三角形问题问题描述:输入三角形三条边a、b、c,三条边有效取值范围为[1,200],判断该三角形是什么三角形,输出内容具体包括:(1)等边三角形;(2)等腰三角形;(3)直角三角形;(4)等腰直角三角形;(5)一般三角形;(6)非三角形;(7)输入数据非法。
题目二:NextDate问题问题描述:输入年月日year、month、day,其中年份的有效取值范围为[1900,2100],请输出输入日期的下一天,例如输入2019年9月29日,输出为2019年9月30日。
若输入日期非法,例如输入2019年2月30日,则输出“输入日期不存在”,若输入日期超出取值范围,例如输入2019年9月32日,则输出“输入日期超出范围”。
问题三:佣金问题问题描述:前亚利桑那洲境内的一位步枪销售商销售密苏里州制造商制造的步枪机(lock)、枪托(stock)和枪管(barrel)。
枪机卖45美元,枪托卖30美元,枪管卖25美元。
销售商每月至少要售出一支完整的步枪,且生产限额是大多数销售商在一个月内可销售70个枪机、80个枪托和90个枪管。
根据当月的销售情况,并计算销售商的佣金如下:(1)不到(含)1000美元的部分为10%;(2)1000(不含)~1800(含)美元的部分为15%;(3)超过1800美元的部分为20%。
佣金程序生成月份销售报告,汇总售出的枪机、枪托和枪管总数,销售商的总销售额以及佣金。
三、实验步骤1.运行TC, Visual C++, JAVA等开发工具;2.在开发环境中完成程序设计,并进行调试;3.在程序没有语法错误的前提下重点检查程序的逻辑错误; 4.对程序进行调试,并记录实验数据。
四、实验内容 1.三角形问题(1)程序流程图(2)源代码import java.util.Scanner; public class triangel {public static void main(String[] args){ Scanner input=newScanner(System.in); double a=input.nextDouble(); double b=input.nextDouble(); double c=input.nextDouble(); }}if(a200||b200||c200){ System.out.println("输入数据非法\n"); }else if((a+b)else if(a==b&&b==c&&a==c){System.out.println("等边三角形\n"); }else if(a==b||b==c||a==c){if(a*a==b*b+c*c||b*b==a*a+c*c||c*c==a*a+b*b){System.out.println("等腰直角三角形\n"); }else{System.out.println("等腰三角形\n"); }}else if(a*a==b*b+c*c||b*b==a*a+c*c||c*c==a*a+b*b){ System.out.println("直角三角形\n"); } else{System.out.println("一般三角形\n"); }(3)测试数据及测试结果a=1,b=2,c=3a=2,b=2,c=3a=3,b=4,c=5a=8,b=8,c=8a=4,b=7,c=92.NextDate问题(1)程序流程图(2)源代码import java.util.Scanner;public class Nextday {public static void main(String[] args){ Scanner input=newScanner(System.in); intyear=input.nextInt(),input.nextInt(),day=input.nextInt(); inttomorrowday=day,tomorrowmonth=month,tomorrowyear=year;if(year2100||month12||day31) { System.out.printf("输入日期非法");System.exit(-1);} elseif((month==4||month==6||month==9||month==11)&&(day==31)){ System.out.printf("输入日期不存在\n");System.exit(-1);} elseif((year%400==0||(year%100!=0&&year%4==0))&&month==2&&day>29){System.out.printf("输入日期不存在\n");System.exit(-1);} elseif((!(year%400==0||(year%100!=0&&year%4==0))&&month==2&&day>28)){System.out.printf("输入日期不存在\n");System.exit(-1);}else if((month==4||month==6||month==9||month==11)&&day==30){ tomorrowmonth++; tomorrowday=1; } elseif((month==1||month==3||month==5||month==7||month==8||month==10)&&day==31){tomorrowmonth++;tomorrowday=1;}else if(month==12&&day==31){ tomorrowyear++;tomorrowmonth=1; tomorrowday=1;} elseif(month==2&&(year%400==0||(year%100!=0&&year%4==0))&&day==29){ tomorrowmonth+ +;tomorrowday=1;} elseif(month==2&&(!(year%400==0||(year%100!=0&&year%4==0)))&&day==28){tomorrowmonth++;tomorrowday=1;}else{ tomorrowday++;}System.out.println("nextdayis\n"+tomorrowyear+"/"+tomorrowmonth+"/"+tomorrowday); } }(3)测试数据及测试结果year=2130,month=11,day=11year=2001,month=4,day=30year=2019,month=5,day=31year=2019,month=2,day=28year=2019,month=2,day=29year=2019,month=2,day=29year=2019,month=12,day=313.佣金问题(1)程序流程图(2)源代码import java.util.Scanner;public class yongjin {public static void main(String[] args){double lockprice=45,stockprice=30,barrelprice=25; doubletotallocks=0,totalstocks=0,totalbarrels=0; double commission;Scanner input=new Scanner(System.in);System.out.print("Input the locks,stocks and barrels:\n");int locks=input.nextInt(); int stocks=input.nextInt();int barrels=input.nextInt();if(1>locks||locks>70||1>stocks||locks>=80||1>barrels||barrels>=90){System.out.println("输入错误");System.exit(-1);}totallocks=totallocks+locks;totalstocks=totalstocks+stocks; totalbarrels=totalbarrels+barrels; double locksales=lockprice*totallocks, double stocksales=stockprice*totalstocks,double barrelsales=barrelprice*totalbarrels, doublesales=locksales+stocksales+barrelsales; if(sales>1800){commission=0.10*1000;commission=commission+0.15*800;commission=commission+0.20*(sales-1800);} else if(sales>1000){commission=0.10*1000;commission=commission+0.15*(sales-1000);} else commission=0.10*sales; System.out.print("salesis $"+sales+"commission is $:"+commission); }}(3)测试数据及测试结果locks=60,stocks=60,barrels=70locks=30,stocks=40,barrels=50locks=80,stocks=48,barrels=31五、结果分析 1.三角形问题程序较为简单,算法和语法基本没问题,题目要求也都实现了,程序未出现大错误,只是在编写时有几个符号打错,后经改正后无错误。