0% found this document useful (0 votes)
9 views6 pages

Manual

Uploaded by

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

Manual

Uploaded by

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

VI Semester

1 Design, develop, code and run the program in c 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.

#include <stdio.h>
#include <stdlib.h>

int main() {
int locks, stocks, barrels, t_sales;
float commission;

// Input for locks


printf("Enter the total number of locks: ");
scanf("%d", &locks);
if (locks <= 0 || locks > 70) {
printf("Invalid input for locks\n");
return 1;
}

// Input for stocks


printf("Enter the total number of stocks: ");
scanf("%d", &stocks);
if (stocks <= 0 || stocks > 80) {
printf("Invalid input for stocks\n");
return 1;
}

// Input for barrels


printf("Enter the total number of barrels: ");
scanf("%d", &barrels);
if (barrels <= 0 || barrels > 90) {
printf("Invalid input for barrels\n");
return 1;
}

// Calculate total sales


t_sales = (locks * 45) + (stocks * 30) + (barrels * 25);

// Calculate commission based on total sales


if (t_sales <= 1000) {
commission = 0.10 * t_sales;
} else if (t_sales <= 1800) {
commission = 0.10 * 1000 + 0.15 * (t_sales - 1000);
} else {
commission = 0.10 * 1000 + 0.15 * 800 + 0.20 * (t_sales - 1800);
}

// Display results
printf("The total sales is %d\n", t_sales);
printf("The commission is %.2f\n", commission);

return 0;
}
Design, develop, code and run the program in c language to implement the
2
NextDate function. Analyze it from the perspective of equivalence class value
testing, derive different test cases, execute these test cases and discuss the test
results.

#include <stdio.h>
int main() {
int d, m, y;
// Prompt the user to enter the date in MM DD YYYY format
printf("Enter today's date in the form of MM DD YYYY: ");
scanf("%d %d %d", &m, &d, &y);
// Check if the date is valid
if ((d < 1 || d > 31) || (m < 1 || m > 12) || (y < 1812 || y > 2030)) {
printf("Invalid date\n");
return 1;
}
// Handling months with 31 days
if ((m == 1 || m == 3 || m == 5 || m == 7 || m == 8 || m == 10) && d < 31) {
d++;
}
// End of months with 31 days
else if ((m == 1 || m == 3 || m == 5 || m == 7 || m == 8 || m == 10) && d == 31) {
d = 1;
m++;
}
// Handling months with 30 days
else if ((m == 4 || m == 6 || m == 9 || m == 11) && d < 30) {
d++;
}
// End of months with 30 days
else if ((m == 4 || m == 6 || m == 9 || m == 11) && d == 30) {
d = 1;
m++;
}
// Handling December
else if (m == 12 && d < 31) {
d++;
}
// End of December
else if (m == 12 && d == 31) {
printf("%d is over\n", y);
d = 1;
m = 1;
y++;
}
// Handling February
else if (m == 2 && ((y % 4 != 0 && d < 28)||(y % 4 == 0 && d < 29))) {
d++;
}
// Handling end of February
else if (m == 2 && ((y % 4 != 0 && d == 28) || (y % 4 == 0 && d == 29))) {
d = 1;
m++;
}
// If February is invalid
else {
printf("Invalid date in February\n");
return 1;
}
// Print the next date
printf("Next date: %d-%d-%d\n", m, d, y);
return 0;
}
3 Design, develop, code and run the program in c language to solve the commission
problem. Analyze it from the perspective of decision table-based testing, derive
different test cases, execute these test cases and discuss the test results.

#include <stdio.h>
#include <stdlib.h>

int main() {
int locks, stocks, barrels, t_sales;
float commission;

// Input for locks


printf("Enter the total number of locks: ");
scanf("%d", &locks);
if (locks <= 0 || locks > 70) {
printf("Invalid input for locks\n");
return 1;
}

// Input for stocks


printf("Enter the total number of stocks: ");
scanf("%d", &stocks);
if (stocks <= 0 || stocks > 80) {
printf("Invalid input for stocks\n");
return 1;
}

// Input for barrels


printf("Enter the total number of barrels: ");
scanf("%d", &barrels);
if (barrels <= 0 || barrels > 90) {
printf("Invalid input for barrels\n");
return 1;
}

// Calculate total sales


t_sales = (locks * 45) + (stocks * 30) + (barrels * 25);

// Calculate commission based on total sales


if (t_sales <= 1000) {
commission = 0.10 * t_sales;
} else if (t_sales <= 1800) {
commission = 0.10 * 1000 + 0.15 * (t_sales - 1000);
} else {
commission = 0.10 * 1000 + 0.15 * 800 + 0.20 * (t_sales - 1800);
}

// Display results
printf("The total sales is %d\n", t_sales);
printf("The commission is %.2f\n", commission);

return 0;
}
Design and develop a program in c language to solve the triangle problem defined as
follows: Accept three integers which are supposed to be the three sides of a triangle
4 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, equivalence class partitioning and decision-table
approach and execute the test
cases and discuss the results.

#include <stdio.h>

int main()
{
int a, b, c;

// Prompt user to enter the sides of the triangle


printf("Enter the three sides of the triangle (1 to 10):\n");
scanf("%d %d %d", &a, &b, &c);

// Check if the sides are within the valid range


if (a < 1 || a > 10)
{
printf("Side a is out of range\n");
}
if (b < 1 || b > 10)
{
printf("Side b is out of range\n");
}
if (c < 1 || c > 10)
{
printf("Side c is out of range\n");
}

// Check if the sides can form a valid triangle


if (a < (b + c) && b < (a + c) && c < (a + b))
{
// Classify the triangle
if (a == b && b == c)
{
printf("The triangle is equilateral\n");
}
else if (a != b && a != c && b != c)
{
printf("The triangle is scalene\n");
}
else
{
printf("The triangle is isosceles\n");
}
}
else
{
printf("Triangle not possible\n");
}

return 0; // Exit the program successfully


}
5 Design, develop, code and run the program in c 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.

#include <stdio.h>

int main()
{
int locks, stocks, barrels, tlocks = 0, tstocks = 0, tbarrels = 0;
float lprice = 45.0, sprice = 30.0, bprice = 25.0, sales, comm;

// Prompt user for the number of locks


printf("\nEnter the number of locks (enter -1 to exit the loop):\n");
scanf("%d", &locks);

while (locks != -1)


{
// Prompt user for the number of stocks and barrels
printf("Enter the number of stocks and barrels:\n");
scanf("%d%d", &stocks, &barrels);

// Update totals
tlocks += locks;
tstocks += stocks;
tbarrels += barrels;

// Prompt user for the number of locks again


printf("\nEnter the number of locks (enter -1 to exit the loop):\n");
scanf("%d", &locks);
}

// Display total counts


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

// Calculate sales
sales = (lprice * tlocks) + (sprice * tstocks) + (bprice * tbarrels);
printf("\nThe total sales = %.2f\n", sales);

// Calculate commission
if (t_sales <= 1000) {
commission = 0.10 * t_sales;
} else if (t_sales <= 1800) {
commission = 0.10 * 1000 + 0.15 * (t_sales - 1000);
} else {
commission = 0.10 * 1000 + 0.15 * 800 + 0.20 * (t_sales - 1800);
}

// Display commission
printf("The commission is = %.2f\n", comm);

return 0;
}
6 Design, develop, code and run the program in c language to implement the
binary search algorithm. Determine the basis paths and using them derive
different test cases, execute these test cases and discuss the test results.

#include <stdio.h>

int main()
{
int a[20], n, low, high, mid, key, i;

// Input number of elements


printf("Enter number of elements: ");
scanf("%d", &n);

// Input elements
printf("Enter %d elements in ascending order:\n", n);
for (i = 0; i < n; i++)
{
scanf("%d", &a[i]);
}

// Input key to search


printf("Enter key to search: ");
scanf("%d", &key);

// Initialize binary search variables


low = 0;
high = n - 1;

// Binary search
while (low <= high)
{
mid = (low + high) / 2;

if (a[mid] == key)
{
printf("Element found at position %d\n", mid + 1);
return 0;
} else if (a[mid] < key)
{
low = mid + 1;
} else
{
high = mid - 1;
}
}

// Key not found


printf("Element not found\n");

return 0;
}

You might also like