Teachers signaTure
Acknowledgement
I cbytes would like to thanks
Mrs.shashi mam to give me the idea of
making this file and helping me in all
aspects.I further like to thanks My
family and my friends as they
understand my work and also helps me
wherever I need their help.so, thank
you all for be there with me when I need
your advice and also helps me in
clearing my doubts .I REALLY RESPECT
YOUR OPINIONS.THANK YOU FOR YOUR
SUPPORT.
1. PROGRAM TO FIND THE ROWSUM AND THE COLUMN SUM OF
THE MATRIX
#include<iostream.h>
#include<conio.h>
int main()
{ int *val,*Rsum,*Csum;
int MaxR,MaxC,i,j;
cin>>MaxR>>MaxC;
val=new int[MaxR*MaxC];
Csum=new int[MaxC];
for(i=0;i<MaxR;i++)
Rsum[i]=0;
for(j=0;j<MaxC;j++)
{ cin>>val[i*MaxC+j];
Rsum[i]+=val[i*MaxC+j];} }
for(j=0;j<MaxC;j++)
{ Csum[j]=0;
for(i=0;i<MaxR;i++)
{ Csum[j]=0;
for(i=0;i<MaxR;i++)
{ Csum[j]+=val[i*MaxC+J];}
} cout<<"\n\nThe given array along with Rowsum and Colsum is:\n\n";
for(i=0;i<MaxR;i++)
{ for(j=0;j<MaxC;j++)
{for(j=0;j<MaxC;j++)
{cout<<val[i*MaxC+j]<<"\t"; }
cout<<Rsum[i]<<endl;}
for(j=0;j<MaxC;j++)
{ cout<<Csum[j]<<'\t'; }
return 0;
OUTPUT
1 2 3 6
2 1 1 4
3 2 2 7
6 5 6
1. PROGRAM TO SEARCH THE ELEMENT IN THE ARRAY BY USING
THE BINARY SEARCH
#include<iostream.h>
int main()
{ int AR[50],ITEM,N,index;
for(int i=0;i<N;i++)
{cin>>AR[i];}
cin>>ITEM;
index=Bsearch(AR,N,ITEM);
if(index==-1)
else
return 0; }
{ 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;
OUTPUT
2 5 7 8 9 10 15
#include<iostream.h>
int main()
int AR[50],ITEM,N,index;
cin>>N;
for(int=0;i<N;i++)
cin>>AR[i];
Bubblesort(AR,N);
for(i=0;i<N;i++)
cout<<AR[i]<< ;
cout<endl;
return 0;
int temp,ctr=0;
for(int i=0;i<size;i++)
{
for(int j=o;j<size;i++)
{ if(AR[j]>AR[j+1])
{temp=AR[j];
AR[j]=AR[j+1];
AR[j+1]=temp;
for(int k=0;k<size;k++)
cout<<AR[k]<< ;
cout<<endl;
OUTPUT
9 7 4 6 1
#include<iostream.h>
#include<conio.h>
class student
{ int rno;
char name[30];
float marks;
public:
void getdata( )
getch( );}
void putdata( )
{cout<<"Roll no"<<rno;
cout<<"Student Name";
cout.write(name,30);
cout<<"Student marks"<<marks;
getch( ); } };
main( )
for(i=0;i<size:i++)
{ info[i].getdata( );}
for(i=0;i<size;i++)
{ info[i].putdata( );}
OUTPUT
Enter the number of the students whose details you will read
Roll no 1
Student marks 89
Roll no 2
#include<iostream.h>
#include<stdio.h>
#include<string.h>
int main()
{ char string[50];
int len=strlen(string);
int i,j,last=0;
for(i=0;i<len;) { j=i;
if(j%2==0)last=j;
else last=j-1;
char ch1;
for(int k=i;k<last;k+=2)
{ Ch1=string[k];
String[k]=string[k+1];
return 0;}
OUTPUT
# include<iostream.h>
# include<conio.h>
# include<stdlib.h>
cout<<"\tTime:"<<time<<"years";
cout<<,"\t rate:"<<rate;
main()
{ clrscr();
return 0; }
OUTPUT
Case 1
Case 2
#include<iostream.h>
#include<process.h>
int main()
{ int AR[50],ITEM,N,index;
char ch=y;
while(ch==y//ch==Y)
if(N==0)
{cout<<underflow!!\n; exit(1); }
index=Lsearch(AR,N,ITEM);
if(index!=-1) AR[index]=0;
else
for(i=0;i<N;i++)
cout<<AR[i]<< ;
{ AR[i]=AR[i+1]; }
N-=1;
cin>>ch; }
cout<<\nThe array after shifting ALL emptied space towards right is\n;
for(i=0;i<N;i++)
cout<<AR[i]<< ; return 0 ; }
{ for(int i=0;i<size;i++)
{ if(AR[i]==item) return i; }
return -1; }
OUTPUT
2 4 5 3 7 9 12 15 33 40
2 4 5 3 7 0 12 15 33 40
The array after shifting all emptied spaces towards right is:
2 4 5 3 7 12 15 33 40
#include<iostream.h>
#include<string.h>
#include<stidio.h>
char name[26];
float basic;
float experience; };
void display(Employee*emp);
void increase(Employee*emp);
int main()
{ Employee mgr,*eptr;
eptr=&mgr;
display(eptr);
increase(eptr);
display(eptr);
return 0 ;}
void display(Employee*emp)
{ int len=strlen(emp->name);
cout<<Employeee number<<emp->empno;
cout<<\nName:;
cout.write(emp->name,len);
cout<<\tBasic:<<emp->basic;
cout<<\tExperience:<<emp->experience<<years\n; }
void increase(Employee*emp)
OUTPUT
Employee number:501
Name:abc
Basic:10000
Experience:12 years
Employee number:501
Name :abc
Basic:10200
Experience:12 years
#include<iostream.h>
#include<fstream.h>
#include<stidio.h>
class stu { int rollno; char name[25]; char class[4]; float marks; char grade;
public:
void getdata()
cout<<"Name:"; cin>>name;
cout<<"Class:"; cin>>class;
cout<<"Marks"; cin>>marks;
if(marks>=75) grade='A';
else grade='F'; }
void putdata()
{cout<<"Rollno"<<rollno<<"\tName:"<<name<<"\nMarks:";
cout<<marks<<"\tGrade:"<<grade<<endl; }
int getrno( )
{ return rollno; }
}s1,stud;
int main()
{ ifstream fi("stu.dat",ios::in);
ofstream fo("temp.dat",ios::out);
while(!fi.eof() )
{ fi.read((char*)&stud,sizeof(stud));
if(s1.getrno()<=stud.getrno() )
{ fo.write( (char*)&s1,sizeof(s1));
last='n'; break; }
else
fo.write( (char*)&stud,sizeof(stud)); }
if(last=='y')
fo.write( (char*)&s1,sizeof(s1));
else if(!fi.eof())
{ while(!fi.eof())
{ fi.read((char*)&stud,sizeof(stud));
fo.write((char*)&stud,sizeof(stud)) }}
fi.close();
fo.close();
remove("stu.dat");
rename("temp.dat","stu.dat");
fi.open("stu.dat",ios::in);
while(!fi.eof())
{ fi.read((char*)&stud,sizeof(stud));
if(fi.eof( )) break;
stud.putdata(); }
fi.close();
return 0;
OUTPUT
Rollno:114
Name:Mira
Class:XII A
Marks:99
Rollno:102 Name:joseph
Marks:67 Grade:B
Rollno:114 Name:Mira
Marks:99 Grade:A
9. PROGRAM TO CREATE A FILE AND DISPLAY ITS CONTENT
#include<iostream.h>
#include<fstream.h>
#include<stdlib.h>
main()
{ ofstream fout(student,ios::out);
char name[30],ch;
float marks=0.0;
for(int i=0;i<3;i++)
{ cout<<student<<(i+1)<<:\tName:;
cin.get(name,30)
cout<<\t\tMarks:;
cin>>marks;
cin.get(ch);
fout<<name<<\n<<marks<<\n;
fout.close();
ifstream fin(student,ios::in);
fin.seekg(0);
cout<<\n;
for(i=0;i<3;i++)
{ fin.get(name,30);
fin.get(ch);
fin>>marks;
fin.get(ch);
cout<<Student Name:<<name;
cout<<\t Marks:<<marks<<\n;
fin.close();
return 0;
OUTPUT
Marks:99
Marks:88
Marks:89
#include<iostream.h>
#include<process.h>
int main()
{ int A[10][10],B[10][10],C[10][10],I,j,m,n,p,q,ip;
exit(0); }
cout<<\nInput matrix-A:\n;
for(i=0;i<m;++i)
{for(j=0;j<n;++j)
cin>>A[i][j];}
cout<<\nInput matrix-B:\n;
for(i=0;i<p;++i)
{for(j=0;j<q;++j)
cin>B[i][j]; }
for(i=0;i<m;++i)
for(j=0;j<q;++j)
{ C[i][j]=0;
for(ip=0;ip<n;++ip)
C[i][j]+=A[i][j]*B[i][j];
cout<<\nProduct of A and B matrices:;
for(i=0;i<m;++i)
{cout<<\n;
for(j=0;j<q;++j)
cout<<C[i][j]<< ;}
return 0; }
OUTPUT
23
32
Input matrix-A:
1 2 3
1 2 3
Input matrix-B:
1 2
1 2
1 2
6 12
6 12
11. PROGRAM TO MERGE THE TWO GIVEN ARRAYS
#include<iostream.h>
int main()
{ int A[50],B[50],C[50],MN=O,M,N;
cin>>M;
cin>>N;
MN=M+N;
for(i=0;i<N;i++0 cin>>B[i];
Merge(A,M,B,N,C);
for(i=0;i<MN;i++) c
cout<<C[i]<< ;
cout<<endl;
return 0; }
{ int a,b,c;
for(a=0,b=-1,c=0;a<M&&b>=0;)
{ if(A[a]<=B[b]C[c++]=A[a++];
Else{ C[c++]=B[b--]; }
if(a<M)
{C[c++]=A[a++]; }
else
{while (b>=0)
C[c++]=B[b--];
OUTPUT
2 5 8 9 12
16 12 10 8 7 3 1
1 2 3 5 7 8 9 10 12 12 16
12. PROGRAM TO PRINT DIFFERENT VALUES BEING POINTING TO
BY AN ARRAY OF THE POINTER
#include<iostream.h>
# include<conio.h>
main()
ip[0]=&f; ip[2]=&t;
ip[1]=&s; ip[3]=&fo;
for(i=0;i<4;i++)
getch( );
return 0;
OUTPUT
#include<iostream.h>
#include<process.h>
int main()
{int Stack[size],item,top=-1,res;
char ch=y;
while(ch==y//ch==Y)
res=push(stack,top,Item);
if (res==-1)
{cout<<overflow!!!Aborting!!; exit(1); }
Display(stack,top);
cin>>ch; }
ch=y;
while(ch==y!! ch==Y);
{res=pop(stack,top);
if(res==-1)
{ cout<<UNDERFLOW!!!Aborting!!\n;
exit(1); }
else
cin>>ch;}
return 0;
{ if(top==size-1)
return-1;
else
{ top++; Stack[top]=ele; }
return 0; }
{ int ret;
if (top==-1)
return -1;
return ret; }
{ if(top==-1)
return;
cout<<stack[top]<< <<endl;
}
OUTPUT
9<--
3<--
Element deleted is :3
9<--
#include<iostream.h>
#include<conio.h>
void prod();
main()
void prod( );
{int a[10][10],i,j,r,c,prod=1;
for(i=0;i<r;i++)
{ for(j=0;j<c;j++) cin>>a[i][j];}
cout<<"Product of row"<<i+1<<"="<<prod[i]; }
return; }
OUTPUT
10 20
20 20
#include<iostream.h>
int*big(int&,int&);
int main()
{ int a,b,*c;
cin>>a>>b;
c=big(a,b);
return 0;
int*big(int&x,int&y)
{ if(x>y)
return(&x);
else
return(&y);
OUTPUT
7 13
#include<iostream.h>
#include<process.h>
}*front,*newptr,*save,*ptr,*rear;
Node*Create_New_node(int);
void Insert_End(Node*);
void display(Node*);
int main( )
{ front=rear=NULL;
while(ch==y//ch==Y);
newptr=create_new_node(inf);
if(newptr==NULL);
Insert_End(newptr);
return 0; }
Node*Create_New_Node(int n);
{ ptr=new node;
ptr->info=n;
ptr->next=NULL;
return ptr; }
void insert_end(node*np)
{ if (front==NULL)front=rear=np;
else
{rear->next=np;
rear=np; }
void display(Node*np)
{ while (np!=NULL)
{cout<<np->info<<->;
np=np->next; }
cout<<!!!\n;
OUTPUT
5->!!!
5->12->!!!
Press Y to enter more nodes,N to exitn
#include<iostream.h>
int a=10;
int main()
{ int a=15;
cout<<Main()<<\n;
cout<<a=<<a<<\n;
cout<<::a=<<::a<<\n;
{ int a=25;
cout<<::a=<<::a<<\n; }
cout<<::a=<<::a<<\n; return 0; }
OUTPUT
main()
a=15
::a=10
Inner Block
a=25
::a=10
Back to main()
a=15
::a=10
#include<iostream.h>
#include<conio.h>
main()
int Ar[10],i;
cin>>size;
for(i=0;i<size;i++)
cin>>Ar[i];
cout<<" ";
for(i=0;i<size;i++)
cout<<Ar[i]<<" ";
getch();
return 0;
}
inti=0,j=size-1,tmp;
for(;i<=j,i++,j--)
tmp=Ar[i];
Ar[i]=Ar[j];
Ar[j]=tmp;
return;
OUTPUT
25367341
14376352
19. PROGRAM TO SEARCH FOR A GIVEN CHARACTER INSIDE A
STRING AND TO PRONT THE STRING FROM THE POINT OF MATCH
#include<iostream.h>
char*match(char,char*);
main()
{ char string[80],*cp,ch;
cin,getline(string,80);
cp=NULL; cp=match(ch,string);
if(*cp)
{for(;(*cp!=\'0');cp++)
cout<<cp; }
return0; }
char*match(char c,char*s)
{ while((c!=*s)&&(*s))
s++; return(s); }
OUTPUT
o
mputer science
#include<iostream.h>
#include<stdlib.h>
#include<process.h>
Node*next;
} *top,*newptr,*save,*ptr;
Node*create_new_node(int);
void push(node*);
void display(node*);
int main()
top=NULL;clrscr( );
while(ch==y//ch==y)
newptr=create_new_node(inf);
if (newptr==null)
Push(newptr);
Display(top);
return 0; }
Node*create_new_node(int n);
{ ptr=new node;
ptr->info=n;
ptr->info=n;
void push(node*np)
{ if(top==null)
Top=np;
else { if (top==null)
Top=np;
else
{ save=new node;
ptr->next=null;
return ptr; }
void push(node*np)
{ if(top==null)
Top=np;
else
{ save=top;
Top=np;
np->next=save; }
void display(node*np)
{ while(np!=null)
{cout<<np->info<<->;
np=np->next; }
cout<<!!!\n;
OUTPUT
5->!!!
8-> 5->!!!
3->8->5->!!!
21. PROGRAM THAT INPUTS A LINE OF TEXT AND A SUBSTRING
TO SEARCH FOR .THEN IT SHOULD DISPLAY THE POSITION OF
FIRST AND THE LAST POSITION OF THAT SUBSTRING
#include<iostream.h>
#include<stdio.h>
#include<string.h>
int main()
{ char line[80];
char sub[15];
int len=strlen(line);
int i,j,k,spos,lpos;
for(i=0;i<len;)
{ j=i;
if(line[j]==sub[0])
{ j=i;
if(line[j]==sub[0])
{k =0;
while(line[j++]==sub[k++]);
if(sub[k-1]== \0 )
{ spos=i;break; }
else
i=j-1; }
else
i++; }
int len2=strlen(sub);
for(i=len-1;i>=0;)
{ j=i;
if(line[j]==sub[len2-1]
{k=len2-1;
while(line[j--]==sub[k--]);
if(k<0)
{ lpos=j+2;
break; }
else
i- -;
OUTPUT
Enter line of text:a string such as this string holds another string even strings in it
#include<iostream.h>
#include<conio.h>
main()
cin>>n;
for(int i=0;i<n;i++)
cin>>ar[i];
for(i=o;i<n;i++)
{ ar[i]*=2;
cout<<ar[i];
cout<<" ";
getch( ); return 0; }
OUTPUT
2 5 7 9 12 20 25
#include<iostream.h>
int main()
{ void swap(int*x,int*y);
int a=7,b=4;
cout<<Original values\n;
cout<<a=<<a<<,b=<<b<<\n;
swap(&a,&b);
cout<<Swapped Values\n;
cout<<a=<<a<<,b=<<b<<\n;
return 0;
void swap(int*x,int*y)
{ int temp;
temp=*x;
*x=*y;
*y=temp;
OUTPUT
Original values
a=7, b=4
Swapped Valus
a=4, b=7
#include<iostream.h>
#include<conio.h>
main()
{ clrscr( );
int a[3][3],b[3][3],i,j;
for(i=0;i,3;i++)
{for(j=0;j<3;j++)
cin>>a[i][j];}
for(i=0;i<3;i++)
{ for(j=0;j<3;j++)
cout<<a[i][j]; }
for(i=0;i<3;i++)
cout<<"\n";
for(j=0;j<3;j++)
{ b[i][j]=a[j][i];
cout<<b[i][j]<<" ";
}
return 0;}
OUTPUT
1 5 6
7 5 3
1 7 9
1 5 6
7 5 3
1 7 9
1 7 1
5 5 7
6 3 9
BIBLIOGRAPHY
COMPUTER SCIENCE WITH c++
TEXTBOOK CLASS XI & CLASS XII
SAMPLE PAPERS OF COMPUTER
SCIENCE
CBSE WEBSITE
OTHER RELATED BOOKS & SAMPLE
PAPERS