Sie sind auf Seite 1von 38

PROGRAMS

1.\\

#include<fstream.h>

#include<iostream.h>

#include<string.h>

void main()

int countis();

int count;

count=countis();

cout<<"Count of number of times word is or are appeared is ";

cout<<count;

int countis()

int c=0;

char ch[20];

ifstream fin;

fin.open("dialogue.txt",ios::in);

while(fin)

fin>>ch;

if(strcmp(ch,"is")==0||strcmp(ch,"are")==0)

c++;

fin.close();
return(c);
}

OUTPUT
2.\\

#include<iostream.h>

#include<stdlib.h>

#define size 5

class stack

int r[size];

int top;

public:

stack()

top=-1;

void push ();

void pop();

void display();

};

void stack::push()

{
int rno;

cout<<"enter the roll number = ";

cin>>rno;

if(top==size-1)

cout<<"stack is full\n";

else

top++;
r[top]=rno;
}

void stack::pop()

int rno1;

if(top==-1)

cout<<"stack empty\n";

else

rno1=r[top];

top--;

cout<<"\n deleted roll number is\t"<<rno1;

void stack::display()

int i;

for(i=top;i>=0;i--)

cout<<r[i]<<"\n";

}
void main()

int choice;

stack s;

char ans='y';

while((ans=='y')||(ans=='Y'))

{
cout<<"main menu\n";
cout<<"1. To push\n";

cout<<"2. To pop\n";

cout<<"3. To display\n";

cout<<"4. To quit\n";

cout<<"enter choice = ";

cin>>choice;

switch(choice)

case 1:s.push();

break;

case 2:s.pop();

break;

case 3:s.display();

break;

default:exit(0);

cout<<"\n do you want to continue\n";

cin>>ans;

}
}

OUTPUT
3.\\
#include <iostream.h>

class myarray

int arr[100];

int n;

public:

void readarray();

void displayarray();

int linearsearch(int y);

};

void selsort(int [],int);

void selsort(int arr[],int n)

int small,temp,pos,i,j;

for(i=0;i<n-1;i++)

small=arr[i];

pos=i;

for(j=i+1;j<n;j++)

if(arr[j]<small)

small=arr[j];

pos=j;
}

temp=arr[i];

arr[i]=arr[pos];

arr[pos]=temp;

void myarray::readarray()

int i;

cout<<"\nEnter the size of array\n";

cin>>n;

cout<<"\nEnter the elements of array\n";

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

cin>>arr[i];

selsort(arr,n);

void myarray::displayarray()

int i;

cout<<"The array is:\n";

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

{
cout<<arr[i]<<" ";

int myarray::linearsearch(int y)

int i;

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

if(arr[i]==y)

return(i);

return -1;

void main()

int y,index,ch;

myarray s;

char ch1;

do{

cout<<" Main Menu\n";

cout<<"1.Create Array\n";

cout<<"2.Display Array\n";

cout<<"3.Search element in Array\n";

cout<<"\n Enter choice\n";

cin>>ch;
switch(ch)

case 1:s.readarray();

break;

case 2:s.displayarray();

break;

case 3:cout<<"Enter the value to be searched for\n";

cin>>y;

index=s.linearsearch( y);

if(index==-1)

cout<<"`\nSorry!! given element could not be found\n";

else

cout<<"\nElement found at
index:"index:"<<index<<",position"<<index+1;

break;

default: cout<<"invalid choice\n";

cout<<"\n Do you want to continue ?\n";

cin>>ch1;

}while((ch1=='y')||(ch1=='Y'));

OUTPUT
4.\\

#include<iostream.h>

#include<fstream.h>

#include<string.h>

#include<stdio.h>

#include<conio.h>

class batsmen

char Firstname[20];

char Lastname[20];

int Runsmade;

int Number_of_fours;

int Number_of_sixes;

public:

batsmen()

strcpy(Firstname,"NULL");

strcpy(Lastname,"NULL");

Runsmade=0;
Number_of_fours=0;

Number_of_sixes=0;

void enter_information()

cout<<"\nenter your first name: \n";

gets(Firstname);
cout<<"\nenter your last name: \n";
gets(Lastname);

cout<<"\nenter runs made: \n";

cin>>Runsmade;

cout<<"\nenter number of fours \n";

cin>>Number_of_fours;

cout<<"\nenter number of sixes \n";

cin>>Number_of_sixes;

void update_runsmade()

cout<<"\nenter runs made: \n";

cin>>Runsmade;

void display_information()

cout<<"\nfirst name: \n";

puts(Firstname);

cout<<"\nlast name: \n";

puts(Lastname);
cout<<"\nruns: \n";

cout<<Runsmade;

cout<<"\nnumber of fours:\n";

cout<<Number_of_fours;

cout<<"\nnumber of sixes:\n";

cout<<Number_of_sixes;

}
void read()
{

ifstream fp;

fp.open("batsmen.dat",ios::in|ios::binary);

batsmen b;

while(fp.read((char*)&b,sizeof(b)))

b.display_information();

fp.close();

void write()

ofstream fp;

fp.open("batsmen.dat",ios::app|ios::binary);

batsmen b;

b.enter_information();

fp.write((char*)&b,sizeof(b));

fp.close();

}
};

void main()

clrscr();

int ch;

char rep;

batsmen b;
do
{

cout<<"\nMAIN MENU\n";

cout<<"\n 1.to insert details \n";

cout<<"\n 2.to update runs made \n";

cout<<"\n 3.to display details \n";

cin>>ch;

switch(ch)

case 1: b.write();

break;

case 2: b.update_runsmade();

break;

case 3: b.read();

break;

default:cout<<"\nwrong choice!!!\n";

cout<<"\ndo you want to continue:\n";

cin>>rep;

}while((rep=='y')||(rep=='Y'));
}

OUTPUT
5.\\

#include<iostream.h>

#include<process.h>

#define size 10

class array

int arr[size];

int e;

public:

array()

e=0;

void enter();

void display();

void deletear();

};

void array::enter()

{
cout<<"Enter size (less than 10)= ";

cin>>size;

cout<<"Enter the sorted array(ascending)\n";

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

cin>>arr[i];

}
}
void array::display()

cout<<"The array is :\n";

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

cout<<arr[i]<<" ";

void array::deletear()

int flag=0,pos,i,index,temp;

int x;

cout<<"enter the element that you want to delete\n";

cin>>x;

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

if(arr[i]==x)

index=i;
flag=1;

pos=index+1;

cout<<"the element is: "<<x<<"\n";

cout<<" \nthe position is: "<<pos;

if(flag==0)
{
cout<<"the element does not exist\n";

for(int j=index;j<size-1;j++)

arr[j]=temp;

arr[j]=arr[j+1];

arr[j+1]=temp;

e++;

void main()

array a;

int choice;

char ch;

do

{ cout<<"MAIN MENU\n"

<<"1-ENTER\n"

<<"2-DISPLAY\n"
<<"3-DELETE\n"

<<"4-EXIT\n"

<<"\nenter your choice : ";

cin>>choice;

switch(choice)

case 1:a.enter();
break;
case 2:a.display();

break;

case 3:a.deletear();

break;

case 4: exit(0);

cout<<"\nDo you want to continue: ";

cin>>ch;

}while((ch=='y')||(ch=='Y'));

OUTPUT
6.\\

#include<iostream.h>

#include<process.h>

#define size 10

class array

int arr[size];

int e;

public:

array()

e=0;

void enter();

void display();

void deletear();

};

void array::enter()

{
cout<<"Please enter the sorted array(ascending)\n";

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

cin>>arr[i];

void array::display()
{
cout<<"The array is :\n";

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

cout<<arr[i]<<" ";

void array::deletear()

int flag=0,pos,i,index,temp;

int x;

cout<<"enter the element that you want to delete\n";

cin>>x;

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

if(arr[i]==x)

index=i;

flag=1;

pos=index+1;
cout<<"the element is: "<<x<<"\n";

cout<<" \nthe position is: "<<pos;

if(flag==0)

cout<<"the element does not exist\n";


}
for(int j=index;j<size-1;j++)

arr[j]=temp;

arr[j]=arr[j+1];

arr[j+1]=temp;

e++;

void main()

array a;

int choice;

char ch;

do

{ cout<<"MAIN MENU\n"

<<"1-ENTER\n"

<<"2-DISPLAY\n"

<<"3-DELETE\n"

<<"4-EXIT\n"
<<"\nenter your choice : ";

cin>>choice;

switch(choice)

case 1:a.enter();

break;

case 2:a.display();
break;
case 3:a.deletear();

break;

case 4: exit(0);

cout<<"\nDo you want to continue: ";

cin>>ch;

}while((ch=='y')||(ch=='Y'));

OUTPUT
7.\\

#include<iostream.h>

#include<conio.h>

class MERGE

int A[20],B[20],C[40],m,n,a,b,c;

public:

MERGE()

c=0;

void enter()

cout<<"Enter the size of array A and B\n";

cin>>m>>n;

for(a=0;a<m;a++)

cout<<"Enter the array A in ascending order\n";

cin>>A[a];
}

for(b=0;b<n;b++)

cout<<"Enter the array B in descending order\n";

cin>>B[b];

mergesort(A,B,C,m,n) ;

}
}
void mergesort(int A[],int B[],int C[],int m,int n)

int a,b,c;

for(a=0,b=n-1,c=0;(a<m)&&(b>=0);)

if(A[a]<=B[b])

C[c++]=A[a++];

else

C[c++]=B[b--];

if(a<m)

while(a<m)

C[c++]=A[a++];

else

{
while(b>=0)

C[c++]=B[b--];

void sortedarray()

cout<<"The sorted array is\n";


for(c=0;c<m+n;c++)
cout<<C[c]<<endl;

};

void main()

MERGE M;

char ch;

int choice;

do{

cout<<"\t\t Merge Sort Menu\n";

cout<<"\t 1. Enter the array\n";

cout<<"\t 2. Display the sorted array\n";

cout<<"\t 3. Exit\n";

cout<<"Enter your choice (1-4)....";

cin>>choice;

switch(choice)

case 1 : M.enter();

break;
case 2 :M.sortedarray();

break;

case 3 :break;

default : cout<<"Valid choices are 1...3 only\n";

cout<<"Do you want to continue\n";

cin>>ch;
} while ((ch=='y')||(ch=='Y'));
}

OUTPUT
8.\\

#include<iostream.h>

#include<conio.h>

#include<process.h>

class Array

int A[30],i;

public:

int n;

void enter();

void Arr();

void display();

void Bsorter();

};

void Array::Arr()

int pos;

cout<<"enter the position of element which is to be deleted\n";

cin>>pos;
for( i=pos;i<=n;i++)

A[i]=A[i+1];

n--;

void Array::enter()
{
cout<<"enter the elements of the array\n";

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

cin>>A[i];

void Array::display()

cout<<"The array is\n";

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

cout<<A[i]<<"\n";

void Array::Bsorter()

int i,j,c;

for(j=n-1;j>=1;j--)

for(i=1;i<=j;i++)

if(A[i]>A[i+1])

{c=A[i];
A[i]=A[i+1];

A[i+1]=c;

cout<<"Sorted Array\n";

}
void main()
{

int choice;

char ch;

Array a;

cout<<"enter the size of array\n";

cin>>a.n;

do

{cout<<"Main Menu\n";

cout<<"1-enter the array\n";

cout<<"2-sort the array\n";

cout<<"3-delete the element\n";

cout<<"4-display the element\n";

cout<<"5-exit\n";

cout<<"Enter your choice\n";

cin>>choice;

switch(choice)

case 1:a.enter();

break;
case 2:a.Bsorter();

break;

case 3:a.Arr();

break;

case 4:a.display();

break;

case 5:exit(0);
break;
default:cout<<"\nWrong choice\n";

cout<<"Try Again \n";

cout<<"\nDo you wanna continue\n";

cin>>ch;

}while((ch=='y')||(ch=='Y'));

getch();

}
9.\\

#include<iostream.h>

#include<process.h>

#include<fstream.h>

class bank

int bal,acc,with;

char dep[12],type[12];

public:

void show();

void deposit();

void display();

void withdraw();

void create();

bank()

acc=0;

bal=0;

}
};

void bank::deposit()

{bank b;

fstream f;

cout<<"enter the name\n";

cin>>dep;

cout<<"enter the acc no.\n";


cin>>acc;
cout<<"enter the type of account\n";

cin>>type;

cout<<"enter the balance\n";

cin>>bal;

f.write((char*)&b,sizeof(b));

void bank::show()

cout<<"name:\n"<<dep<<endl;

cout<<"acc. no.\n"<<acc<<endl;

cout<<"type:\n"<<type<<endl;

cout<<"balance:\n"<<bal<<endl;

fstream f;

bank b;

void bank::display()

f.open("bank.dat",ios::binary|ios::in|ios::out);

while(!f.eof())
{

f.read((char*)&b,sizeof(b));

b.show();

b.withdraw();

void bank::withdraw()
{
if(bal>1000)

cout<<"enter the amount to be withdraw\n";

cin>>with;

cout<<"the amount of withdrawal is\n";

cout<<with;

else

cout<<"the amount cannot be withdrawn\n";

void bank::create()

{fstream f;

bank b;

char rep;

f.open("bank.dat",ios::binary|ios::in);

do{

b.deposit();
f.write((char*)&b,sizeof(b));

cout<<"do you want to continue\n";

cin>>rep;

}while((rep=='y')||(rep=='Y'));

f.close();

void main()
{
int choice;

char ch;

do{

cout<<"1-to deposit\n";

cout<<"2-to show\n";

cout<<"3-to display withdrawed amount\n";

cout<<"enter the choice\n";

cin>>choice;

switch(choice)

case 1:b.deposit();

break;

case 2:b.show();

break;

case 3:b.display();

break;

cout<<"do you want to continue\n";

cin>>ch;
}while((ch=='y')||(ch=='Y'));

Das könnte Ihnen auch gefallen