通过这次实验,让我掌握边界值、等价类和决策表测试的基本方法。
七、 附录
TRIANGLE.C
#include
int flag[15]={3,3,2,3,5,3,3,2,3,5,3,3,2,3,5},
a[15]={100,100,100,100,100,100,100,100,100,100,1,2,100,199,200}, b[15]={100,100,100,100,100,1,2,100,199,200,100,100,100,100,100}, c[15]={1,2,100,199,200,100,100,100,100,100,100,100,100,100,100}; int i,j=0;
printf(\is...---------------------\\n\ for(i=0;i<15;i++){
if(isTriangle(a[i],b[i],c[i])==flag[i]) j++; }
printf(\compared with the expected results--------\\n\
printf(\}
int isTriangle(int a,int b,int c) {
int flag;
if(a
if(flag==1) {
if(a==b && b==c){ flag=2;
printf(\ }
else if(a!=b && b!=c && a!=c){ flag=4;
printf(\ }
else{ flag=3;
printf(\ } }
else{ flag=5;
printf(\ }
return flag;
}
DATE.C
#include
int tomorrowDay,tomorrowMonth,tomorrowYear,day,month,year;//设置程序需要的变量
printf(\ scanf(\
switch(month){//通过switch来选择不同的月份下的情况 case 1: case 3: case 5: case 7: case 8:
case 10://上面的月份都是31天的,下面代码实现31天情况下的月份 if(day<31){
tomorrowDay=day+1; tomorrowMonth=month; tomorrowYear=year; } else {
tomorrowDay=1;
tomorrowMonth=month+1; tomorrowYear=year; }
break; case 4: case 6: case 9:
case 11://上面的月份都是30天的,下面代码实现30天情况下的月份 if(day<30) {
tomorrowDay=day+1; tomorrowMonth=month; tomorrowYear=year; } else
{
tomorrowDay=1;
tomorrowMonth=month+1; tomorrowYear=year; }
break;
case 12://由于12月一过,年份要加一,故单独把12月拿出 if(day<31) {
tomorrowDay=day+1; tomorrowMonth=month; tomorrowYear=year; } else {
tomorrowDay=1; tomorrowMonth=1; if(year==2012){
printf(\ exit(0); } else
tomorrowYear=year+1; }
break;
case 2://根据是否闰年来判断二月的天数,故把二月单独拿出来 if(day<28) {
tomorrowDay=day+1; tomorrowMonth=month+1; tomorrowYear=year+1; }
else if(day==28) {
if((year/4==0 && year/100!=0) || year/400==0){ tomorrowDay=29;
tomorrowMonth=month; tomorrowYear=year; } else {
tomorrowDay=1; tomorrowMonth=3; tomorrowYear=year;
} }
else if(day==29) {
tomorrowDay=1; tomorrowMonth=3; tomorrowYear=year; } else
printf(\ }
printf(\
is %d %d %d\\n\
}
COMMISSI.C
#include
int locks,stocks,barrels;
float lockPrice,stockPrice,barrelPrice; int totalLocks,totalStocks,totalBarrels; float lockSales,stockSales,barrelSales; float sales,commission;
lockPrice=45.0; stockPrice=30.0; barrelPrice=25.0; totalLocks=0; totalStocks=0; totalBarrels=0;
printf(\ scanf(\
while(locks!=-1) {
printf(\ scanf(\
totalLocks=totalLocks+locks; totalStocks=totalStocks+stocks; totalBarrels=totalBarrels+barrels;
date
printf(\ scanf(\ }
printf(\ printf(\ printf(\
lockSales=lockPrice*totalLocks; stockSales=stockPrice*totalStocks; barrelSales=barrelPrice*totalBarrels;
sales=lockSales+stockSales+barrelSales; printf(\
if(sales>1800.0) {
commission=0.10*1000.0;
commission=commission+0.15*800.0;
commission=commission+0.20*(sales-1800.0); }
else if(sales>1000.0) {
commission=0.10*1000.0;
commission=commission+0.15*(sales-1000.0); } else
commission=0.10*sales;
printf(\}
相关推荐: