Prog 5
Prog 5
Design, develop, code and run the program in any suitable language to solve the commission
problem. Analyze it from the perspective of dataflow testing, derive different test cases, execute
these test cases and discuss the test results.
1 #include <stdio.h>
2 #include <conio.h>
3 int main()
4{
5 int c1,c2,c3,temp;
6 int locks,stocks,barrels,totallocks,totalstocks,totalbarrels;
7 float lockprice,stockprice,barrelprice,locksales,stocksales,barrelsales,sales,com;
8 lockprice=45.0;
9 stockprice=30.0;
10 barrelprice=25.0;
11 totallocks=0;
12 totalstocks=0;
13 totalbarrels=0;
14 clrscr();
15 printf("Enter the number of locks and to exit press -1\n");
16 scanf("%d",&locks);
17 while(locks != -1)
18 {
19 c1=(locks<=0 || locks>70);
20 printf("\nEnter the number of stocks and barrels\n");
21 scanf("%d %d",&stocks,&barrels);
22 c2=(stocks<=0 || stocks>80);
23 c3=(barrels<=0 || barrels>90);
24 if(c1)
25 printf("\nValue of locks are not in the range of 1....70\n");
26 else
27 {
28 temp=totallocks+locks;
29 if(temp>70)
30 printf("New totallocks = %d not in the range of 1....70\n",temp);
31 else 32 totallocks=temp;
33 }
34 printf("Total locks = %d",totallocks);
35 if(c2)
36 printf("\n Value of stocks not in the range of 1....80\n");
37 else
38 {
39 temp=totalstocks+stocks;
40 if(temp>80)
41 printf("\nNew total stocks = %d not in the range of 1....80",temp);
42 else
43 totalstocks=temp;
44 }
45 printf("\nTotal stocks = %d",totalstocks);
46 if(c3)
47 printf("\n Value of barrels not in the range of 1....90\n");
48 else
49 {
50 temp=totalbarrels+barrels;
51 if(temp>90)
52 printf("\nNew total barrels = %d not in the range of 1....90\n",temp);
53 else
54 totalbarrels=temp;
55 }
56 printf("\nTotal barrels=%d", totalbarrels);
57 printf("\nEnter the number of locks and to exit press -1\n");
58 scanf("%d",&locks);
59 }
60 printf("\n Total locks = %d",totallocks);
61 printf("\n Total stocks = %d",totalstocks);
62 printf("\n Total barrels = %d",totalbarrels);
63 locksales=totallocks*lockprice;
64 stocksales=totalstocks*stockprice;
65 barrelsales=totalbarrels*barrelprice;
66 sales=locksales+stocksales+barrelsales;
67 printf("\n Total sales = %f",sales);
68 if(sales>1800)
69 {
70 com=0.10*1000;
71 com=com+(0.15*800);
72 com=com+0.20*(sales-1800);
73 }
74 else if(sales>1000)
75 {
76 com=0.10*1000;
77 com=com+0.15*(sales-1000);
78 }
79 else
80 com=0.10*sales;
81 printf("\nCommission = %f",com);
82 getch();
83 return 0;
84 }
OUTPUT:-
Define/ Use Nodes for variables in the commission problem
11,12,13,14,15,16,17,18,19,20,21,22,23,24,26,27,28,29,3 NO
<11,34>, 1,32,33,34
11,12,13,14,15,16,17,18,19,20,21,22,23,24,26,27,28,29,3
<11,60>, 1,32,33,34,35,37 ,38,39 ,40,42,43, 44, 45, 46, 48, 49, 50,
51, 53, 54, 55, 56, 57, 58, 59, 60 NO
Check for totallocks
variable 11,12,13,14,15,16,17,18,19,20,21,22,23,24,26,27,28,29,3
DEF(totallocks,11,32) <11,63>, 1,32,33,34,35,37 ,38,39 ,40,42,43 ,44, 45, 46, 48, 49, 50, NO
4
And 51, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63
USE(totallocks,28,34,
60,63) <32,28> 32,33,34,35,37,38,39,40,42,43,44,45,46,48,49,50,51,53,5 YES
4,55,56,57,58,17 ,18,19,20,21,22,23,24,26,27,28
<43,61> 43,44,45,46,48,49,50,51,53,54,55,56,57,58,59,60,61
YES
<43,64> 43,44,45,46,48,49,50,51,53,54,55,56,57,58,59,60,61,62,6
3,64 YES
13,14,15,16,17,18,19,20,21,22,23,24,26,27,28,29 ,31,32,
<13,56> 33,34,35,37,38,39,40,42,43,44,45,46,48,49 ,50,51,53,54, NO
55,56
54,55,56
<54,56>
YES
54,55,56,57,58,59,60,61,62
<54,62> YES
54,55,56,57,58,59,60,61,62,63,74,65
<54,65> YES
<70,71> 70,71 NO
<70,72> 70,71,72 NO
<70,81> 70,71,72,73,81 NO
<71,72> 71,72 NO
Check for commission
variable <71,81> 71,72,73,81 NO
14 DEF(com,70,71,72,76,77
,8 0) And <72,81> 72,73,81 YES
USE(com,71,72,77,81)
<76,77> 76,77 NO
<76,81> 76,77,78,81 NO
Note :
In above Du-Paths, some paths like < 70,77 >, < 71,71 >, < 71,77> , < 72,71> , < 72,72> ,
<72,77>, <76,71>, <76,72>, < 77,71>, < 77,71>, < 77,77>, < 80,70>, < 80,72>, < 80,77>,
<80,77> are not possible to be formed. So they are not considered in above table.