Anda di halaman 1dari 48

NAME cbtes

Roll no. -16


Class XII-F
Programming file

Tyagi public school


CERTIFICATE
This is to certify that cbytes student
of class XII-f of Tyagi public school has
completed this FILE under the guidance
of MRS.SHASHI SHARMA MY,COMPUTER
SCIENCE in the academic session 2014-
2015.

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;

cout<<"Enter dimensions (row col):";

cin>>MaxR>>MaxC;

val=new int[MaxR*MaxC];

Rsum=new int [MaxR];

Csum=new int[MaxC];

for(i=0;i<MaxR;i++)

{cout<<"\n Enter elements of row"<<i+1<<":";

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

Enter dimensions(row col): 3 3

Enter elements of row 1: 1 2 3

Enter elements of row 2: 2 1 1

Enter elements of row 3: 3 2 2

The given array along with rowsum and colsum is :

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 Bsearch(int[ ],int,int);

int main()

{ int AR[50],ITEM,N,index;

cout<<Enter desired array size(max.50); cin>>N;

cout<<\nEnter array elements(must be sorted in asc. Order)\n;

for(int i=0;i<N;i++)

{cin>>AR[i];}

cout<<\nEnter element to be searched for;

cin>>ITEM;

index=Bsearch(AR,N,ITEM);

if(index==-1)

{cout<<\nSorry!!given element could not be found.\n;}

else

{cout<<\nElement found at index:<<index<<,position:<<index+1<<endl;}

return 0; }

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;

OUTPUT

Enter desired array size(max.50)7

Enter array elements (must be sorted in asc. Order)

2 5 7 8 9 10 15

Enter element to be searched for8

Element found at index:3,position:4


2. PROGRAM TO PERFORM THE BUBBLE SORTING IN THE
GIVEN ARRAY

#include<iostream.h>

void Bubblesort(int[ ],int);

int main()

int AR[50],ITEM,N,index;

cout<<How many elements do u want to create array with?(max.50);

cin>>N;

cout<<\nEnter array elements\n;

for(int=0;i<N;i++)

cin>>AR[i];

Bubblesort(AR,N);

cout<<\n\nThe sorted array is as shown below\n;

for(i=0;i<N;i++)

cout<<AR[i]<< ;

cout<endl;

return 0;

void Bubblesort(int AR[ ],int size)

int temp,ctr=0;

for(int i=0;i<size;i++)

{
for(int j=o;j<size;i++)

{ for( j=0;j<(size-1)- -i;j++)

{ if(AR[j]>AR[j+1])

{temp=AR[j];

AR[j]=AR[j+1];

AR[j+1]=temp;

cout<<Array after iteration-<<++ctr<<-is:;

for(int k=0;k<size;k++)

cout<<AR[k]<< ;

cout<<endl;

OUTPUT

How many elements do u want to create array array with?(max.50)5

Enter Array elements

9 7 4 6 1

Array after iteration-1-is: 7 4 6 1 9

Array after iteration-2-is: 4 6 1 7 9

Array after iteration-3-is: 4 1 6 7 9

Array after iteration-4-is:1 4 6 7 9

Array after iteration-5-is:1 4 6 7 9

The sorted array is as shown below


1 4 6 7 9

3. PROGRAM TO READ & DISPLAY THE DETAILS OF THE STUDENTS

#include<iostream.h>

#include<conio.h>

class student

{ int rno;

char name[30];

float marks;

public:

void getdata( )

{ cout<<"Enter the roll no of the student "; cin>>rno;

cout<<"Enter the name of the student"; cin.getline(name,30);

cout<<"Enter the marks of the student "; cin>>marks;

getch( );}

void putdata( )

{cout<<"Roll no"<<rno;

cout<<"Student Name";

cout.write(name,30);

cout<<"Student marks"<<marks;

getch( ); } };

main( )

{ student info[size]; int size,i;


cout<<"Enter the number of the students whose details you will read"; cin>>size;

cout<<"Enter the information of the students :-";

for(i=0;i<size:i++)

{ info[i].getdata( );}

cout<<" The details of the students are as follows :-";

for(i=0;i<size;i++)

{ info[i].putdata( );}

getch ();return 0;}

OUTPUT

Enter the number of the students whose details you will read

Enter the information of the students :-

Enter the roll no of the student 1

Enter the name of the student Joseph

Enter the marks of the student 89

Enter the roll no of the student 2

Enter the name of the student Franze

Enter the marks of the student 93

The details of the students are as follows :-

Roll no 1

Student name Joseph

Student marks 89

Roll no 2

Student name Franze


Student marks 93

4. PROGRAM TO READ A STRING OF TEXT AND DISPLAY THE


STRING WITH EACH PAIR OF ADJACENT LETTERS REVERSED IN
INDIVIDUAL WORDS

#include<iostream.h>

#include<stdio.h>

#include<string.h>

int main()

{ char string[50];

cout<<enter the string/lne of text:; gets(string);

int len=strlen(string);

int i,j,last=0;

for(i=0;i<len;) { j=i;

while(string[j]!= &&string[j]!=\0)j++; last =j;

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];

String[k+1]=ch1; } i=j+1; } cout<<string<<endl;

return 0;}

OUTPUT

Enter the string/line of text:computer science


ocpmture cseicne

5. PROGRAM TO CALCULATE INTEREST AMOUNT USING


DEFAULT ARGUMENTS

# include<iostream.h>

# include<conio.h>

# include<stdlib.h>

void amount (float princ,int time=2,float rate=0.08);

void amount(float princ,int time,float rate);

{ cout<<"\nPrincipal Amount :"<<princ;

cout<<"\tTime:"<<time<<"years";

cout<<,"\t rate:"<<rate;

cout<<"\n Interest amount :"<<(princ*time*rate)<<"\n"; }

main()

{ clrscr();

cout<<"case 1"; amount(2000);

cout<<"case 2"; amount(2500,3);

return 0; }

OUTPUT

Case 1

Principal Amount :2000 Time : 2years Rate:0.08

Interest Amount :320

Case 2

Principal amount :2500 Time :3years Rate:0.08


Interest Amount:600

6. PROGRAM TO DELETE THE GIVEN ELEMENT FROM THE ARRAY

#include<iostream.h>

#include<process.h>

int Lsearch(int[ ],int,int);

int main()

{ int AR[50],ITEM,N,index;

cout<<How many elements do u want to create array with?(max.50); cin>>N;

cout<<\nEnter array elements\n;

for(int i=0;i<N;i++) cin>>AR[i];

char ch=y;

while(ch==y//ch==Y)

{ cout<<\nEnter element 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;

cout<<\nThe array now is as shown below\n;

cout<<Zero(0) signifies deleted element\n;

for(i=0;i<N;i++)

cout<<AR[i]<< ;

cout<<After this emptied spae will be shifted to the end of array\n;


for(i=index;i<N;i++)

{ AR[i]=AR[i+1]; }

N-=1;

cout<<\nWant to delete more elements?(y/n);

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 ; }

int Lsearch(int AR[ ],intsize,int item)

{ for(int i=0;i<size;i++)

{ if(AR[i]==item) return i; }

return -1; }

OUTPUT

How many elements do u want to create array with?(max.50)10

Enter array elements

2 4 5 3 7 9 12 15 33 40

Enter elements to be deleted9

The array now is as shown below

Zero(0) signifies deleted element

2 4 5 3 7 0 12 15 33 40

After this emptied space will be shifted to the end of array

Want to delete more elements?(y/n)n

The array after shifting all emptied spaces towards right is:
2 4 5 3 7 12 15 33 40

7. PROGRAM TO INCREASE THE BASIC SALARY OF THE EMPLOYEES

#include<iostream.h>

#include<string.h>

#include<stidio.h>

Struct Employee { int empno;

char name[26];

float basic;

float experience; };

void display(Employee*emp);

void increase(Employee*emp);

int main()

{ Employee mgr,*eptr;

cout<<Enter employee number:; cin>>mgr.empno;

cout<<Enter name:; gets(mgr.name);

cout<<Enter basic pay:; cin>>mgr.basic;

cout<<Enter experience(in years); cin>>mgr.experience;

eptr=&mgr;

cout<<\nEmployee Details before increase()\n;

display(eptr);

increase(eptr);

cout\nEmployee details before increase()\n;

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)

{ if(emp-> experience>=10) Emp-> basic+=200; }

OUTPUT

Enter employee number:501

Enter name: abc

Enter basic pay:10000

Enter experience(in years):12

Employee details before increase()

Employee number:501

Name:abc

Basic:10000

Experience:12 years

Employee details after increase()

Employee number:501

Name :abc

Basic:10200
Experience:12 years

8. PROGRAM TO INSERT THE INFORMATION IN THE FILE

#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<<"Roll no:"; cin>>rollno;

cout<<"Name:"; cin>>name;

cout<<"Class:"; cin>>class;

cout<<"Marks"; cin>>marks;

if(marks>=75) grade='A';

else if(marks>=60) grade='B';

else if(marks>=50) grade='C'

else if(marks>=40) grade='D';

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);

char last ='y'; s1.getddata();

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);

cout<<"file now contains\n";

while(!fi.eof())
{ fi.read((char*)&stud,sizeof(stud));

if(fi.eof( )) break;

stud.putdata(); }

fi.close();

return 0;

OUTPUT

Enter the details of student whose record is to be entered:

Rollno:114

Name:Mira

Class:XII A

Marks:99

File now contains:

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

Student 1 : Name: Jenny

Marks:99

Student 2: Name: Charles

Marks:88

Student 3: Name: Maya

Marks:89

Student Name :Jenny marks:100

Student Name:Charles marks:100

Student name:Maya marks:100


10. PROGRAM TO FIND THE PRODUCT OF THE TWO MATICES

#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;

cout<<Input row&column A matrix:\n; cin>>m>>n;

cout<<Input rows & column of A materix:\n; cin>>p>>q;

if(n==p) cout<<Matrices can be multiplied.;

else { cout<<Matrices can not be multiplied.;

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

Input row & column of A matrix:

23

Input row &coloumn of B materx:

32

Matrices can be multiplied.

Input matrix-A:

1 2 3

1 2 3

Input matrix-B:

1 2

1 2

1 2

Product of A &B materices:

6 12

6 12
11. PROGRAM TO MERGE THE TWO GIVEN ARRAYS

#include<iostream.h>

void Merge(int[ ],it[,int [ ],int ,int[ ]);

int main()

{ int A[50],B[50],C[50],MN=O,M,N;

cout<<\n How many elements do u want to create first array with?(max.50);

cin>>M;

cout<<\nEnter first array\s element[ascending]\n;

for(int i=0;i<M;i++) cin>>A[i];

cout<<\nHow many elements do you want to create second array


with?(max.50);

cin>>N;

MN=M+N;

cout<<\nEnter second array\s elements[descending]\n;

for(i=0;i<N;i++0 cin>>B[i];

Merge(A,M,B,N,C);

cout<<\n\nThe merged array is as shown below\n;

for(i=0;i<MN;i++) c

cout<<C[i]<< ;

cout<<endl;

return 0; }

void Merge(int A[ ],int M,int B[ ],int N,int C[ ])

{ 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

How many elements do u you want to create first array with?(max.50)5

Enter first arrays elements [ascending]

2 5 8 9 12

How many elements do you want to create second array with?(max.50)..7

Enter second arrays elements[descending]

16 12 10 8 7 3 1

The merged array is shown below

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()

{ int*ip[4]; int f=65,s=67,t=69,fo=70;

ip[0]=&f; ip[2]=&t;

ip[1]=&s; ip[3]=&fo;

for(int i=0 ;i<4;i++)

cout<<"The pointers ip["<<i<<"]points to"<<*ip[i];

for(i=0;i<4;i++)

cout<<"The address stored in ip["<<i<<"] is"<<ip[i];

getch( );

return 0;

OUTPUT

The pointer ip[0] points to 65

The pointer ip[1] points to 67

The pointer ip[2] points to 69

The pointer ip[3] points to 70

The base address of array ip of pointers is 0x22f72422

The address stored in ip[0] is 0x22f72458

The address stored in ip[1] is 0x22f72456

The address stored in ip[2] is 0x22f72454


The address stored in ip[3] is 0x22f72450

13. PROGRAM TO POP THE ELEMENT FORM THE ARRAY STACK

#include<iostream.h>

#include<process.h>

int Pop(int[ ],int&);

int push(int[ ],int&,int);

void Display(int[ ],int);

Const int size=50;

int main()

{int Stack[size],item,top=-1,res;

char ch=y;

while(ch==y//ch==Y)

{ cout<<\n Enter Item for insertion:; cin>>Item;

res=push(stack,top,Item);

if (res==-1)

{cout<<overflow!!!Aborting!!; exit(1); }

cout<<\nThe stack now is:\n;

Display(stack,top);

cout<<\nWant to insert more elements?(y/n);

cin>>ch; }

cout<<Now deletion of elements begins\n;

ch=y;

while(ch==y!! ch==Y);

{res=pop(stack,top);
if(res==-1)

{ cout<<UNDERFLOW!!!Aborting!!\n;

exit(1); }

else

{ cout<<\nWant to delete more elements?...(y/n)\n;

cin>>ch;}

return 0;

int push(int stack[ ],int & top,int ele)

{ if(top==size-1)

return-1;

else

{ top++; Stack[top]=ele; }

return 0; }

int pop(int stack[ ],int&top)

{ int ret;

if (top==-1)

return -1;

else { ret=stack[top]; top--; }

return ret; }

void Display(int stack[ ],int top)

{ if(top==-1)

return;

cout<<stack[top]<< <<endl;
}

OUTPUT

Enter ITEM for insertion : 9

The stack now is :

9<--

Want to insert more elements?(y/n)...y

Enter ITEM for insertion :3

The stack now is :

3<--

Want to insert more elements ?(y/n)...n

Now deletion of elements begins...

Element deleted is :3

The stack now is :

9<--

Want to delete more elements?(y/n)...n


14. PROGRAM TO PRINT THE PRODUCT OF THE EACH ROW OF
THE 2-D ARRAY

#include<iostream.h>

#include<conio.h>

void prod();

main()

{ prod( ); getch( ); return 0; }

void prod( );

{int a[10][10],i,j,r,c,prod=1;

cout<<enter no. of rows and columns; cin>>r>>c;

cout<<enter the array elements;

for(i=0;i<r;i++)

{ for(j=0;j<c;j++) cin>>a[i][j];}

for(i=0;i<r;i++) { for(j=0;j<c;j++) prod*=a[i][j];

cout<<"Product of row"<<i+1<<"="<<prod[i]; }

return; }

OUTPUT

Enter no of rows and columns 2 2

Enter the elements of array

10 20

20 20

Product of row 1 = 2000

Product of row 2 = 4000


15. PROGRAM TO PRINT THE LARGEST NUMBER

#include<iostream.h>

int*big(int&,int&);

int main()

{ int a,b,*c;

cout<<Enter two integers\n;

cin>>a>>b;

c=big(a,b);

cout<<The bigger value is<<*c<<\n;

return 0;

int*big(int&x,int&y)

{ if(x>y)

return(&x);

else

return(&y);

OUTPUT

Enter two integers

7 13

The bigger value is 13


16. PROGRAM TO SHOW PUSHING IN THE LINKED QUEUE

#include<iostream.h>

#include<process.h>

struct Node { int info; Node*next;

}*front,*newptr,*save,*ptr,*rear;

Node*Create_New_node(int);

void Insert_End(Node*);

void display(Node*);

int main( )

{ front=rear=NULL;

int inf; char ch=y;

while(ch==y//ch==Y);

{ cout<<Enter INFORmation for the new node; cin>>inf;

newptr=create_new_node(inf);

if(newptr==NULL);

{cout<<cannot create new node!!!Aborting!!; exit( 1); }

Insert_End(newptr);

cout<</nPress Y to enter more nodes,N to exit; cin>>ch; }

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

Enter INFOrmation for the new node5

Now the queue(FronttoRear)is:

5->!!!

Press Y to enter more nodes,N to exity

Enter INFOrmation for the new node12

Now the queue(FronttoRear)is:

5->12->!!!
Press Y to enter more nodes,N to exitn

17. PROGRAM TO PRINT THE GLOBAL VARIABLES

#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<<Inner Block\n; cout<<a=<<a<<\n;

cout<<::a=<<::a<<\n; }

cout<<Back to main()<<\n; 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

18. PROGRAM TO REVERSE THE ARRAY

#include<iostream.h>

#include<conio.h>

int RevAr( int,int);

main()

int Ar[10],i;

cout<<"Enter the no. of the elements of the array";

cin>>size;

cout<<"Enter the array elements";

for(i=0;i<size;i++)

cin>>Ar[i];

cout<<" ";

RevAr( intAr[ ],int size);

cout<<"The Reversed array is";

for(i=0;i<size;i++)

cout<<Ar[i]<<" ";

getch();

return 0;
}

int RevAr(Ar[ ],int size)

inti=0,j=size-1,tmp;

for(;i<=j,i++,j--)

tmp=Ar[i];

Ar[i]=Ar[j];

Ar[j]=tmp;

return;

OUTPUT

Enter the no. of the elements of the array

Enter the array elements

25367341

The Reversed array is

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;

cout<<"Enter a string (max,80 characters)\n";

cin,getline(string,80);

cout<<"Enter a character to be searched for"; cin>>ch;

cp=NULL; cp=match(ch,string);

if(*cp)

{for(;(*cp!=\'0');cp++)

cout<<cp; }

else cout<<"no match found\n";

return0; }

char*match(char c,char*s)

{ while((c!=*s)&&(*s))

s++; return(s); }

OUTPUT

Enter a string (Max.80 characters )

I like computer science

Enter a character to be searched for

o
mputer science

20. PROGRAM OF PUSHING THE INFORMATION IN THE STACK

#include<iostream.h>

#include<stdlib.h>

#include<process.h>

Struct node { int info;

Node*next;

} *top,*newptr,*save,*ptr;

Node*create_new_node(int);

void push(node*);

void display(node*);

int main()

{ int inf; char ch=y;

top=NULL;clrscr( );

while(ch==y//ch==y)

{ cout<<enter INFOrmation for the new node; cin>>inf;

newptr=create_new_node(inf);

if (newptr==null)

{ cout<<cannot create new node!!!Aborting!!;exit(1) ; }

Push(newptr);

cout<<now the linked-stack is:;

Display(top);

cout<<press Y to enter more nodes,N to exit; cin>>ch; }

return 0; }
Node*create_new_node(int n);

{ ptr=new node;

ptr->info=n;

ptr->info=n;

ptr->next=null; return ptr; }

void push(node*np)

{ if(top==null)

Top=np;

else { if (top==null)

Top=np;

else

{ save=new node;

ptr-> info =n;

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

Enter INFOrmation for the new node5

Now the linked-stack is:

5->!!!

Press Y to enter more nodes ,N to exity

Enter INFOrmation for the new node8

Now the linked-stack is:

8-> 5->!!!

Press Y to enter more nodes ,N to exity

Enter INFOrmation for the new node...3

Now the liked -stack is:

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];

cout<< enter line of text: ; gets(sub);

cout<< enter substring to find: ; gets(sub);

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

Enter substrig to find:string

First occurance of string is at position 3

Last occurance of string is at position 56


22. PROGRAM TO SHOW TRAVERSAL IN THE ARRAY

#include<iostream.h>

#include<conio.h>

main()

{int ar[50],item ,n,index;

cout<<"How many elements do you want to create array with?(max.50)...";

cin>>n;

cout<<"Enter Array elements...";

for(int i=0;i<n;i++)

cin>>ar[i];

cout<<"Array with doubled elements is as follows..";

for(i=o;i<n;i++)

{ ar[i]*=2;

cout<<ar[i];

cout<<" ";

getch( ); return 0; }

OUTPUT

How many elements do u want to create an array with?(max.50)7

Enter array elements

2 5 7 9 12 20 25

Array with doubled elements is as follows


4 10 14 18 24 40 50

23. PROGRAM TO SWAP THE VARIBLES USING POINTERS

#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

24. PROGRAM TO DISPLAY THE TRANSPOSE OF THE MATRIX

#include<iostream.h>

#include<conio.h>

main()

{ clrscr( );

int a[3][3],b[3][3],i,j;

cout<<"Enter the elements of the matrix:";

for(i=0;i,3;i++)

{for(j=0;j<3;j++)

cin>>a[i][j];}

cout<<"\nGiven Matrix is:";

for(i=0;i<3;i++)

{ for(j=0;j<3;j++)

cout<<a[i][j]; }

cout<<"Transpose of the matrix is:";

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

Enter the elements of a matrix:

1 5 6

7 5 3

1 7 9

Given Matrix is:

1 5 6

7 5 3

1 7 9

The transpose of the matrix is:

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

Anda mungkin juga menyukai