Computer Project 1KIDDIES
Computer Project 1KIDDIES
Std.........................................Roll No.............................
This is to certify that activity written in the project
have been performed by the student satisfactorily.
Signature
School Stamp Dated..................
AKNOWLEDGEMENT
I want to express my sincere gratitude towards my school and
respective teachers who have helped me in completing this
project. I am extremely grateful to them for extending their
guidance and cooperation throughout this project which in turn
has resulted in a great strength to carve my creative ideas. I
remain grateful to all, my respected teachers for their all time
support. I am also thankful for the supporting staff of the
school, who guided me for this project from time to time.
INDEX
S No.
PROGRAMMES PAGE NO REMARKS
1. Program to Calculate Interest Amount using Function
Overloading
2. Circular Queue
3. Binary Search
4. Bubble Sort
5. Insertion Sort
6. Linear Search
7. Merge Sort-I
8. Merge Sort-II
9. Merge Sort-III
10. Product of Two Matrices
11. Selection Sort
12. Sum of Two Matrices
13. Deleting an Element from Array using Location
14. Inserting an Element into the Array at any Location
15. Transpose of a Matrix
16. Stack Program by Dynamic Memory Allocation
17. Stack through Arrays
18. Queue Program by Dynamic Memory Allocation
19. Queue Implementation through Arrays
20. SQL related Questions for tables Product and Client
21. SQL related Questions for tables Consignor and
Consignee
22. SQL related Questions for tables Stock and Dealer
23. SQL related Questions for tables Furniture and
Arrivals
24. Program on a Structure named Product
25. Program on a Class named Book
26. Program on a Class named Student
CALCULATE INTEREST AMOUNT USING FUNCTION OVERLOADING
#include<iostream.h>
#include<conio.h>
void amount(float princ,float rate,int time)
{
cout<<"\n Principal Amount: Rs."<<princ;
cout<<"\t Time: "<<time<<" years";
cout<<"\n Rate of Interest: "<<rate;
cout<<"\t Interest Amount: "<<(princ*time*rate)<<endl;
}
void amount(float princ,int time)
{
cout<<"\n Principal Amount: Rs."<<princ;
cout<<"\t Time: "<<time<<" years";
cout<<"\n Rate of Interest: 0.08";
cout<<"\t Interest Amount: "<<(princ*time*0.08)<<endl;
}
void amount(float princ,float rate)
{
cout<<"\n Principal Amount: Rs."<<princ;
cout<<"\t Time: 2 years";
cout<<"\n Rate of Interest: "<<rate;
cout<<"\t Interest Amount: "<<(princ*2*rate)<<endl;
}
void amount(float princ)
{
cout<<"\n Principal Amount: Rs."<<princ;
cout<<"\t Time: 2 years";
cout<<"\n Rate of Interest: 0.15";
cout<<"\t Interest Amount: "<<(princ*2*0.15)<<endl;
}
void main()
{
clrscr();
cout<<"Case 1";
amount(2500.0f,0.08,2);
cout<<"Case 2";
amount(2000.0f,2);
cout<<"Case 3";
amount(3000.0f,0.13f);
cout<<"Case 4";
amount(4000.0);
getch();
}
OUTPUT
Case 1
Principal Amount: Rs.2500 Time: 2 years
Rate of Interest: 0.08 Interest Amount: 400
Case 2
Principal Amount: Rs.2000 Time: 2 years
Rate of Interest: 0.08 Interest Amount: 320
Case 3
Principal Amount: Rs.3000 Time: 2 years
Rate of Interest: 0.13 Interest Amount: 780
Case 4
Principal Amount: Rs.4000 Time: 2 years
Rate of Interest: 0.15 Interest Amount: 1200
CIRCULAR QUEUE
#include<iostream.h>
#include<conio.h>
const int size=5;
void insert(int[],int);
void disp(int[],int,int);
void del(int[]);
int cqueue[size], front=-1, rear=-1;
void main()
{
int item,ch;
while(ch!=4)
{
clrscr();
cout<<"Main menu"<<endl;
cout<<"1. Add a node "<<endl;
cout<<"2. Delete a node"<<endl;
cout<<"3. Display all "<<endl;
cout<<"4. Exit"<<endl;
cout<<"Enter your choice \t";
cin>>ch;
switch(ch)
{
case 1:
cout<<"Enter the element to add ";
cin>>item;
insert(cqueue,item);
break;
case 2:
del(cqueue);
break;
case 3:
disp(cqueue,front,rear);
break;
case 4:
cout<<"End of the program"<<endl;
break;
default:
cout<<"Invalid choice"<<endl;
break;
}
getch();
}
}
void insert(int cqueue[], int ele)
{
if((front==0 && rear==size-1)||(front==rear+1))
{
cout<<"Queue is full / OVERFLOW "<<endl;
return;
}
if(rear==-1)
front=rear=0;
else
if(rear==size-1)
rear=0;
else
rear++;
cqueue[rear]=ele;
}
void disp(int cqueue[],int front,int rear)
{
int i=0;
if(front==-1)
{
cout<<"Queue is empty / UNDERFLOW"<<endl;
return;
}
if(rear>=front)
{
for(i=0;i<front;i++)
cout<<"-";
cout<<">>>";
for(i=front;i<rear;i++)
cout<<cqueue[i]<<"<-";
cout<<cqueue[rear]<<"<<<"<<endl;
}
else
{
for(i=0;i<rear;i++)
cout<<cqueue[i]<<"-";
cout<<cqueue[rear]<<"<<<";
for(;i<front;i++)
cout<<"-";
cout<<">>>";
for(i=front;i<size;i++)
cout<<cqueue[i]<<"<-";
cout<<"\t ... wrap around";
}
}
void del(int cqueue[])
{
if(front==-1)
{
cout<<"Queue is empty"<<endl;
return;
}
cout<<"node deleted is "<<cqueue[front]<<endl;
if(front==rear)
front=rear=-1;
else
{
if(front==size-1)
front=0;
else
front++;
}
}
OUTPUT: CIRCULAR QUEUE
BINARY SEARCH
#include<iostream.h>
#include<conio.h>
int bsearch(int a[],int n,int n1);
void main()
{
int a[20],i,n,item,pos;
clrscr();
cout<<"enter the size of the array ";
cin>>n;
cout<<"enter elements in sorted order"<<endl;
for(i=0;i<n;i++)
{
cout<<"enter the element " ;
cin>>a[i];
}
cout<<"enter the element to search ";
cin>>item;
pos=bsearch(a,n,item);
if(pos==-1)
cout<<"Element is not present"<<endl;
else
cout<<"Element found at loation "<<pos+1<<endl;
getch();
}
int bsearch(int a[],int n,int item)
{
int first,last,mid,pos;
first=0;
last=n-1;
/* to search the array */
while(first<=last)
{
mid=(first+last)/2;
if (item==a[mid])
return(mid);
else
if (item>a[mid])
first=mid+1;
else
last=mid-1;
}
return(-1);
}
OUTPUT: BINARY SEARCH
BUBBLE SORT
#include<iostream.h>
#include<conio.h>
void bubble( int a[], int n);
void main()
{
int a[30],i,n;
clrscr();
cout<<"enter the total number of elements ";
cin>>n;
for(i=0;i<n;i++)
{
cout<<"enter the element ";
cin>>a[i];
}
bubble(a,n);
cout<<"\nsorted elements list is \n";
for(i=0;i<n;i++)
{
cout<<a[i]<<endl;
}
getch();
}
void bubble(int a[],int n)
{
int i,t,j;
i=0;
for(i=0;i<n;i++)
{
for(j=0;j<(n-1)-i;j++)
{
if (a[j]>a[j+1])
{
t=a[j];
a[j]=a[j+1];
a[j+1]=t;
}
}
}
}
OUTPUT: BUBBLE SORT
INSERTION SORT
#include<iostream.h>
#include<conio.h>
void insertion(int [],int);
void main()
{
int a[30],i,n;
clrscr();
cout<<"enter the total number of elements \t";
cin>>n;
cout<<"enter the elements \n";
for(i=0;i<=n-1;i++)
{
cout<<"enter the element \t";
cin>>a[i];
}
insertion(a,n);
cout<<"sorted elements list is \n";
for(i=0;i<=n-1;i++)
{
cout<<"\n"<<a[i];
}
getch();
}
void insertion(int a[],int n)
{
int i,j,t;
for(i=0;i<=n-1;i++)
{
t=a[i];
j=i-1;
while((t<a[j]) && (j>=0)) /* to scan for the proper place*/
{
a[j+1]=a[j];
j=j-1;
}
a[j+1]=t;
}
}
OUTPUT: INSERTION SORT
LINEAR SEARCH
#include<iostream.h>
#include<conio.h>
int lsearch(int a[],int n,int n1);
void main()
{
int a[30],i,n,n1,pos;
clrscr();
cout<<"Enter the total number of elements ";
cin>>n;
for(i=0;i<n;i++)
{
cout<<"enter the element ";
cin>>a[i];
}
cout<<"enter the element to search ";
cin>>n1;
pos=lsearch(a,n,n1);
if (pos==-1)
cout<<"Element is not present"<<endl;
else
cout<<"Element found at location "<<pos+1<<endl;
getch();
}
int lsearch(int a[],int n,int n1)
{
int i;
for(i=0;i<n;i++)
{
if (a[i]==n1)
{
return(i);
}
}
return(-1);
}
OUTPUT: LINEAR SEARCH
MERGE SORT
CASE 1:
#include<iostream.h>
#include<conio.h>
void merge(int [],int [],int [],int,int);
void main()
{
int a1[30],a2[30],a3[60],i,j,n,m;
clrscr();
cout<<"enter total elements in 1st array ";
cin>>n;
cout<<"enter total elements in 2nd array ";
cin>>m;
cout<<"enter elements of 1st array in ascending order \n";
for(i=0;i<n;i++)
{
cout<<"enter the element ";
cin>>a1[i];
}
cout<<"enter elements of 2nd array in ascending order \n";
for(i=0;i<m;i++)
{
cout<<"enter the element ";
cin>>a2[i];
}
merge(a1,a2,a3,n,m);//function calling
cout<<"\nthe final merged array is \n";
for(i=0;i<m+n;i++)
{
cout<<a3[i]<<"";
}
getch();
}
void merge(int a1[],int a2[],int a3[],int n,int m)
{
int p1=0,p2=0,p3=0;
/* to merge the sorted arrays in the third array */
while(p1<n && p2<m)
{
if (a1[p1]<a2[p2])
{
a3[p3]=a1[p1];
p1++;
p3++;
}
else
{
a3[p3]=a2[p2];
p2++;
p3++;
}
}
/* the above loop will be terminated only when
one of the array is fully traversed */
/* to copy the rest of the array of a1 if it is left*/
while(p1<n)
{
a3[p3]=a1[p1];
p1++;
p3++;
}
/* to copy the rest of the array of a2 if it is left*/
while(p2<m)
{
a3[p3]=a2[p2];
p2++;
p3++;
}
}
OUTPUT:MERGE SORT
CASE 1:
MERGE SORT
CASE 2:
#include<iostream.h>
#include<conio.h>
void merge(int [],int [],int [],int,int);
void main()
{
int a1[30],a2[30],a3[60],i,j,n,m;
clrscr();
cout<<"enter total elements in 1st array ";
cin>>n;
cout<<"enter total elements in 2nd array ";
cin>>m;
cout<<"enter elements of 1st array in descending order \n";
for(i=0;i<n;i++)
{
cout<<"enter the element ";
cin>>a1[i];
}
cout<<"enter elements of 2nd array in desending order \n";
for(i=0;i<m;i++)
{
cout<<"enter the element ";
cin>>a2[i];
}
merge(a1,a2,a3,n,m);
cout<<"\nthe final merged array is \n";
for(i=0;i<m+n;i++)
{
cout<<a3[i]<<"";
}
getch();
}
void merge(int a1[],int a2[],int a3[],int n,int m)
{
int p1=n-1,p2=m-1,p3=0;
/* to merge the sorted arrays in the third array */
while(p1>=0 && p2>=0)
{
if (a1[p1]<a2[p2])
{
a3[p3]=a1[p1];
p1=p1-1;
p3++;
}
else
{
a3[p3]=a2[p2];
p2=p2-1;
p3++;
}
}
/* the above loop will be terminated only when
one of the array is fully traversed */
/* to copy the rest of the array of a1 if it is left*/
while(p1>=0)
{
a3[p3]=a1[p1];
p1=p1-1;
p3++;
}
/* to copy the rest of the array of a2 if it is left*/
while(p2>=0)
{
a3[p3]=a2[p2];
p2=p2-1;
p3++;
}
}
OUTPUT: MERGE SORT
CASE 2:
MERGE SORT
CASE 3:
#include<iostream.h>
#include<conio.h>
void merge(int [],int [],int [],int,int);
void main()
{
int a1[30],a2[30],a3[60],i,j,n,m;
clrscr();
cout<<"enter total elements in 1st array ";
cin>>n;
cout<<"enter total elements in 2nd array ";
cin>>m;
cout<<"enter elements of the 1st array in asescending order \n";
for(i=0;i<n;i++)
{
cout<<"enter the element ";
cin>>a1[i];
}
cout<<"enter elements of the 2nd array in desending order \n";
for(i=0;i<m;i++)
{
cout<<"enter the element \t";
cin>>a2[i];
}
merge(a1,a2,a3,n,m);
cout<<"\nthe final merged array is \n";
for(i=0;i<m+n;i++)
{
cout<<a3[i]<<"";
}
getch();
}
void merge(int a1[],int a2[],int a3[],int n,int m)
{
int p1=0,p2=m-1,p3=0;
/* to merge the sorted arrays in the third array */
while(p1<n && p2>=0)
{
if (a1[p1]<a2[p2])
{
a3[p3]=a1[p1];
p1=p1+1;
p3++;
}
else
{
a3[p3]=a2[p2];
p2=p2-1;
p3++;
}
}
while(p1<n)
{
a3[p3]=a1[p1];
p1=p1+1;
p3++;
}
while(p2>=0)
{
a3[p3]=a2[p2];
p2=p2-1;
p3++;
}
}
OUTPUT: MERGE SORT
CASE 3:
PRODUCT OF TWO MATRICES
#include<iostream.h>
#include<conio.h>
void main()
{
int a[10][10],b[10][10],c[10][10],r1,c1,r2,c2,i,j,k;
clrscr();
cout<<"Enter total rows and cols in 1st matrix ";
cin>>r1>>c1;
cout<<"Enter total rows and cols in 2nd matrix ";
cin>>r2>>c2;
//condition
if(c1==r2)
cout<<"Product of matrix can be calculated"<<endl;
else
{
cout<<"Product of matrix cannot be calculated"<<endl;
getch();
return;
}
//input 1st matrix
cout<<"Enter elements of 1st matrix"<<endl;
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
{
cout<<"Enter ["<<i<<"]["<<j<<"] element ";
cin>>a[i][j];
}
}
//input 2nd matrix
cout<<"Enter elements of 2nd matrix"<<endl;
for(i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
{
cout<<"Enter ["<<i<<"]["<<j<<"] element ";
cin>>b[i][j];
}
}
//display 1st matrix
cout<<"1st matrix"<<endl;
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
{
cout<<a[i][j]<<"";
}
cout<<endl;
}
//display 2nd matrix
cout<<"2nd matrix"<<endl;
for(i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
{
cout<<b[i][j]<<"";
}
cout<<endl;
}
//cal product
for(i=0;i<r1;i++)
{
for(j=0;j<c2;j++)
{
c[i][j]=0;
for(k=0;k<c1;k++)
{
c[i][j]=c[i][j]+a[i][k]*b[k][j];
}
}
}
//display product
cout<<"product of matrix"<<endl;
for(i=0;i<r1;i++)
{
for(j=0;j<c2;j++)
{
cout<<c[i][j]<<"";
}
cout<<endl;
}
getch();
}
OUTPUT: PRODUCT OF TWO MATRICES
SELECTION SORT
#include<iostream.h>
#include<conio.h>
void selection(int [],int);
void main()
{
int a[30],i,n;
clrscr();
cout<<"enter the total number of elements ";
cin>>n;
cout<<"enter the node elements \n";
for(i=0;i<=n-1;i++)
{
cout<<"enter the element ";
cin>>a[i];
}
selection(a,n);
cout<<"sorted elements list is \n";
for(i=0;i<=n-1;i++)
{
cout<<a[i]<<endl;
}
getch();
}
void selection(int a[],int n)
{
int i,j,min,t,pos;
for(i=0;i<=n-2;i++)
{
min=a[i];
pos=i;
for(j=i+1;j<=n-1;j++)
{
if (a[j]<min)
{
min=a[j];
pos=j;
}
}
t=a[i];
a[i]=a[pos];
a[pos]=t;
}
}
OUTPUT: SELECTION SORT
SUM OF TWO MATRICES
#include<iostream.h>
#include<conio.h>
void main()
{
int a[10][10],b[10][10],c[10][10],r1,c1,r2,c2,i,j;
clrscr();
cout<<"Enter total rows and cols in 1st matrix ";
cin>>r1>>c1;
cout<<"Enter total rows and cols in 2nd matrix ";
cin>>r2>>c2;
//condition
if(r1==r2 && c1==c2)
cout<<"Sum of matrix can be calculated"<<endl;
else
{
cout<<"Sum of matrix cannot be calculated"<<endl;
getch();
return;
}
//input 1st matrix
cout<<"Enter elements of 1st matrix"<<endl;
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
{
cout<<"Enter ["<<i<<"]["<<j<<"] element ";
cin>>a[i][j];
}
}
//input 2nd matrix
cout<<"Enter elements of 2nd matrix"<<endl;
for(i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
{
cout<<"Enter ["<<i<<"]["<<j<<"] element ";
cin>>b[i][j];
}
}
//display 1st matrix
cout<<"1st matrix"<<endl;
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
{
cout<<a[i][j]<<"";
}
cout<<endl;
}
//display 2nd matrix
cout<<"2nd matrix"<<endl;
for(i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
{
cout<<b[i][j]<<"";
}
cout<<endl;
}
//cal and display sum
cout<<"Sum of matrix"<<endl;
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
{
c[i][j]=a[i][j]+b[i][j];
cout<<c[i][j]<<"";
}
cout<<endl;
}
getch();
}
OUTPUT: SUM OF TWO MATRICES
DELETING AN ELEMENT FROM THE ARRAY USING LOCATION
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
void Delete(int a[],int n,int loc);
void main()
{
int a[50],i,n,loc;
clrscr();
cout<<"enter the size of the array ";
cin>>n;
for(i=0;i<=n-1;i++)
{
cout<<"enter the element ";
cin>>a[i];
}
cout<<"enter the location from which you want to delete the element ";
cin>>loc;
loc=loc-1; /*to make relative to zero */
if (loc>n-1 || loc<0)
{
cout<<"deletion not possible, invalid location \n";
getch();
exit(1);
}
Delete(a,n,loc);
getch();
}
void Delete(int a[],int n,int loc)
{
int x,back,i;
x=a[loc];
back=loc;
while(back<n)
{
a[back]=a[back+1];
back++;
}
n--; /* to decrease the array size*/
cout<<"to print the final array after deletion \n";
for(i=0;i<=n-1;i++)
{
cout<<a[i]<<endl;
}
cout<<"\n\nthe deleted node is "<<x<<endl;
getch();
}
OUTPUT:DELETING AN ELEMENT FROM ARRAY
INSERTING AN ELEMENT INTO THE ARRAY AT ANY LOCATION
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
void insert(int a[],int n,int loc,int num);
void main()
{
int a[50];
int i,n,loc,num;
clrscr();
cout<<"enter total number of elements ";
cin>>n;
for(i=0;i<n;i++)
{
cout<<"enter the element ";
cin>>a[i];
}
cout<<"enter the location to insert ";
cin>>loc;
if (loc>n || loc<=0)
{
cout<<"insertion not possible/invalid position\n";
getch();
exit(1);
}
cout<<"enter the value of the node to insert ";
cin>>num;
insert(a,n,loc,num);
getch();
}
void insert(int a[],int n,int loc,int num)
{
int back,i;
back=n;
while(back>=loc)
{
a[back]=a[back-1];
back--;
}
a[back]=num;
n++; /* to increase the array size*/
cout<<"Final array after insertion \n";
for(i=0;i<n;i++)
{
cout<<a[i]<<"";
}
}
OUTPUT: INSERTING AN ELEMENT IN AN ARRAY
TRANSPOSE OF A MATRIX
#include<iostream.h>
#include<conio.h>
void main()
{
int a[10][10],r,c,i,j,s=0;
clrscr();
cout<<"Enter total rows and cols ";
cin>>r>>c;
//input
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
cout<<"Enter ["<<i<<"]["<<j<<"] element ";
cin>>a[i][j];
}
}
//display
cout<<"Normal matrix"<<endl;
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
cout<<a[i][j]<<"";
}
cout<<endl;
}
//display transpose
cout<<"Transpose of matrix"<<endl;
for(j=0;j<c;j++)
{
for(i=0;i<r;i++)
{
cout<<a[i][j]<<"";
}
cout<<endl;
}
getch();
}
OUT PUT TRANSPOSE OF A MATRIX
STACK PROGRAM BY DYNAMIC MEMORY ALLOCATION
#include<iostream.h>
#include<conio.h>
struct node
{
int data;
node*link;
};
node*p=NULL;
void push()
{
node*temp;
int num;
cout<<"Enter the node value to add in the stack \t";
cin>>num;
temp=new node;//1
if(temp==NULL)
{
cout<<"Overflow"<<endl;
return;
}
temp->data=num;//2
temp->link=p;//3
p=temp;//4
}
void disp_all()
{
cout<<"The list of nodes in the stack are\n";
node*q;
q=p;
while(q!=NULL)
{
cout<<q->data<<endl;
q=q->link;
}
}
void pop()
{
node*temp;
if(p==NULL)
{
cout<<"Underflow\n";
return;
}
temp=p;//1
cout<<"The extracted element is "<<temp->data<<endl;//2
p=temp->link;//3
delete temp;//4
}
void count()
{
int c=0;
node*q;
q=p;
while(q!=NULL)
{
c++;
q=q->link;
}
cout<<"Total nodes in the stack are"<<c<<endl;
}
void main()
{
int op=0;
while(op!=5)
{
clrscr();
cout<<"Main menu\n";
cout<<"1.Push\n";
cout<<"2.POP\n";
cout<<"3.Display all\n";
cout<<"4.Count all\n";
cout<<"5.Exit\n";
cout<<"Enter your choice\t";
cin>>op;
switch(op)
{
case 1:
push();
break;
case 2:
pop();
break;
case 3:
disp_all();
break;
case 4:
count();
break;
case 5:
cout<<"End of the program\n";
break;
default:
cout<<"Invalid option entered\n";
break;
}
getch();
}
}
OUTPUT: DYNAMIC STATIC
STACK THROUGH ARRAYS
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
int stack[50], top =-1, size;
void push()
{
int val;
cout<<"Enter the value to add";
cin>>val;
if(top<size-1)
{
top++;
stack[top]=val;
}
else
cout<<"Stack is full / OVERFLOW"<<endl;
}
void pop()
{
if(top==-1)
cout<<"Stack is empty / UNDERFLOW"<<endl;
else
{
cout<<"Node deleted is "<<stack[top]<<endl;
top--;
}
}
void display()
{
int i;
if(top==-1)
cout<<"Stack is empty"<<endl;
else
{
for(i=top; i>=0;i--)
{
cout<<stack[i]<<endl;
}
}
}
void main()
{
int op=0;
clrscr();
cout<<"Enter total elements (size) ";
cin>>size;
while(op!=4)
{
clrscr();
cout<<"Main menu"<<endl;
cout<<"1. Push "<<endl;
cout<<"2. Pop"<<endl;
cout<<"3. Display All"<<endl;
cout<<"4. Exit"<<endl;
cout<<"Enter your choice ";
cin>>op;
switch(op)
{
case 1:
push() ;
break ;
case 2:
pop() ;
break ;
case 3:
display() ;
break ;
case 4:
cout<<"End of the program"<<endl;
break ;
default:
cout<<"Invalid Choice"<<endl;
break ;
}
getch();
}
}
OUTPUT: STACK THROUGH ARRAYS
QUEUE PROGRAM BY DYNAMIC MEMORY ALLOCATION
#include<iostream.h>
#include<conio.h>
struct node
{
int data;
node * link;
};
node*front= NULL, *rear =NULL;
void add()
{
node *temp;
int num;
cout<<"Enter the node value to add in the queue";
cin>>num;
temp= new node;//1
if(temp==NULL)
{
cout<<"OVERRFLOW"<<endl;
return;
}
temp->data=num;//2
temp->link=NULL;//3
if(front==NULL)
front=temp;//4
else
rear->link=temp;//5
rear=temp;//6
}
void disp_all()
{
node*q;
q=front;
while(q!= NULL)
{
cout<<q->data<<endl;
q=q->link;
}
}
void delete_node()
{
node*temp;
int num;
if(front==NULL)
cout<<"The queue is emply / UNDERFLOW\n";
else
{
temp=front;//1
num=temp->data;//2
cout<<"The extracted element is\t"<<num;//2
front=temp->link;//3
delete temp;//5
if(front==NULL)
rear=NULL;//4
}
}
void main()
{
int op=0;
while(op!=4)
{
clrscr();
cout<<"Main menu"<<endl;
cout<<"1. Add a node in the queue"<<endl;
cout<<"2. Display all the nodes of the queue"<<endl;
cout<<"3. Delete a node from the queue"<<endl;
cout<<"4. Exit"<<endl;
cout<<"Enter your choice \t";
cin>>op;
switch(op)
{
case 1:
add();
break;
case 2:
disp_all();
break;
case 3:
delete_node();
break;
case 4:
cout<<"End of the program"<<endl;
break;
default:
cout<<"Invalid choice"<<endl;
break;
}
getch();
}
}
OUTPUT: DYNAMIC QUEUE
QUEUE IMPLEMENTATION THROUGH ARRAYS
#include<iostream.h>
#include<conio.h>
int queue[30];
int front=-1, rear=-1, size;
void add()
{
int val;
cout<<"Enter the number to add\t";
cin>>val;
if(front==-1)
{
front = 0;
rear = 0;
}
else
if(rear<=size-1)
{
queue[rear]=val;
rear++;
}
else
cout<<"The queue is full / OVERFLOW"<<endl;
}
void del()
{
int i;
if(front!=-1)
{
cout<<"Node deleted is "<<queue[front]<<endl;
for(i=1;i<rear;i++)
{
queue[i-1]=queue[i];
}
rear--;
if(rear==0)
{
front=-1;
rear=-1;
}
}
cout<<"The queue is empty / UNDERFLOW"<<endl;
}
void disp()
{
int i;
cout<<"The queue elements are \n";
if(front!=-1)
{
for(i=front;i<rear;i++)
{
cout<<queue[i]<<endl;
}
}
else
cout<<"The queue is empty\n";
}
void main()
{
int ch=0;
clrscr();
cout<<"Enter the size of the queue\t";
cin>>size;
while(ch!=4)
{
clrscr();
cout<<"Main menu"<<endl;
cout<<"1. Add an element"<<endl;
cout<<"2. Delete an element "<<endl;
cout<<"3. Display all the elements "<<endl;
cout<<"4. Exit"<<endl;
cout<<"Enter your choice \t";
cin>>ch;
switch(ch)
{
case 1:
add();
break;
case 2:
del();
break;
case 3:
disp();
break;
case 4:
cout<<"End of the program"<<endl;
break;
default:
cout<<"Invalid choice"<<endl;
break;
}
getch();
}
}
OUTPUT: QUEUE IMPLEMENTATION THROUGH ARRAYS
Consider the following tables Product and Client. Write SQL commands for the
following statement (i) to (iv) and give outputs for SQL queries (v) to (viii).
Table: Product Table: Client
C_ID ClientName City P_ID
01 Cosmetic Shop Delhi FW05
06 Total Health Mumbai BS01
12 Live Life Delhi SH06
15 Pretty Woman Delhi FW12
16 Dreams Bangalore TP01
(i) To display the details of those Clients whose City is Delhi.
Ans. SELECT * FROM Client
WHERE City = Delhi;
(ii) To display the details of Products whose Price is in the range of 50 to 100 (Both values
included).
Ans. SELECT * FROM Product
WHERE Price BETWEEN 50 to 100;
(iii) To display the ClientName,City from table Client, and ProductName and Price from table
Product with their corresponding matching P_ID.
Ans. SELECT ClientName, City, ProductName, Price FROM Client, Product WHERE
Client.P_ID=Product.P_ID;
(iv) To increase the Price of All Products by 10.
Ans. UPDATE Product
SET Price = Price + 10;
(v) SELECT DISTINCT City FROM Client;
Ans. Delhi
Mumbai
Bangalore
(vi) SELECT Manufacturer, MAX(Price), MIN(Price), Count(*)
FROM Product GROUP BY Manufacturer;
Ans. LAK 40 40 1
ABC 55 45 2
XYZ 120 95 2
(vii) SELECT ClientName, ProductName
FROM Product, Client
WHERE Client.P_ID=Product.P_ID;
Ans. Cosmetic Shop Face Wash
Total Health Bath Soap
P_ID ProductName Manufacturer Price
TP01 Talcum Powder LAK 40
FW05 Face Wash ABC 45
BS01 Bath Soap ABC 55
SH06 Shampoo XYZ 120
FW12 Face Wash XYZ 95
Live Life Shampoo
Pretty Woman Face Wash
Dreams Talcum Powder
(viii) SELECT ProductName, Price*4
FROM Product;
Ans. Talcum Powder 160
Face Wash 180
Bath Soap 220
Shampoo 480
Face Wash 380
Consider the following tables Consignor and Consignee. Write SQL commands for the statements (i)
to (iv) and give outputs for SQL queries (v) to (viii).
Table: Consignor
CnorID CnorName CnorAddress City
ND01 R Singhal 24, ABC Enclave New Delhi
ND02 Amit Kumar 123, Palm Avenue New Delhi
MU15 R Kohli 5/A, South Street Mumbai
MU50 S Kaur 27-K, Westend Mumbai
Table: Consignee
CneeID CnorID CneeName CneeAddress CneeCity
MU05 ND01 Rahul Kishore 5, Park Avenue Mumbai
ND08 ND02 P Dhingra 16/J, Moore Enclave New Delhi
KO19 MU15 A P Roy 2A, Central Avenue Kolkata
MU32 ND02 S Mittal P 245, AB Colony Mumbai
ND48 MU50 B P Jain 13, Block D, A Vihar New Delhi
(i) To display the names of all Consignors from Mumbai.
Ans. SELECT CnorName FROM Consignor
WHERE City = Mumbai;
(ii) To display the CneeID, CnorName, CnorAddress, CneeName, CneeAddress for
every Consignee.
Ans. SELECT CneeID, CnorName, CnorAddress, CneeName, CneeAddress
FROM Consignor, Consignee
WHERE Consignor.CnorID = Consignee.CnorID;
(iii) To display consignee details in ascending order of CneeName.
Ans. SELECT * FROM Consignee
ORDER BY CneeName ASC;
(iv) To display number of consignor from each city.
Ans. SELECT CneeCity, Count(CneeCity) FROM Consignee
GROUP BY CneeCity;
(v) SELECT DISTINCT CneeCity FROM Consignee;
Ans. Mumbai
New Delhi
Kolkata
(vi) SELECT A.CnorName, B.CneeName FROM Consignor A, Consignee B
WHERE A.CnorID = B.CnorID AND B.CneeCity = Mumbai;
Ans. R Singhal Rahul Kishore
Amit Kumar S Mittal
(vii) SELECT CneeName, CneeAddress FROM Consignee
WHERE CneeCity NOT IN (Mumbai, Kolkalta);
Ans. P Dhingra 16/J, Moore Enclave
B P Jain 13, Block D, Avihar
(viii) SELECT CneeID, CneeName FROM Consignee
WHERE CnorID = MU15 OR CnorID = ND01;
Ans. MU05 Rahul Kishore
KO19 A P Roy
Consider the following tables Stock and Dealers and answer (a1) and (a2) parts of this question.
Table: Stock
ItemNO Item Dcode Qty UnitPrice StockDate
5005 Ball Pen 0.5 102 100 16 31-Mar-10
5003 Ball Pen 0.25 102 150 20 01-Jan-10
5002 Gel Pen Premium 101 125 14 14-Feb-10
5006 Gel Pen Classic 101 200 22 01-Jan-09
5001 Eraser Small 102 210 5 19-Mar-09
5004 Eraser Big 102 60 10 12-Dec-09
5009 Sharpener Classic 103 160 8 23-Jan-09
Table: Dealer
Dcode Dname
101 Reliable Stationers
103 Classic Plastics
102 Clear Deals
(a1) Write SQL commands for the following statements:
(i) To display details of all Items in Stock table in ascending order of StockDate.
Ans. SELECT *
FROM Stock
ORDER BY StockDate;
(ii) To display ItemNo and Item name of those items from Stock table whose
UnitPrice is more than Rupees 10.
Ans. SELECT ItemNo, Item
FROM Stock
WHERE UnitPrice > 10;
(iii) To display the details of those items whose dealer code (Dcode) is 102 or
Quantity in Stock (Qty) is more than 100 from the table Stock.
Ans. SELECT *
FROM Stock
Where Dcode = 102 OR Qty > 100;
(iv) To display Maximum UnitPrice of items for each dealer individuallt as per
Dcode from the table Stock.
Ans. SELECT Dcode, MAX(UnitPrice)
FROM Stock
GROUP BY Dcode;
(a2) Give the output of the following SQL queries:
(i) SELECT COUNT(DISTINCT Dcode)
FROM Stock;
Ans. 3
(ii) SELECT Qty*UnitPrice FROM Stock
WHERE ItemNo = 5006;
Ans. 4400
(iii) SELECT Item, Dname FROM Stock S, Dealers D
WHERE S.DCODE = D.Dcode AND ItemNO = 5004;
Ans. Eraser Big Clear Deals
(iv) SELECT MIN(StockDate) FROM Stock;
Ans. 01-Jan-09
Consider the following tables Furniture and Arrival. Write SQL commands for the statements (a) to
(f) and give outputs for (g).
Table: Furniture
No. Itemname Type Dateofstock Price Discount
1 White Lotus Double Bed 23/02/02 30000 25
2 Pink Feather Baby Cot 20/01/02 7000 20
3 Dolphin Baby Cot 19/02/02 9500 20
4 Decent Office Table 01/01/02 25000 30
5 Comfort Zone Double Bed 12/01/02 25000 25
6 Donald Baby Cot 24/02/02 6500 15
7 Royal Finish Office Table 20/02/02 18000 30
8 Royal Tiger Sofa 22/02/02 31000 30
9 Econo Sitting Sofa 13/12/01 9500 25
10 Eating Paradise Dining Table 19/02/02 11500 25
Table: Arrivals
No. Itemname Type Dateofstock Price Discount
11 Wood Comfort Double Bed 23/03/03 25000 25
12 Old Fox Sofa 20/02/03 17000 20
13 Micky Baby Cot 21/02/03 7500 15
(a) To show all information about the Baby Cots from the Furniture table.
Ans. SELECT *
FROM Furniture
WHERE TYPE = Baby Cot;
(b) To list the Itemname which are priced at more than 15000 from the Furniture table.
Ans. SELECT Itemname
FROM Furniture
WHERE Price > 15000;
(c) To list Itemname and Type of those items, in which Dateofstock is before 22/01/02 from the
Furniture table in descending order of Itemname.
Ans. SELECT Itemname, Type
FROM Furniture
WHERE Dateofstock < {22/01/02} ORDER BY Itemname;
(d) To display Itemname and Dateofstock of those items, in which the Discount percentage is more
the 25 from Furniture table.
Ans. SELECT Itemname, Dateofstock
FROM Furniture
WHERE Discount > 25;
(e) To count the number of items, whose Type is Sofa from Furniture table.
Ans. SELECT Count (*)
FROM Furniture
WHERE Type = Sofa;
(f) To insert a new row in the Arrivals table with the following data:
14, Velvet Touch, Double Bed, {25/03/03}, 25000, 30
Ans. INSERT INTO Arrivals
VALUE ( 14, Velvet Touch, Double Bed, {25/03/03}, 25000, 30} ;
(g) Give the output of the following SQL statement :
(i) SELECT COUNT (DISTINCT Type) FROM Furniture ;
Ans. 5
(ii) SELECT MAX (Discount) FROM Furniture, Arrivals ;
Ans. 30
(iii) SELECT AVG (Discount) FROM Furniture WHERE Type = Baby cot
Ans. 18.33
Declare structure named product with attributes as pno, pname, price, quantity and
cost. Take input for details of 10 product and display the details along with cost.
#include<iostream.h>
#include<conio.h>
struct product
{
int pno;
char pname[20];
float price, qty, cost;
}
p[10];
void main()
{
int i;
clrscr();
for(i=0;i<10;i++)
{
cout<<Enter pno, pname, price & quantity;
cin>>p[i].pno>>p[i].pname>>p[i].price>>p[i].qty;
}
for(i=0;i<10;i++)
{
p[i].cost= p[i].price * p[i].qty;
cout<<pno<<p[i].pno<<pname<<p[i].pname<<<cost<<p[i].cost<<endl;
}
getch();
}
Define a class named BOOK.
Private Members
bcode, noc integer type,
title char size 15,
price, cost float type,
cal_cost() function to calculate cost (cost=price*qty)
Public Members
input() function to take input for the value of bcode,title,noc and price. output()
funtion to call the function cal_cost to calculate total cost and display it.
#include<iostream.h>
#include<conio.h>
class BOOK
{
int bcode,noc;
char title[20];
float price, cost;
void cal_cost()
{
cost = price * qty;
}
public:
void input();
void output();
}
void BOOK :: input()
{
cout<<Enter bcode, title, price and noc;
cin>>bcode>>title>>price>>noc;
}
void BOOK :: output()
{
cal_cost();
cout<<Total cost<<cost<<endl;
}
void main()
{
clrscr();
BOOK b;
b.input();
b.output();
getch();
}
Define a class named STUDENT
Private member :- roll integer type,
name char type size 20,
m1,m2,m3,total,per float type,
cal() to calculate total and percentage.
Public Member :-
input() to take input for roll name m1,m2,m3.
display() to invoke the function cal() and display total and percentage.
#include<iostream.h>
#include<conio.h>
class STUDENT
{
int roll;
char name[20];
float m1, m2, m3, total, per;
void cal()
{
total = m1+m2+m3;
per = total/3;
}
public:
void input();
void display();
};
void STUDENT :: input()
{
cout<<Enter roll, name, m1, m2, m3;
cin>>roll>>name>>m1>>m2>m3;
}
void STUDENT :: display()
{
cal();
cout<<Total<<total<<Per<<per<<endl;
}
void main()
{
clrscr();
STUDENT s;
s.input();
s.display();
getch();
}