Cs Samy
Cs Samy
Cs Samy
CLASS-XII
1
MULTIPLICATION OF 2-D
ARRAY
2
LINEAR SEARCH
3
Binary search
4
PUSH IN STACK.
5
POP FROM STACK
6
INSERTION
7
DELETION
8
SELECTION SORT
9
BUBBLE SORT
10
INSERTION SORT
11
INSERTION USING
LINKED
LIST
12
STATIC FUNCTION+
13
CONSTRUCTOR AND
DESTRUCTOR
14
COPY CONSTRUCTOR
15
INHERITANCE
16
STRUCTURES
17
FRIEND FUNCTION
18
STATIC FUNCTION
19
DATA FILE HANDALING
20
EQUALITY OF MATRICES
21
ENTERED CHARACTER..
#include<conio.h>
void main()
clrscr();
int a[2][3],b[3][2],c[3][3],k,i,j;
for(i=0;i<2;i++)
for(j=0;j<3;j++)
cin>>a[i][j];
cout<<"\n";
for(i=0;i<2;i++)
{
for(j=0;j<3;j++)
cout<<a[i][j]<<"\t";
cout<<"\n";
cout<<"\n\n";
for(i=0;i<3;i++)
for(j=0;j<2;j++)
cin>>b[i][j];
}
for(i=0;i<3;i++)
for(j=0;j<2;j++)
cout<<b[i][j]<<"\t";
cout<<"\n";
cout<<"\n";
cout<<"Product of 2 matrices";
for(i=0;i<2;i++)
cout<<"\n";
for(j=0;j<2;j++)
c[i][j]=0;
for(k=0;k<3;k++)
c[i][j]=c[i][j]+a[i][k]*b[k][i];
cout<<c[i][j]<<" ";
getch();
OUTPUT
2. LINEAR SEARCH
#include<iostream.h>
#include<conio.h>
void main()
clrscr();
int A[10],size,i,flag=0,num,pos;
cin>>size;
for(i=0;i<size;i++)
cin>>A[i];
cin>>num;
for(i=0;i<size;i++)
if(A[i]==num)
{flag=1;
pos=i;
break;
if(flag==0)
else
getch();
OUTPUT
3. Binary search
#include<iostream.h>
#include<conio.h>
int bsearch(int[],int,int);
void main()
clrscr();
int a[10],i,j,size,index;
cin>>size;
for(i=0;i<size;i++)
cin>>a[i];
cin>>j;
index=bsearch(a,size,j);
if(index==-1)
else
getch();
int b,l,m;
b=0;
l=n-1;
while(b<=l)
m=(b+l)/2;
if(y==a[m])
return m;
else l=m-1;
return -1;
OUTPUT
4. PUSH IN STACK.
#include<iostream.h>
#include<conio.h>
#include<process.h>
int push(int[],int&,int);
void display(int[],int);
void main()
{
clrscr();
int stack[size],top=-1,res,item;
char ch='y';
while(ch=='y'||ch=='Y')
cin>>item;
res=push(stack,top,item);
if(res==-1)
cout<<"overflow"<<endl;
exit(1);
cout<<"stack is now:";
display(stack,top);
cin>>ch;
getch();
else
top++;
stack[top]=ele;
return 0;
}
cout<<stack[top]<<"<--"<<endl;
for(int i=top-1;i>=0;i--)
cout<<stack[i]<<endl;
OUTPUT
5. POP FROM STACK
#include<iostream.h>
#include<conio.h>
#include<process.h>
#include<stdlib.h>
int pop(int[],int&);
void display(int[],int);
void main()
clrscr();
int stack[size],item,res,top=-1;
char ch='y';
while(ch=='y'||ch=='Y')
{
cout<<"enter element to insert:"<<endl;
cin>>item;
res=push(stack,top,item);
if(res==-1)
cout<<"overflowed";
exit(1);
cout<<"stack is now:"<<endl;
display(stack,top);
cin>>ch;
ch='Y';
while(ch=='y'||ch=='Y')
res=pop(stack,top);
if(res==size-1)
cout<<"underflow";
exit(1);
else
display(stack,top);
getch();
else
top++;
stack[top]=ele;
return 0;
int ret;
else
ret=stack[top];
top--;
return ret;
cout<<stack[top]<<"<--"<<endl;
for(int i=top-1;i>=0;i--)
cout<<stack[i]<<endl;
}
OUTPUT
6. INSERTION
#include<iostream.h>
#include<conio.h>
void main()
clrscr();
int i,a[5],n,pos;
for(i=0;i<5;i++)
cin>>a[i];
}
cin>>pos;
if(pos>5)
cout<<"over flow";
else
cin>>n;
--pos;
a[i+1]=a[i];
}
a[pos]=n;
cout<<"new array";
cout<<a[i];
getch();
output
7. DELETION
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int i,a[5],n,pos;
for(i=0;i<5;i++)
cin>>a[i];
cin>>pos;
if(pos>5)
cout<<"over flow";
{
a[i]=a[i+1];
cout<<"new array";
cout<<a[i];
getch();
OUTPUT
8. SELECTION SORT
#include<iostream.h>
#include<conio.h>
void selsort(int[],int);
void main()
clrscr();
int a[10],size,item,index;
cin>>size;
cout<<"enter element:";
for(int i=0;i<size;i++)
cin>>a[i];
selsort(a,size);
for(i=0;i<size;i++)
cout<<a[i]<<" ";
cout<<endl;
getch();
int small,pos,temp;
for(int i=0;i<n-1;i++)
small=a[i];
pos=i;
for(int j=i+1;j<n;j++)
if(a[j]<small)
small=a[j];
pos=j;
temp=a[i];
a[i]=a[pos];
a[pos]=temp;
for(j=0;j<n;j++)
cout<<a[j]<<" ";
OUTPUT
9. BUBBLE SORT
#include<iostream.h>
#include<conio.h>
void main()
clrscr();
void bub_sort(int[],int);
int ar[10];
int size;
cout<<"Enter the size of an array \n";
cin>>size;
for(int i=0;i<size;i++)
cin>>ar[i];
for(i=0;i<size;i++)
cout<<ar[i]<<" ";
bub_sort(ar,size);
for(i=0;i<size;i++)
{
cout<<ar[i]<<" ";
getch();
int temp;
for(int i=0;i<sz;i++)
for(int j=0;j<sz-1;j++)
if(ar[j]>ar[j+1])
{
temp=ar[j];
ar[j]=ar[j+1];
ar[j+1]=temp;
OUTPUT
10. INSERTION SORT
#include<iostream.h>
#include<conio.h>
#include<limits.h>
void insort(int[],int);
void main()
clrscr();
int a[10],size,item,index;
cin>>size;
cout<<"enter element:";
for(int i=1;i<=size;i++)
cin>>a[i];
insort(a,size);
for(i=1;i<=size;i++)
cout<<a[i]<<" ";
cout<<endl;
getch();
int temp,j;
a[0]=INT_MIN;
for(int i=1;i<=n;i++)
temp=a[i];
j=i-1;
while(temp<a[j])
a[j+1]=a[j];
j--;
a[j+1]=temp;
for(int k=1;k<=n;k++)
cout<<a[k]<<" ";
cout<<endl;
OUTPUT
11. INSERTION USING LINKED LIST
#include<iostream.h>
#include<conio.h>
struct node
{ int info;
node*next;
}
*ptr,*newptr,*save,*next,*start;
node*new_node(int);
void ins(node*);
void dis(node*);
void main()
clrscr();
start=NULL;
int inf;
char ch='y';
while(ch=='y'||ch=='Y')
{
cin>>inf;
newptr=new_node(inf);
ins(newptr);
dis(start);
cin>>ch;
}
getch();
node* new_node(int n)
ptr=new node;
ptr->info=n;
ptr->next=NULL;
return ptr;
{
if(start==NULL)
start=np;
else
save=start;
start=np;
np->next=save;
void dis(node*st)
while(st!=NULL)
cout<<st->info<<"->";
st=st-> next;
}
OUTPUT
12. STATIC FUNCTION
#include<iostream.h>
#include<conio.h>
#include<process.h>
int insert(int[],int);
void display(int[],int,int);
int queue[size],front=-1,rear=-1;
void main()
clrscr();
int item,res;
char ch='y';
while(ch=='y'||ch=='Y')
{
cout<<"enter item:";
cin>>item;
res=insert(queue,item);
if(res==-1)
cout<<"overflowed";
exit(1);
display(queue,front,rear);
cin>>ch;
getch();
}
int insert(int queue[],int ele)
else if(rear==-1)
front=rear=0;
queue[rear]=ele;
else
{rear++;
queue[rear]=ele;}
return 0;
{
if(front==-1) return;
for(int i=front;i<rear;i++)
cout<<queue[i]<<"<--\t";
cout<<queue[rear]<<endl;
OUTPUT
#include<conio.h>
int count=0;
class des
public:
des()
count++;
cout<<"Constructor "<<count<<"\n";
~des()
cout<<"Desructor "<<count<<"\n";
count--;
}
};
void main()
clrscr();
des a,b;
des c;
des d;
}
cout<<"\n"<<count;
getch();
OUTPUT
14. COPY CONSTRUCTOR
#include<iostream.h>
#include<conio.h>
class con
int a;
int b;
public:
con()
}
con(int i,int j=100)
a=i;
b=j;
cout<<a<<" "<<b<<"\n";
con(con &i)
a=i.a;
b=i.b;
}
};
void main()
clrscr();
con c1;
con c2(120);
con c3=c2;
getch();
OUTPUT
15. INHERITANCE
#include<iostream.h>
#include<conio.h>
class A
{ int a;
public:
void read()
cin>>a;
cout<<"\n";
}
void disp()
{ cout<<a<<endl;
};
class B:public A
{ char b;
public:
void reading()
cin>>b;
cout<<"\n";
void display()
{ cout<<b;
}
};
void main()
{ clrscr();
A ob1;
B ob2;
ob1.read();
ob1.disp();
ob2.read();
ob2.disp();
ob2.reading();
ob2.display();
getch();
OUTPUT
16. INSERTION SORT
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
void main()
clrscr();
int i,ch;
struct emp
char name[10];
int salary;
int contact;
char address[10];
int code;
};
emp s1[2];
for(i=0;i<2;i++)
cout<<"enter code";
cin>>s1[i].code;
gets(s1[i].name);
cin>>s1[i].salary;
cin>>s1[i].contact;
cout<<"\n\n";
for(i=0;i<2;i++)
cout<<"employe"<<i+1<<"\n";
cout<<"name = ";
cout.write(s1[i].name,10)<<"\n";
cout<<"salary="<<s1[i].salary<<"\n";
cout<<"address = ";
cout.write(s1[i].address,10)<<"\n";
cout<<"\n";
}
getch();
OUTPUT
#include<conio.h>
class B;
class A
{ int a;
public:
void set(int i)
{ a=i;
};
class B
{ int b;
public:
void set(int i)
{ b=i;
};
if(x.a>y.b)
cout<<x.a<<" is greater";
else
}
void main()
{ clrscr();
A abc;
B xyz;
int a,b;
cin>>a>>b;
abc.set(a);
xyz.set(b);
max(abc,xyz);
getch();
}
OUTPUT
#include<conio.h>
class stat
stat()
++count;
cout<<"hello "<<count<<"\n";
};
int stat::count;
void main()
clrscr();
stat s1,s2,s3;
stat::counting();
getch();
OUTPUT
19. DATA FILE HANDALING
#include<iostream.h>
#include<fstream.h>
#include<conio.h>
void main()
{ clrscr();
char n;
int m;
ofstream fo("file.txt",ios::trunc);
cin>>n;
cin>>m;
fo<<n<<"\n"<<m;
fo.close();
//
ifstream fin("file.txt",ios::in);
fin>>n>>m;
cout<<n<<endl<<m;
fin.close();
getch();
OUTPUT
#include<conio.h>
void main()
clrscr();
int m[3][3],n[3][3],i,j,result;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
cin>>m[i][j];
cout<<"\n";
for(i=0;i<3;i++)
for(j=0;j<3;j++)
cin>>n[i][j];
cout<<"\n";
}
for(i=0;i<3;i++)
for(j=0;j<3;j++)
cout<<m[i][j]<<" ";
cout<<"\n";
for(i=0;i<3;i++)
for(j=0;j<3;j++)
{
cout<<n[i][j]<<" ";
cout<<"\n";
for(i=0;i<3;i++)
{ for(j=0;j<3;j++)
if(m[i][j]==n[i][j])
result=1;
else
result =0;
if(result==1)
getch();
OUTPUT
21. ENTERED CHARACTER..
#include<iostream.h>
#include<conio.h>
#include<ctype.h>
void main()
clrscr();
char ch;
cin>>ch;
if(isdigit(ch))
{int a;
ch=a;
cout<<"it is a digit";
if(a=0-a)
cout<<"it is negative"<<"\n";}
else
{cout<<"it is a positive number"<<"\n"; }
else if(isalpha(ch))
cout<<"it is a alphabet"<<"\n";
switch(ch)
case'a':cout<<"\n"<<"it is a vowel";break;
case'e':cout<<"\n"<<"it is a vowel";break;
case'i':cout<<"\n"<<"it is a vowel";break;
case'o':cout<<"\n"<<"it is a vowel";break;
case'u':cout<<"\n"<<"it is a vowel";break;
case'A':cout<<"\n"<<"it is a vowel";break;
case'E':cout<<"\n"<<"it is a vowel";break;
case'I':cout<<"\n"<<"it is a vowel";break;
case'O':cout<<"\n"<<"it is a vowel";break;
case'U':cout<<"\n"<<"it is a vowel";break;
if(islower(ch))
else if(isupper(ch))
getch();
}
OUTPUT