0% found this document useful (0 votes)
56 views7 pages

Prog 5

The document outlines a C program designed to solve a commission problem involving sales of locks, stocks, and barrels. It includes variable definitions, user input handling, and calculations for total sales and commissions based on sales thresholds. Additionally, it discusses dataflow testing, defining and using nodes and paths for various variables to analyze the program's functionality and correctness.

Uploaded by

skjskjskj333
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
56 views7 pages

Prog 5

The document outlines a C program designed to solve a commission problem involving sales of locks, stocks, and barrels. It includes variable definitions, user input handling, and calculations for total sales and commissions based on sales thresholds. Additionally, it discusses dataflow testing, defining and using nodes and paths for various variables to analyze the program's functionality and correctness.

Uploaded by

skjskjskj333
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

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

Variable Defined at node Used at node


lockprice 8 63
stockprice 9 64
barrelprice 10 65
totallocks 11, 32 28, 34, 60, 63
totalstocks 12, 43 39, 45, 61, 64
totalbarrels 13, 54 50, 56, 62, 65
Locks 16, 58 17, 19, 28
stocks 21 22, 39
barrels 21 23, 50
locksales 63 66
stocksales 64 66
barrelsales 65 66
Sales 66 67, 68, 72, 74, 77, 80
Com 70, 71, 72, 76, 77, 80 71, 72, 77, 81

Define /Use paths with definition clear status


Variables
DC
Tes (beginnin
Description DU paths path
t id g , end
?
nodes)
Check for lockprice 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22,
variable 23, 24, 26, 27, 28, 29, 31, 32, 33, 34, 35, 37, 38, 39,
1 <8,63> YES
DEF(lockprice,8) And 40, 42, 43, 44, 45, 46, 48, 49, 50, 51, 53, 54, 55, 56,
USE(lockprice,63) 57, 58, 59, 60, 61, 62, 63
Check for stockprice
9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22,
variable
23, 24, 26, 27, 28, 29, 31, 32, 33, 34, 35, 37, 38, 39,
2 DEF(stockprice,9) <9,64> YES
40, 42, 43, 44, 45, 46, 48, 49, 50, 51, 53, 54, 55, 56,
And
57, 58, 59, 60, 61, 62, 63, 64
USE(stockprice,64)
Check for barrelprice
10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
variable
24, 26, 27, 28, 29, 31, 32, 33, 34, 35, 37, 38, 39, 40,
3 DEF(barrelprice,10) <10,65> YES
42, 43, 44, 45, 46, 48, 49, 50, 51, 53, 54, 55, 56, 57,
And
58, 59, 60, 61, 62, 63, 64, 65
USE(barrelprice,65)
Variables
DC
Tes (beginnin
Description DU paths path
t id g , end
?
nodes)
<11,28>, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, YES
26, 27, 28,

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

<32,34> 32,33,34 YES

<32,60> 32,33,34,35,37,38,39,40,42,43,44,45,46,48,49,50,51,53, YES


54, 55,56,57,58,59, 60

<32,63> 32,33,34,35,37,38,39,40,42,43,44,45,46,48,49,50,51, YES


53,54,55,56,57,58,59 ,60,61,62,63
5 Check for totalstocks <12,39>, 12,13,14,15,16,17,18,19,20,21,22,23,24,26,27,28,29,31 , YES
variable 32,33,34,35,37,38,39
DEF(totalstocks,12,43)
And 12,13,14,15,16,17,18,19,20,21,22,23,24,26,27,28,29 ,31,
<12,45>, 32,33,34,35,37,38,39,40,42,43,44,45 NO
USE(totalstocks,39,45,6
1,64) 12,13,14,15,16,17,18,19,20,21,22,23,24,26,27,28,29 ,31, NO
<12,61>, 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,61

<12,64>, 12,13,14,15,16,17,18,19,20,21,22,23,24,26,27,28,29 ,31,


32,33,34,35,37,38,39,40,42,43,44,45,46,48,49 ,50,51,53, NO
54,55,56,57,58,59,60,61,62,63,64
Variables
DC
Tes (beginnin
Description DU paths path
t id g , end
?
nodes)
<43,45>, 43,44,45 YES

<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,50> 13,14,15,16,17,18,19,20,21,22,23,24,26,27,28,29 ,31,32, YES


33,34,35,37,38,39,40,42,43,44,45,46,48,49,50

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

Check for totalbarrels <13,62> 13,14,15,16,17,18,19,20,21,22,23,24,26,27,28,29, NO


31,32,33,34,35,37,38,39,40,42,43,44,45,46,48,49,
variable
50,51,53,54,55,56,57,58,59,60,61,62
6 DEF(totalbarrels,13,54)
And USE(totalbarrels,
50,56,62,65)
<13,65> 13,14,15,16,17,18,19,20,21,22,23,24,26,27,28,29, NO
31,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,61,62,63,64,65

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

7 Check for locks variable <16,17> 16,17 YES


DEF(locks,16,58) And
<16,19> 16,17,18,19 YES
Variables
DC
Tes (beginnin
Description DU paths path
t id g , end
?
nodes)
<16,28> 16,17,18,19,20,21,22,23,24,26,27,28 YES

<58,17> 58,17 YES


USE(locks,17,19,28)
<58,19> 58,17,18,19 YES

<58,28> 58,17,18,19,20,21,22,23,24,26,27,28 YES

Check for stocks variable <21,22> 21,22 YES


8 DEF(stocks,21) And
USE(stocks,22,39) <21,39> 21,22,23,24,26,27,28,29,31,32,33,34,35,37,38,39 YES

Check for barrels <21,23> 21,22,23 YES


9 variable DEF(barrels,21) <21,50> 21,22,23,24,25,26,27,28,29,31,32,33,34,35,37,38,39,40,4 YES
And USE(barrels,23,50) 2,43,44,45, 46,47,48,49,50

Check for lockpsales <63, 66> 63,64,65,66 YES


variable
10
DEF(locksales,63) And
USE(locksales,66)

Check for stocksales <64,66> 64,65,66 YES


variable
11
DEF(stocksales,64) And
USE(stocksales,66)

Check for barrelsales < 65,66> 65,66 YES


variable
12
DEF(barrelsales,65) And
USE(barrelsales,66)

13 Check for sales variable <66,67> 66,67 YES


DEF(sales,66) And
USE(sales,67,68,72,74,7 <66,68> 66,67,68 YES
7,8 0) <66,72> 66,67,68,69,70,71,72 YES

<66,74> 66,67,68,74 YES

<66,77> 66,67,68,74,75,76,77 YES


Variables
DC
Tes (beginnin
Description DU paths path
t id g , end
?
nodes)
<66,80> 66,67,68,74,79,80 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

<77,81> 77,78,81 YES

<80,81> 80,81 YES

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.

You might also like