Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

ST Lab Program

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 10

Design and develop a program in a language of your choice to solve the triangle

problem defined as follows: Accept three integers which are supposed to be the
three sides of a triangle and determine if the three values represent an
equilateral triangle, isosceles triangle, scalene triangle, or they do not form a
triangle at all. Assume that the upper limit for the size of any side is 10. Derive
test cases for your program based on boundary-value analysis, execute the test
cases and discuss the results.

ALGORITHM:
Step 1: Input a, b & c i.e three integer values which represent three sides of
the triangle.
Step 2: if (a < (b + c)) and (b < (a + c)) and (c < (a + b) then
do step 3
else
print not a triangle. do step 6.
Step 3: if (a=b) and (b=c) then
Print triangle formed is equilateral. do step 6.
Step 4: if (a ≠ b) and (a ≠ c) and (b ≠ c) then
Print triangle formed is scalene. do step 6.
Step 5: Print triangle formed is Isosceles.
Step 6: stop

PROGRAM CODE:
#include<stdio.h>
int main()
{
int a, b, c;
printf("Enter three sides of the triangle");
scanf("%d%d%d", &a, &b, &c);
//range 1 to 10
if((a<=0 && a > 10) || (b<=0 && b > 10) || (c<=0 && c > 10))
{
printf("Out of range");

}
else
{
if((a<b+c)&&(b<a+c)&&(c<a+b))
{
if((a==b)&&(b==c))
{
printf("Equilateral triangle");
}
else if((a!=b)&&(a!=c)&&(b!=c))
{
printf("Scalene triangle");
}
else
printf("Isosceles triangle");
}
else
printf("triangle cannot be formed");
}
return 0;
}

Test Case Name :Boundary Value Analysis for triangle problem


Experiment Number : 1
Test Data : Enter the 3 Integer Value( a , b And c )
Pre-condition : 1 ≤ a ≤ 10 , 1 ≤ b ≤ 10 and 1 ≤ c ≤ 10 and a < b + c , b < a + c and c < a +
b
Brief Description : Check whether given value for a equilateral, isosceles , Scalene
triangle or can't from a triangle

Triangle Problem -Boundary value Test cases for input data

Input Data

Expected Actual
Status Comments
Case Output Output
Description
Id

A b c

Should
Enter the display
min value the
1 1 1 1
for a , b message
and c Equilateral
triangle
Enter the Message
2 1 1 2 should be
min value
for 2 items displayed
and can't form
min +1 for a
any one triangle
item1
Enter the Message
min value should be
for 2 items displayed
3 and 1 2 1 can't form
min +1 for a
any one triangle
item1
Enter the Message
min value should be
for 2 items displayed
4 and 2 1 1 can't form
min +1 for a
any one triangle
item1
Enter the Should
normal display
value for 2 the
5 items 5 5 1 message
and 1 item Isosceles
is min triangle
value
Enter the Should
normal display
value for 2 the
6 items 5 1 5 message
and 1 item Isosceles
is min triangle
value
Enter the Should
normal display
value for 2 the
7 items 1 5 5 message
and 1 item Isosceles
is min triangle
value
Should
Enter the display
normal the
8 5 5 5 message
Value for a,
b and c Equilateral
triangle
Enter the
normal Should
value for 2 display
the
9 items 5 5 10
message
and 1 item Not a
is max triangle
value
10 Enter the Should
normal display
value for 2 the
items 5 10 5 message
and 1 item Not a
is max triangle
value
Enter the Should
normal display
value for 2 the
11 items 10 5 5 message
and 1 item Not a
is max triangle
value
Enter the Should
max value display
for 2 items the
12 and 10 10 9 message
max - 1 for Isosceles
any one triangle
item

Enter the Should


max value display
for 2 items the
13 and 10 9 10 message
max - 1 for Isosceles
any one triangle
item
14 Enter the Should
max value display
for 2 items the
and 9 10 10 message
max - 1 for Isosceles
any one triangle
item
15 Should
Enter the 10 10 10 display
max value
the
for a, b and message
c Equilateral
triangle

2. Design, develop, code and run the program in any suitable language to solve the commission
problem. Analyze it from the perspective of boundary value testing, derive different test cases,
execute these test cases and discuss the test results

/* Assumption price for lock=45.0, stock=30.0 and barrels=25.0 production limit could sell in a
month 70 locks,80 stocks and 90 barrels. commission on sales = 10 % <= 1000 and 15 % on
1000 to 1800 and 20 % on above 1800*/ lock =-1 to end sales

tLocks =12

tStock= 15

tBarrels=19

Sales= 12 *45.0 + 15 * 30.0 +19 *25 = 1465

1st case sales >1800

Sales = 2000

Comm= 1000 * 0.1 + 800 * .15 + 200*0.2 =

2nd case sales >1000

Comm= 1000 * 0.1 + 465 * 0.15= 169.75

3rd case

Sales < 1000

Sales= 577

Comm= 577 *0.1

#include<stdio.h>

int main()

int locks, stocks, barrels, tlocks, tstocks, tbarrels;

float lprice, sprice, bprice, sales, comm;

int c1,c2,c3, temp;

lprice=45.0;
sprice=30.0;

bprice=25.0;

tlocks=0;

tstocks=0;

tbarrels=0;

printf("\nenter the number of locks and to exit the loop enter -1 for locks\n");

scanf("%d",&locks);

while(locks!=-1)

c1=(locks<=0||locks>70);

printf("enter the number of stocks and barrels\n");

scanf("%d%d",&stocks,&barrels);

c2=(stocks<=0||stocks>80);

c3=(barrels<=0||barrels>90);

if(c1)

printf("value of locks not in the range 1..70 ");

else

temp=tlocks+locks; temp =69 + 7 =76

if(temp>70)

printf("new total locks =%d not in the range 1..70 so old ",temp);

else

tlocks=temp;

printf("total locks = %d\n",tlocks);

if(c2)

printf("value of stocks not in the range 1..80 ");

else

temp=tstocks+stocks;
if(temp>80)

printf("new total stocks =%d not in the range 1..80 so old ",temp);

else

tstocks=temp;

printf("total stocks=%d\n",tstocks);

if(c3)

printf("value of barrels not in the range 1..90 ");

else

temp=tbarrels+barrels;

if(temp>90)

printf("new total barrels =%d not in the range 1..90 so old ",temp);

else

tbarrels=temp;

printf("total barrel=%d",tbarrels);

printf("\nenter the number of locks and to exit the loop enter -1 for locks\n");

scanf("%d",&locks);

printf("\ntotal locks = %d\ntotal stocks =%d\ntotal barrels =%d\n",tlocks,tstocks,tbarrels);

sales = lprice*tlocks+sprice*tstocks+bprice*tbarrels;

printf("\nthe total sales=%f\n",sales);

if(sales > 0)

if(sales > 1800.0)

comm=0.10*1000.0;

comm=comm+0.15*800;

comm=comm+0.20*(sales-1800.0);
}

else if(sales > 1000)

comm =0.10*1000;

comm=comm+0.15*(sales-1000);

else

comm=0.10*sales;

printf("the commission is=%f\n",comm);

else

printf("there is no sales\n");

return 0;

Cas Description Input data Expected Output Actual staus Com


e Id Output ment
s
Tota Total Total Sales Commission Sales Com
l locs Stocs barrel missi
on
1 Enter the
min value
for locks,
stocks 1 1 1 100 10
and
barrels
2 Enter the 1 1 2 125 12.5
3 min value 1 2 1 130 13
4 for 2
items and
min +1 for 2 1 1 145 14.5
any one
item
5 Enter the
value 5 5 5 500 50
6 sales 10 10 9 975 97.5
7 approxim 10 9 10 970 97
8 ately mid
9 10 10 955 95.5
value
9
between
100 to
1000

Enter the
values to
calculate
the
commissi 100
10 10 10 100
on for 0
sales
nearly
less than
1000

10 Enter the
values
sales 102
10 10 11 103.75
exactly 5
equal to
1000
103
10 11 10 104.5
0
104
11 10 10 106.75
5
14 14 14

You might also like