0% found this document useful (0 votes)
47 views9 pages

Presented To: Prepared By: PGT Computer Science Xii Science

This document contains 21 programs related to computer science concepts like arrays, searching, sorting, stacks, queues, matrices, inheritance, and SQL commands. The programs include linear search in an array, binary search, deletion from an array, bubble sort, selection sort, insertion sort, product of matrices, file handling, class objects, stack as array and linked list, queue as linked list and array, circular queue, matrix transpose, function overloading, inheritance, call by value/reference, copy constructor, and a Christmas tree program using for loops. Sample code is provided for the linear search, binary search, and deletion from array programs.

Uploaded by

Shubham Tyagi
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)
47 views9 pages

Presented To: Prepared By: PGT Computer Science Xii Science

This document contains 21 programs related to computer science concepts like arrays, searching, sorting, stacks, queues, matrices, inheritance, and SQL commands. The programs include linear search in an array, binary search, deletion from an array, bubble sort, selection sort, insertion sort, product of matrices, file handling, class objects, stack as array and linked list, queue as linked list and array, circular queue, matrix transpose, function overloading, inheritance, call by value/reference, copy constructor, and a Christmas tree program using for loops. Sample code is provided for the linear search, binary search, and deletion from array programs.

Uploaded by

Shubham Tyagi
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/ 9

PRESENTED TO: PREPARED BY:

PGT COMPUTER SCIENCE


XII SCIENCE
S.NO. PROGRAMES SIGNATURE
1. LINEAR SEARCH IN AN ARRAY

2. PROGRAM FOR BINARY SEARCH

3. PROGRAM FOR DELETION

4. BUBBLE SORT

5. SELECTION SORT IN AN ARRAY

6. INSERTION SORT

7. PRODUCT OF MATRICES

8. PROGRAM TO CREATE A SINGLE FILE AND THEN


DISPLAY ITS CONTENTS
9. PROGRAM FOR READING AND WRITING CLASS OBJECT

10. PROGRAM FOR STACK AS AN ARRAY

11. PROGRAM FOR STACK AS LINKED LIST

12. PROGRAM FOR QUEUE AS LINKED LIST

13. QUEUE AS AN ARRAY

14. CIRCULAR QUEUE THROUGH ARRAY

15. PROGRAM FOR TRANSPOSE OF MATRICES

16. PROGRAM FOR FUNCTION OVERLOADING

17. PROGRAM FOR IMPLEMENTING INHERITANCE

18. PROGRAM FOR CALL BY VALUE/CALL BY REFERENCE

19 PROGRAM FOR COPY CONSTRUCTOR

20. PROGRAM FOR MAKING CHRISTMAS TREE (FOR_LOOP)

21. SQL COMMANDS


/*************************PROGRAM #1*******************/
/************************LINEAR SEARCH******************/
#include<iostream.h>
#include<conio.h>
int lsearch(int[],int,int);
void main ()
{
clrscr();
int ar[50],item,n,index;
cout<<"enter array size";
cin>>n;
cout<<"\n enter array elements";
for(int i=0;i<n;i++)
{cin>>ar[i];
}
cout<<"\n enter element to be searched";
cin>>item;
index=lsearch(ar,n,item);
if(index==-1)
cout<<"\n sorry !! element could not be found";
else
cout<<"\n element found at index:"<<index<<"position:"<<index+1;
getch();
}
int lsearch(int ar[],int size, int item)
{
for(int i=0;i<size; i++)
{
if(ar[i]==item)
return i;
}
return -1;
}
/***********************PROGRAM #2**********************/
/**********************BINARY SEARCH*********************/

#include<iostream.h>
#include<conio.h>
int bsearch(int[],int,int);
void main()
{
clrscr();
int ar[50],item,n,index;
clrscr();
cout<<"enter array size(max.50):";
cin>>n;
cout<<"\n array elements sorted in asc. order :";
for(int i=0;i<n;i++)
{ cin>>ar[i];}
cout<<"\nenter elements to be searched for:";
cin>>item;
index=bsearch(ar,n,item);
if(index==-1)
cout<<"\nsorry!! element could not be found\n";
else
cout<<"\n element found at index:" <<index<<",position:"<< index+1 <<endl;
getch();
}
int bsearch(int ar[],int size,int item)
{ int beg,last,mid;
beg=0; last=size-1;
while(beg<=last)
{mid=(beg+last)/2;
if(item==ar[mid])
return mid;
else if(item>ar[mid])
beg=mid+1;
else
last=mid-1;
}
return-1;
}
/***********************PROGRAM #3********************/
/*************DELETE AN ELEMENT FROM AN ARRAY*********/

#include<iostream.h>
#include<conio.h>
#include<process.h> //for exit()
int lsearch(int[],int,int);
//function to determine the right position for new element
void main()
{
clrscr();
int ar[50],item,n,index; //array can hold ,ax. 50 elements
//clrscr();
cout<<"how many elements do u want to create array with?(max 50_..)";
cin>>n;
cout<<"\n enter array elements\n";
for(int i=0;i<n;i++)
{
cin>>ar[i];}
char ch='y';
while(ch=='y'|| ch=='Y')
{cout<<"\nenter elements to be deleted";
cin>>item;
if(n==0)
{
cout<<"underflow!!\n";
exit(1);
}
index=lsearch(ar,n,item);
if(index!=-1)

ar[index]=0;
else
{
cout<<"sorry!! No such element in the array\n";
exit(1);
}
cout<<"the array now is as shown below\n";
cout<<"zero(0) signifies deleted element\n";
for(i=0;i<n;i++)
cout<<ar[i]<<" ";
cout<<endl;
cout<<"after this emptied space will be shifted to the end of array\n";
for(i=index;i<n;i++)
{
ar[i]=ar[i+1];
}
n-=1;
cout<<"\n want to delete more ?(y/n)\n";
cin>>ch;}
cout<<"the array after shifting is:";
for(i=0;i<n;i++)

cout<<ar[i]<<" ";
cout<<endl;
getch();
}

int lsearch(int ar[],int size, int item)


{ for(int i=0;i<size;i++)
{ if(ar[i]==item)
return i;
}
return -1;
}

You might also like