Академический Документы
Профессиональный Документы
Культура Документы
2 STACK OPERATION
3 QUEUE OPERATION
4 PALINDROME
5 SUM OF DIGITS
6 ARITHMETIC OPERATION
SORTING TWO ARRAYS
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int p,sum=0,m,n;
int lista[5], listb[5], listc[10]={0};
clrscr();
printf("Enter the first element\n");
for(m=0;m<5;m++)
{
scanf("%d",&lista[m]);
sum=sum+abs(lista[m]);
}
printf("Enter the second element\n");
for(n=0;n<5;n++)
{
scanf("%d",&listb[n]);
sum=sum+abs(listb[n]);
}
p=n=m=0;
m=m-sum;
while(m<sum)
{
for(n=0;n<5;n++)
{
if(m==lista[n]||m==listb[n])
listc[p++]=m;
if(m==lista[n]&&m==listb[n])
listc[p++]=m;
}
m++;
}
printf("\nMerged elements are:");
for(n=0;n<10;n++)
{
printf("\n%d", listc[n]);
}
getch();
}
Test the C program:
Sort and store the element of two arrays of integers into the third list.
Min – maximum number of elements in first array and second array.
Max size of first and second array.
Min + Max size of third array.
Expected
Test id Test Description Test Steps Actual Output Status
Output
Entering array
Input number Accepting the Acceptance of
TC-01 elements as an Success
N number N array element
integer
Entering array Input non The number N Non acceptance of
TC-02 elements as non integer number should not be a non integer Success
integer N accepted element
Input more
Entering more than than MAX The number N Non acceptance of
TC-03 MAX number of number of should not be more than MAX Success
element of first array element of first accepted number of element
array
Input more
Entering more than
than MAX The number N Non acceptance of
MAX number of
TC-04 number of should not be more than MAX Success
element of second
element of accepted number of element
array
second array
Input lesser Prompts for more
Entering lesser than than MIN elements if the
Waits to get
TC-05 MIN number of number of MAX no of Success
more inputs
element of first array element of first elements are not
array input
Input lesser Prompts for more
Entering lesser than
than MIN elements if the
MIN number of Waits to get
TC-06 number of MAX no of Success
element of second more inputs
element of elements are not
array
second array input
Storing
elements from
Creation of third two array in Output the third Output is created
TC-07 Success
array third array in array in the third array
ascending
order
OUTPUT 1
STACK OPERATION
#include<iostream.h>
#include<conio.h>
#include<process.h>
class stack
{
int top,a[10],n;
public:
stack()
{
top=-1;
n=5;
}
void push()
{
if(top<n)
{
top++;
cout<<"\n ENTER THE VALUE\t:";
cin>>a[top];
cout<<"\n PUSHED VALUE IS\t:"<<a[top];
}
else
{
cout<<"\n STACK OVERFLOW";
}
getch();
}
void pop()
{
if(top==-1)
{
cout<<"\n STACK UNDERFLOW";
}
else
{
cout<<"\n THE POPED VALUE IS\t:"<<a[top];
top--;
}
getch();
}
void display()
{
int i;
if(top==-1)
{
cout<<"\n STACK EMPTY:";
}
else
{
cout<<"\n STACK VALUES:\n";
for(i=top;i>=-1;i--)
cout<<a[i]<<endl;
}
getch();
}
};
void main()
{
int b;
stack s;
do
{
clrscr();
cout<<"\n*************************";
cout<<"\n STACK OPERATION";
cout<<"\n*************************";
cout<<"\n1.push\n2.pop\n3.display\n4.exit";
cout<<"\n ENTER THE CHOICE\t:";
cin>>b;
switch(b)
{
case 1:s.push();
break;
case 2:s.pop();
break;
case 3:s.display();
break;
}
}
while(b!=4);
}
Test the C++ program:
Experiment the operation of STACK using array implementation
MAX-Maximum number of elements in a stack
Expected
Test id Test Description Test Steps Actual Output Status
Output
The element The element is
Pushing an element Input an
TC-01 should be accepted in the Success
into empty stack element
pushed empty stack
Acceptance of an
Pushing an element
The element element in the
into stack having less Input an
TC-03 should be stack having less Success
than MAX number of element
pushed than MAX number
elements
of elements
Pushing an element Non acceptance of
The element
into stack having Input an input in a stack
TC-04 should not be Success
MAX number of element having MAX no of
pushed
elements elements
Terminating the Termination of
Termination of the
process of input Input the the input
TC-05 input process when Success
when the element 0 is element 0 process when 0
0 is pressed
pressed is pressed
Display the status of Displaying the
Message is
TC-06 stack if the elements Input data message “the Success
displayed
are on the limit stack is full”
Display the message
Displaying the
“the stack is empty” Message is
TC-07 Input data message “the Success
when the elements displayed
stack is empty”
are added
Display the message
“choice terminated” Displaying the
Message is
TC-08 when the element 0 is Input data message “the Success
displayed
pressed and terminate stack is empty”
the program
List all the
Listing elements in List operation ( All elements of the
TC-09 elements in the Success
the stack Output data) stack are displayed
stack
OUTPUT 2
QUEUE OPERATION
#include<stdio.h>
#include<conio.h>
#include<malloc.h>
struct queue
{
int data;
struct queue*link;
};
struct queue*front,*rear;
void main()
{
int ch,i,n,s;
void insertq(int);
void printq();
int deleteq();
front=rear=NULL;
do
{
clrscr();
printf("\n\t\t QUEUE OPERATION");
printf("\n\t\t 1.INSERTION");
printf("\n\t\t 2.DELETION");
printf("\n\t\t 3.LIST");
printf("\n\t\t 4.EXIT");
printf("\n\t\t SELECT ANY OPTION:");
scanf("%d",&ch);
switch(ch)
{
case 1:
{
printf("\n\t\t ENTER THE LENGTH OF QUEUE:\t");
scanf("%d",&n);
printf("\n\t\t ENTER DATA TO INSERT:\n\t");
for(i=0;i<n;i++)
{
scanf("%d",&s);
insertq(s);
}
}
break;
case 2:
{
printf("\n\t\t %d IS DELETED FROM QUEUE:(press any key)",deleteq());
getch();
}
break;
case 3:
{
printf("\t\t\t ELEMENTS IN THE QUEUE\N");
printq();
getch();
}
break;
}
}
while(ch!=4);
}
void insertq(int num)
{
struct queue*temp;
temp=(struct queue*)malloc(sizeof(struct queue));
temp->data=num;
temp->link=NULL;
if(front==NULL)
front=temp;
else
rear->link=temp;
rear=temp;
}
int deleteq()
{
struct queue*temp;
int num;
if(front==NULL)
{
printf("\t\t QUEUE IS EMPTY");
return(1);
}
else
{
temp=front;
num=temp->data;
front=temp->link;
if(front==NULL)
rear=NULL;
return num;
}
}
void printq()
{
struct queue*temp;
temp=front;
do
{
printf("%d\t",temp->data);
temp=temp->link;
}
while(temp);
getch();
}
Test the C program: Menu driven option for Queue operations to perform insertion, deletion,
list and exit
Expected
Test id Test Description Test Steps Actual Output Status
Output
The element Insertion of the
Inserting an element Input an
TC-01 should be element in the Success
in empty queue element
inserted queue
Set limit for the
Acceptance of the
MAX number of Input the limit The element
element for the
TC-02 elements that are to and size of the should be Success
MAX number of
be inserted in the queue inserted
elements
queue
Non acceptance of
Inserting an element
The element the elements that is
in queue having Input an
TC-03 should not be greater than the Success
MAX number of element
inserted MAX number of
elements
elements
Delete first Deletion of the
Deleting an element Delete
TC-04 element from element is done in Success
from queue operation
the queue the queue
Deleting an element
from the queue The oldest entry Non removal of
Delete
TC-05 having less than must not be the oldest entry of Success
operation
MAX number of removed the queue
elements
Deleting an element
Removal of the
from the queue Delete Output the result
TC-06 oldest entry of the Success
having MAX operation in correct format
queue
number of elements
Listing all element
Listing all
Listing elements in List operation ( in the queue when
TC-07 elements in the Success
the queue Output data) the choice is
queue
entered
Input number
Entering menu option Accepting the Acceptance of the
TC-08 between 1 and Success
1-4 option option
4
The number N Non acceptance of
Entering menu option Input number
TC-09 should not be the element less Success
less than 1 N less than 1
accepted than 1
Input number The number N Non acceptance of
Entering menu option
TC-10 N greater than should not be the element greater Success
greater than 4
4 accepted than 4
OUTPUT 3
PALINDROME
#include<iostream.h>
#include<conio.h>
#include<string.h>
class palin
{
char *s[50],rs[50],ch;
int i,k;
public:
void get() {
cout<<"\n\t\t\t PALINDROME USING POINTERS";
cout<<"\n\t\t\t ENTER THE STRING:";
cin>>*s;
}
void palindrome();
void disp() {
if(strcmp(*s,rs))
cout<<"\n"<<"\n\t\t\t THE GIVEN STRING IS NOT A PALINDROME";
else
cout<<"\n"<<"\n\t\t\t THE GIVEN STRING IS PALINDROME";
}
};
void palin::palindrome()
{
strcpy(rs,*s);
k=strlen(*s);
for(i=0;i<k/2;i++)
{
ch=rs[i];
rs[i]=rs[k-i-1];
rs[k-i-1]=ch;
}
cout<<"\n\t\t\t THE REVERSED STRING IS: " <<rs;
}
void main()
{
clrscr();
palin s,*p;
p=&s;
p->get();
p->palindrome();
p->disp();
getch();
}
Test the C++ program: Palindrome string checking program (using pointers)
Expected
Test id Test Description Test Steps Actual Output Status
Output
Non palindrome
Result as
Acceptance of a string results as the
TC-02 Output data palindrome Success
palindrome string non palindrome
string
string
Non palindrome
Result as non
Acceptance of a non string results as the
TC-03 Output data palindrome Success
palindrome string non palindrome
string
output
Display the
correct reversed
Displayed the
Display the correct string to
TC-04 Output data correct reversed Success
reversed string compare the
string
condition of the
palindrome
The reversed
and the original The string is
Comparison of the
string are compared and the
reversed and the
compared and condition is
TC-05 original string is Output data Success
the condition verified and the
palindrome or not
checked and the correct output is
and display the result
result is displayed
displayed
OUTPUT 4
SUM OF DIGITS
#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
class sum
{
public:
long int x,y,s,sum;
sum()
{
clrscr();
cout<<”\n\t\t *************************”;
cout<<”\n\t\t SUM OF DIGITS”;
cout<<”\n\t\t*************************”;
cout<<”\n\t\t ENTER THE VALUES:”;
cin>>x;
s =0;
sum=0;
s =x;
}
void cal(void);
};
void sum:: cal(void)
{
while(s>9)
{
x=s;
while(x>=1)
{
y=x%10;
sum=sum+y;
x=x/10;
}
s=sum;
cout<<endl;
cout<<”\n\t\t SUM OF DIGITS:”<<sum;
sum=0;
}
}
void main()
{
clrscr();
sum s1;
s1.cal();
getch();
}
Test the C++ program: Accepting a ten digit number and to count the sum of digits up to a
single digit is obtained.
Expected
Test id Test Description Test Steps Actual Output Status
Output
Accepting a
Accepting a character Input a Accepting a
TC-05 character data for Success
data for choice character data character data
choice
Expected
Test id Test Description Test Steps Actual Output Status
Output
Acceptance of an Input an Accepting an Accepting an
TC-01 integer and a float integer and a integer and a integer and a float Success
number float number float number number
Input two Not accepting
Non acceptance of Not accepting two
TC-02 integer two integer Success
two integer numbers integer numbers
numbers numbers
Not accepting
Non acceptance of Input two float Not accepting two
TC-03 two float Success
two float numbers numbers float numbers
numbers
Input a
Non acceptance of a Not accepting a Not accepting a
TC-05 negative Success
negative number negative number negative number
number