Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 42

P1A.

txt
************************************************************************
#include<iostream.h>
#include<stdio.h>
#include<conio.h>
void bubsort(int a[10],int size)
{
int temp,i,j;
for(i=0;i<size;i++)
{
for(j=0;j<(size-1)-i;j++)
{
if(a[j]>a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
cout<<"Sorted array \n";
for(i=0;i<size;i++)
cout<<a[i]<<' ';
}
void ins(int a[10],int size,int n,int p)
{
int i;
for(i=size-1;i>=p-1;i--)
a[i+1]=a[i];
a[p-1]=n;
cout<<"New array \n";
for(i=0;i<=size;i++)
cout<<a[i]<<' ';
}
void binsearch(int a[10],int size,int n1)
{
int i,j,first=0,last=size-1,mid,found=0;
while((first<=last)&&found==0)
{
mid=(first+last)/2;
if(a[mid]==n1)
{
found=1;
break;
}
if(n1>a[mid])
first=mid+1;
else if(n1<a[mid])
last=mid-1;
}
if(found==0)
cout<<"Not found \n";
else
cout<<"Found at position "<<mid+1<<'\n';
}
void main()
{
int i,a[10],ch,size;
clrscr();

char ans='y';
cout<<"Enter size of array : ";
cin>>size;
for(i=0;i<size;i++)
{
cout<<"Enter element "<<i+1<<": ";
cin>>a[i];
}
do
{
cout<<"1.Bubble sort \n";
cout<<"2.Insertion \n";
cout<<"3.Binary search \n";
cout<<"Enter choice : ";
cin>>ch;
switch(ch)
{
case 1 : bubsort(a,size);
break;
case 2 : int n,p;
cout<<"Enter the no to insert : ";
cin>>n;
cout<<"Enter the position : ";
cin>>p;
ins(a,size,n,p);
break;
case 3 : int n1;
cout<<"Enter the no to search : ";
cin>>n1;
binsearch(a,size,n1);
break;
default : cout<<"wrong choice \n";
}
cout<<"Do you want to continue ? y/n ";
cin>>ans;
}while(ans=='y');
getch();
}
P1O.txt
************************************************************************
Enter size of array : 5
Enter element 1: 23
Enter element 2: 32
Enter element 3: 11
Enter element 4: 43
Enter element 5: 21
1.Bubble sort
2.Insertion
3.Binary search
Enter choice : 1
Sorted array
11 21 23 32 43 Do you want to continue ? y/n y
1.Bubble sort
2.Insertion
3.Binary search
Enter choice : 2
Enter the no to insert : 10
Enter the position : 2

New array
11 10 21 23 32 43 Do you want to continue ? y/n y
1.Bubble sort
2.Insertion
3.Binary search
Enter choice : 3
Enter the no to search : 21
Found at position 3
Do you want to continue ? y/n n
P2A.txt
************************************************************************
#include<iostream.h>
#include<stdio.h>
#include<conio.h>
void add(int a[10][10],int b[10][10],int size)
{
int i,j,res[10][10];
for(i=0;i<size;i++)
for(j=0;j<size;j++)
res[i][j]=a[i][j]+b[i][j];
cout<<"Added array \n";
for(i=0;i<size;i++)
for(j=0;j<size;j++)
cout<<res[i][j]<<' ';
}
void sub(int a[10][10],int b[10][10],int size)
{
int i,j,res[10][10];
for(i=0;i<size;i++)
for(j=0;j<size;j++)
res[i][j]=a[i][j]-b[i][j];
cout<<"Subtracted array \n";
for(i=0;i<size;i++)
for(j=0;j<size;j++)
cout<<res[i][j]<<' ';
}
void sum(int a[10][10],int size)
{
int res1[20],res2[20],i,j;
for(i=0;i<size;i++)
{
res1[i]=0;
for(j=0;j<size;j++)
{
res1[i]=a[i][j]+res1[i];
}
}
for(j=0;j<size;j++)
{
res2[j]=0;
for(i=0;i<size;i++)
{
res2[j]=a[i][j]+res2[j];
}
}
cout<<"Row sum stored in 1-D array : ";
for(i=0;i<size;i++)
cout<<res1[i]<<' ';

cout<<'\n';
cout<<"Col sum stored in 1-D array : ";
for(i=0;i<size;i++)
cout<<res2[i]<<' ';
}
void main()
{
clrscr();
int ch,a[10][10],b[10][10],r,c,size;char ans;
cout<<"Enter no of rows and columns : ";
cin>>size;
cout<<"Array 1 \n";
for(r=0;r<size;r++)
{
for(c=0;c<size;c++)
{
cout<<"Enter element : ";
cin>>a[r][c];
}
}
cout<<"Array 2 \n";
for(r=0;r<size;r++)
{
for(c=0;c<size;c++)
{
cout<<"Enter element : ";
cin>>b[r][c];
}
}
do
{
cout<<"1.Add \n";
cout<<"2.Subtract \n";
cout<<"3.Row and col sum \n";
cout<<"Enter choice : ";
cin>>ch;
switch(ch)
{
case 1 : add(a,b,size);
break;
case 2 : sub(a,b,size);
break;
case 3 : sum(a,size);
break;
default : cout<<"wrong choice \n";
}
cout<<"Do you want to continue y/n ? ";
cin>>ans;
}while(ans=='y');
getch();
}
P2O.txt
************************************************************************
Enter no of rows of rows and columns : 2
Array 1
Enter element : 10
Enter element : 20
Enter element : 30

Enter element : 40
Array 2
Enter element : 50
Enter element : 60
Enter element : 70
Enter element : 80
1.Add
2.Subtract
3.Row and col sum
Enter choice : 1
Added array
60 80 100 120 Do you want to continue y/n ? y
1.Add
2.Subtract
3.Row and col sum
Enter choice : 2
Subtracted array
-40 -40 -40 -40 Do you want to continue y/n ? y
1.Add
2.Subtract
3.Row and col sum
Enter choice : 3
Row sum stored in 1-D array : 30 70
Col sum stored in 1-D array : 40 60 Do you want to continue y/n ? n
P3A.txt
************************************************************************
#include<iostream.h>
#include<conio.h>
#include<math.h>
#include<string.h>
#include<stdio.h>
class student
{
int no;
char sname[20];
float m[5];
float tot;
float calc()
{
return tot/5;
}
public:
void take();
void show();
};
void student::take()
{
int i;
tot=0;
cout<<"Enter admission number\n";
cin>>no;
cout<<"Enter student name\n";
gets(sname);
cout<<"Enter marks of five subjects\n";
for(i=0;i<5;i++)
{

cout<<"\nEnter marks of "<<i+1<<" subject ";


cin>>m[i];
tot+=m[i];
}
}
void student::show()
{
cout<<endl<<endl;
cout<<"Admission number is "<<no;
cout<<"\nThe name is ";
puts(sname);
cout<<"\nThe marks of 5 subjects are\n";
for(int i=0;i<5;i++)
{cout<<"\nMarks of "<<i+1<<" subject are "<<m[i]<<endl;}
cout<<"\nThe total marks are "<<tot;
cout<<"\nThe average marks are "<<calc();
}
void main()
{
clrscr();
student s1;
s1.take();
s1.show();
getch();
}

P3O.txt
************************************************************************
Enter admission number
123
Enter student name
Antriksh
Enter marks of five subjects
Enter marks of 1 subject 100
Enter marks of 2 subject 97
Enter marks of 3 subject 97
Enter marks of 4 subject 95
Enter marks of 5 subject 80
Admission number is 123
The name is Antriksh
The marks of 5 subjects are
Marks of 1 subject are 100
Marks of 2 subject are 97
P4A.txt
************************************************************************

#include<iostream.h>
#include<conio.h>
#include<math.h>
#include<string.h>
#include<stdio.h>
class floppy
{
int fno;
int size;
char n[30];
public:
void getdata()
{
cout<<"\nEnter floppy number\n";
cin>>fno;
cout<<"\nEnter size of floppy\n";
cin>>size;
cout<<"\nEnter floppy name\n";
gets(n);
cout<<endl;
}
void show()
{
cout<<"\nThe floppy number is "<<fno;
cout<<"\nThe floppy size is "<<size;
cout<<"\nThe floppy name is ";
puts(n);
}
int retfno()
{
return fno;
}
int retsize()
{
return size;
}
int chkname(char sn[])
{
return strcmp(sn,n);
}
};
void searchno(floppy f[],int sfno,int s)
{
int found=0;
for(int i=0;i<s;i++)
{
if(f[i].retfno()==sfno)
{
f[i].show();
found=1;
break;
}
if(found==0)
cout<<"\nNo such floppy\n";

}
}
void count(floppy f[],char sn[],int s)
{
int ctr=0;
for(int i=0;i<s;i++)
{
if(f[i].chkname(sn)==0)
ctr++;
}
if(ctr==0)
cout<<"\nNo such floppy\n";
else
cout<<"\nNumber of floppies - "<<ctr<<endl;
}
void bsort(floppy f[],int s)
{
floppy t;
for(int i=0;i<s-1;i++)
{
for(int j=0;j<s-1-i;j++)
{
if(f[j].retsize()<f[j+1].retsize())
{
t=f[j];
f[j]=f[j+1];
f[j+1]=t;
}
}
}
for(int k=0;k<s;k++)
f[k].show();
}
void main()
{
clrscr();
floppy f1[10];
int size,i,ch,sfno;
char sn[20],ans='y';
cout<<"\nEnter number of floppies\n";
cin>>size;
for(i=0;i<size;i++)
f1[i].getdata();
do
{
cout<<"\nEnter 1 to search by floppy number";
cout<<"\nEnter 2 to count number of floppies of a given name";
cout<<"\nEnter 3 to sort array in descending order of size\n";
cin>>ch;
switch (ch)
{
case 1:cout<<"\nEnter floppy number of floppy to be searched\n";
cin>>sfno;
searchno(f1,sfno,size);
break;
case 2:cout<<"\nEnter name of floppy to be searched\n";
gets(sn);

count(f1,sn,size);
break;
case 3:bsort(f1,size);
break;
default:cout<<"\nWrong choice";
}
cout<<"Enter y to continue or n to discontinue\n";
cin>>ans;
}while(ans=='y');
getch();
}
P4O.txt
************************************************************************
Enter number of floppies
2
Enter floppy number
123
Enter size of floppy
1024
Enter floppy name
HP
Enter floppy number
234
Enter size of floppy
500
Enter floppy name
COMPACT
Enter 1 to search by floppy number
Enter 2 to count number of floppies of a given name
Enter 3 to sort array in descending order of size
1
Enter floppy number of floppy to be searched
123
The floppy
The floppy
The floppy
Enter y to
y

number is 123
size is 1024
name is HP
continue or n to discontinue

Enter 1 to search by floppy number


Enter 2 to count number of floppies of a given name
Enter 3 to sort array in descending order of size
2
Enter name of floppy to be searched
HP
Number of floppies = 1

Enter y to continue or n to discontinue


y
Enter 1 to search by floppy number
Enter 2 to count number of floppies of a given name
Enter 3 to sort array in descending order of size
3
The floppy number is 123
The floppy size is 1024
The floppy name is HP
The floppy
The floppy
The floppy
Enter y to

number is 234
size is 500
name is COMPACT
continue or n to discontinue

P5A.txt
************************************************************************
#include<iostream.h>
#include<conio.h>
#include<math.h>
#include<string.h>
#include<stdio.h>
class employee
{
int empno;
char n[30],dept[30];
float sal;
public:
void getdata()
{
cout<<"\nEnter
cin>>empno;
cout<<"\nEnter
gets(n);
cout<<"\nEnter
gets(dept);
cout<<"\nEnter
cin>>sal;
cout<<endl;
}

employee number\n";
name of employee\n";
employee department\n";
employee salary\n";

void show()
{
cout<<"\nEmployee number\n";
cout<<empno;
cout<<"\nName of employee\n";
puts(n);
cout<<"\nEmployee department\n";
puts(dept);
cout<<"\nEmployee salary\n";
cout<<sal;
cout<<endl;
}
int retempno()

{
return empno;
}
float retsal()
{
return sal;
}
int retna(char sn[])
{
return strcmp(n,sn);
}
int retdep(char sdep[])
{
return strcmp(n,sdep);
}
};
void search1(employee e[],int sempno,int s)
{
int found=0;
for(int i=0;i<s;i++)
{
if(e[i].retempno()==sempno)
{
e[i].show();
found=1;
break;
}
if(found==0)
cout<<"\nEmployee not found\n";
}
}
void search2(employee e[],char sn[],int s)
{
int found=0;
for(int i=0;i<s;i++)
{
if(e[i].retna(sn)==0)
{
e[i].show();
found=1;
break;
}
if(found==0)
cout<<"\nEmployee not found\n";
}
}
void count1(employee e[],int s)
{
int ctr=0;
for(int i=0;i<s;i++)
{
if(e[i].retsal()>50000)
ctr++;
}
if(ctr==0)
cout<<"\nNo employee has salary greater than 50000\n";

else
cout<<"\nNumber of employees = "<<ctr<<endl;
}
void count2(employee e[],char sdep[],int s)
{
int ctr=0;
for(int i=0;i<s;i++)
{
if(e[i].retdep(sdep)==0)
ctr++;
}
if(ctr==0)
cout<<"\nNo employee in given department\n";
else
cout<<"\nNumber of employees = "<<ctr<<endl;
}
void sort(employee e[],int s)
{
employee t;
for(int i=0;i<s-1;i++)
{
for(int j=0;j<s-1-i;j++)
{
if(e[j].retsal()>e[j+1].retsal())
{
t=e[j];
e[j]=e[j+1];
e[j+1]=t;
}
}
}
for(int k=0;k<s;k++)
e[k].show();
}
void main()
{
clrscr();
employee e[10];
int size,i,ch,sempno;
float sal1;
char sn[20],sdep[20],ans='y';
cout<<"\nEnter number of employees\n";
cin>>size;
for(i=0;i<size;i++)
e[i].getdata();
do
{
cout<<"\nEnter 1 to search by employee number";
cout<<"\nEnter 2 to search by employee name";
cout<<"\nEnter 3 to count number of employees earning greater than 50000
";
cout<<"\nEnter 4 to count number of employees in given department";
cout<<"\nEnter 5 to sort array in ascending order of salary\n";
cin>>ch;
switch (ch)
{
case 1:cout<<"\nEnter employee number of employee to be searched
\n";

cin>>sempno;
search1(e,sempno,size);
break;
case 2:cout<<"\nEnter name of employee to be searched\n";
gets(sn);
search2(e,sn,size);
break;
case 3:count1(e,size);
break;
case 4:cout<<"\nEnter department";
gets(sdep);
count2(e,sdep,size);
break;
case 5:sort(e,size);
break;
default:cout<<"\nWrong choice";
}
cout<<"Enter y to continue or n to discontinue\n";
cin>>ans;
}while(ans=='y');
getch();
}
P5O.txt
************************************************************************
Enter number of employees
2
Enter employee number
1
Enter name of employee
Ram
Enter employee department
Management
Enter employee salary
75000
Enter employee number
2
Enter name of employee
Rohan
Enter employee department
HR
Enter employee salary
25000
Enter
Enter
Enter
Enter
Enter

1
2
3
4
5

to
to
to
to
to

search by employee number


search by employee name
count number of employees earning greater than 50000
count number of employees in given department
sort array in ascending order of salary

1
Enter employee number of employee to be searched
1
Employee number
1
Name of employee
Ram
Employee department
Management
Employee salary
75000
Enter y to continue or n to discontinue
y
Enter
Enter
Enter
Enter
Enter
2

1
2
3
4
5

to
to
to
to
to

search by employee number


search by employee name
count number of employees earning greater than 50000
count number of employees in given department
sort array in ascending order of salary

Enter name of employee to be searched


Rohan
Employee number
2
Name of employee
Rohan
Employee department
HR
Employee salary
25000
Enter y to continue or n to discontinue
y
Enter
Enter
Enter
Enter
Enter
3

1
2
3
4
5

to
to
to
to
to

search by employee number


search by employee name
count number of employees earning greater than 50000
count number of employees in given department
sort array in ascending order of salary

Number of employees = 1
Enter y to continue or n to discontinue
y
Enter
Enter
Enter
Enter
Enter
4

1
2
3
4
5

to
to
to
to
to

search by employee number


search by employee name
count number of employees earning greater than 50000
count number of employees in given department
sort array in ascending order of salary

Enter department

Management
Number of employees = 1
Enter y to continue or n to discontinue
y
Enter
Enter
Enter
Enter
Enter
5

1
2
3
4
5

to
to
to
to
to

search by employee number


search by employee name
count number of employees earning greater than 50000
count number of employees in given department
sort array in ascending order of salary

Employee number
2
Name of employee
Rohan
Employee department
HR
Employee salary
25000
Employee number
1
Name of employee
Ram
Employee department
Management
Employee salary
75000
Enter y to continue or n to discontinue
n

P6A.txt
************************************************************************
#include<iostream.h>
#include<conio.h>
#include<math.h>
#include<string.h>
#include<stdio.h>
float total=0,totw=0;
class account
{
int ano;
char name[20];
float bal;
public:
void accept()
{
cout<<"\nEnter account number\n";
cin>>ano;
cout<<"Enter client's name\n";

gets(name);
cout<<"Enter balance\n";
cin>>bal;
}
void show()
{
cout<<"\nThe account number is "<<ano;
cout<<"\nThe client's name is ";
puts(name);
cout<<"The balance is "<<bal<<endl;
}
void trans(char t,float amt)
{
if(t=='d')
bal+=amt;
if(t=='w')
{
if(bal-amt>=1000)
{bal-=amt;
totw+=amt;}
else
cout<<"\nTransaction not possible\n";
}
}
int retano()
{return ano;
}
};
void main()
{
clrscr();
char t;
float amt;
account a[3];
for(int i=0;i<3;i++)
a[i].accept();
int macno;
cout<<"Enter account you want to carry out the transaction on\n";
cin>>macno;
for(i=0;i<3;i++)
{
if(a[i].retano()==macno)
{
cout<<"Enter d for making deposit or w for withdrawal\n"
;
cin>>t;
cout<<"Enter the amount\n";
cin>>amt;
a[i].trans(t,amt);
break;
}
}
for(int j=0;j<3;j++)
a[j].show();
getch();
}

P6O.txt
************************************************************************
Enter account number
123
Enter client's name
Ram
Enter balance
1500
Enter account number
234
Enter client's name
Shyam
Enter balance
10000
Enter
345
Enter
Aman
Enter
2000
Enter
234
Enter
w
Enter
8000

account number
client's name
balance
account you want to carry out the transaction on
d for making deposit or w for withdrawal
the amount

The account number is 123


The client's name is Ram
The balance is 1500
The account number is 234
The client's name is Shyam
The balance is 2000
The account number is 345
The client's name is Aman
The balance is 2000

P7A.txt
************************************************************************
#include<iostream.h>
#include<conio.h>
class complex
{

int r,i;
public: void readdata()
{
cout<<"Enter real part : ";
cin>>r;
cout<<endl;
cout<<"Enter imaginary part : ";
cin>>i;
cout<<endl;
}
void display()
{
cout<<"Real part : "<<r<<endl;
cout<<"Imaginary part : "<<i<<endl;
}
complex addcomplex(complex c2)
{
complex c3;
c3.r=r+c2.r;
c3.i=i+c2.i;
return c3;
}
complex subcomplex(complex c2)
{
complex c3;
c3.r=r-c2.r;
c3.i=i-c2.i;
return c3;
}
};
void main()
{
clrscr();
complex c1,c2,c3;
c1.readdata();
c2.readdata();
c3=c1.addcomplex(c2);
cout<<"Addition :-"<<endl;
c3.display();
cout<<endl<<endl;
cout<<"Subtraction :-"<<endl;
c3=c1.subcomplex(c2);
c3.display();
getch();
}
P7O.txt
************************************************************************
Enter real part : 10
Enter imaginary part : 5
Enter real part : 23
Enter imaginary part : -4
Addition :Real part : 33
Imaginary part : 1

Subtraction :Real part : -13


Imaginary part : 9

P8A.txt
************************************************************************
#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<stdio.h>
#include<math.h>
class circle
{
float r,a;
public:
circle(int r1)
{
r=r1;
ar=3.14*r*r;
}
circle(circle &c1);
void show()

{
cout<<"The radius is "<<r;
cout<<"\nThe area is "<<a;
cout<<endl;
}
};
circle::circle(circle &c1)
{
r=c1.r+1;;
a=3.14*r*r;
}
void main()
{
clrscr();
int r1;
cout<<"Enter radius\n";
cin>>r1;
circle c(r1);
circle c1(c);
c.show();
c1.show();
getch();
}
P8O.txt
************************************************************************
Enter radius
9
The radius is 9
The area is 254.339996
The radius is 10
The area is 314

P9A.txt
************************************************************************
#include<fstream.h>
#include<conio.h>

#include<stdio.h>
#include<string.h>
class Floppybox
{
int fid;
char name[20];
int size;
public:
void getd()
{
cout<<"Enter floppy id : ";
cin>>fid;
cout<<"Enter name of floppy : ";
gets(name);
cout<<"Enter size of floppy : ";
cin>>size;
}
void show()
{
cout<<"Details of floppy \n "<<"Id : "<<fid<<'\n';
cout<<"Name : "<<name<<'\n'<<"Size : "<<size<<'\n';
}
int retid()
{
return fid;
}
char* retname()
{
return name;
}
};
char ans;
Floppybox s1,s2;
fstream f1,f2;
void create()
{
f1.open("floppy.dat",ios::out|ios::binary);
do
{
s1.getd();
f1.write((char*)&s1,sizeof(s1));
cout<<"Want to write more in the file ? y/n ";
cin>>ans;
}while(ans=='y');
f1.close();
}
void read()
{
f1.open("floppy.dat",ios::in|ios::binary);
while(f1.read((char*)&s1,sizeof(s1)))
{
s1.show();
}
f1.close();
}
int count()
{
int ctr1=0;
f1.open("floppy.dat",ios::in|ios::binary);
while(f1.read((char*)&s1,sizeof(s1)))

{
++ctr1;
}
cout<<"Number of records are : ";
f1.close();
return ctr1;
}
void search()
{
int ch1;
f1.open("floppy.dat",ios::in|ios::binary);
cout<<"1.Search on floppy id \n ";
cout<<"2.Search on floppy name \n ";
cout<<"Enter choice : ";
cin>>ch1;
if(ch1==1)
{
int f;
cout<<"Enter id to be searched : ";
cin>>f;
while(f1.read((char*)&s1,sizeof(s1)))
{
if(s1.retid()==f)
{
s1.show();
break;
}}}
if(ch1==2)
{
char nm[20];
cout<<"Enter name to be searched : ";
gets(nm);
while(f1.read((char*)&s1,sizeof(s1)))
{
if(strcmp(nm,s1.retname())==0)
{
s1.show();
break;
}}}
f1.close();
}
void main()
{
clrscr();
int ch;
do
{
cout<<"1.Create file \n";
cout<<"2.Read file \n";
cout<<"3.Search on id or name \n";
cout<<"4.Count records \n";
cout<<"Enter choice : ";
cin>>ch;
switch(ch)
{
case 1 : create();
break;
case 2 : read();
break;
case 3 : search();

break;
case 4 : int q=count();
cout<<q<<'\n';
break;
default : cout<<"Wrong choice ";
}
cout<<"Do you want to continue y/n ";
cin>>ans;
}while(ans=='y');
getch();
}

P9O.txt
************************************************************************
1.Create file
2.Read file
3.Search on id or name
4.Count records
Enter choice : 1
Enter floppy id : 123
Enter name of floppy : A
Enter size of floppy : 20
Want to write more in the file ? y/n y
Enter floppy id : 345
Enter name of floppy : B
Enter size of floppy : 30
Want to write more in the file ? y/n n
Do you want to continue y/n y
1.Create file
2.Read file
3.Search on id or name
4.Count records
Enter choice : 2
Details of floppy
Id : 123
Name : A
Size : 20
Details of floppy
Id : 345
Name : B
Size : 30
Do you want to continue y/n y
1.Create file
2.Read file
3.Search on id or name
4.Count records
Enter choice : 3
1.Search on floppy id
2.Search on floppy name
Enter choice : 1
Enter id to be searched : 123
Details of floppy
Id : 123
Name : A
Size : 20
Do you want to continue y/n y
1.Create file

2.Read file
3.Search on id or name
4.Count records
Enter choice : 3
1.Search on floppy id
2.Search on floppy name
Enter choice : 2
Enter name to be searched : B
Details of floppy
Id : 345
Name : B
Size : 30
Do you want to continue y/n y
1.Create file
2.Read file
3.Search on id or name
4.Count records
Enter choice : 4
Number of records are : 2
Do you want to continue y/n n
P10A.txt
************************************************************************
#include<fstream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
#include<ctype.h>
void create()
{
ofstream fout("Lines.txt");
char str[80],ans='y';
while(ans=='y')
{
cout<<"Enter a line : ";
gets(str);
fout<<str<<'\n';
cout<<"Want to write more y/n ? ";
cin>>ans;
}
fout.close();
}
void countthe()
{
int ctr=0;
ifstream fin("Lines.txt");
char wd[80];
if(!fin)
{
cout<<"\n Cannot open ";
}
while(fin>>wd)
{
if(strcmpi(wd,"the")==0)
ctr++;
}
cout<<"No. of the --> "<<ctr;
fin.close();
}

void copy()
{
ofstream fout("new.txt");
ifstream fin("Lines.txt");
char s[80];
if(!fin)
cout<<"\n Cannot open ";
while(fin>>s)
{
if(s[0]=='A'||s[0]=='a')
fout<<s<<" ";
}
fout.close();
fin.close();
cout<<"\n Changed file \n";
fin.open("new.txt");
while(fin>>s)
{
cout<<s<<" ";
}
fin.close();
}
void cnt()
{
ifstream fin("Lines.txt");
int a=0,d=0,s=0;
char ch;
while(fin.get(ch))
{
if(isalpha(ch))
a++;
else if(isdigit(ch))
d++;
else
s++;
}
cout<<"\n No. of alphabets are "<<a;
cout<<"\n No. of digits are "<<d;
cout<<"\n No. of special char are "<<s;
fin.close();
}
void wdsize()
{
ifstream fin("Lines.txt");
int cnt=0,total=0;
char w[80];
if(!fin)
cout<<"\n Cannot Open ";
while(fin>>w)
{
cnt++;total+=strlen(w);
}
cout<<"\n No. of words : "<<cnt;
cout<<"\n Avg word size : "<<float(total/cnt);
fin.close();
}
void size()
{
ifstream fin("Lines.txt");
int counter=0;

char ch;
while(fin.get(ch))
{ counter++;
}
cout<<"\n Size : "<<counter<<'\n';
fin.close();
}
void reverse()
{
ofstream fout("rev.txt");
ifstream fin("Lines.txt");
char s1[80];
if(!fin)
cout<<"\n Cannot Open ";
while(fin>>s1)
{
strrev(s1);
fout<<s1<<" ";
}
fout.close();
fin.close();
fin.open("rev.txt");
while(fin>>s1)
{
cout<<s1<<" ";
}
fin.close();
}
void main()
{
clrscr();
int ch;char answer='y';
do
{
cout<<"1.Create \n";
cout<<"2.Count the \n";
cout<<"3.Copy words starting with A to new file \n";
cout<<"4.Count no of alpha,digits and spec char \n";
cout<<"5.Count no of words and avg word size \n";
cout<<"6.Find size \n";
cout<<"7.Reverse each word & store in new file \n";
cout<<"enter choice : ";
cin>>ch;
switch(ch)
{
case 1 : create();break;
case 2 : countthe();break;
case 3 : copy();break;
case 4 : cnt();break;
case 5 : wdsize();break;
case 6 : size();break;
case 7 : reverse();break;
default : cout<<"wrong choice ";
}
cout<<"Do you want to continue y/n ? ";
cin>>answer;
}while(answer=='y');
getch();
}

P10O.txt
************************************************************************
1.Create
2.Count the
3.Copy words starting with A to new file
4.Count no of alpha,digits and spec char
5.Count no of words and avg word size
6.Find size
7.Reverse each word & store in new file
enter choice : 1
Enter a line : The 9th alphabet is I
Want to write more y/n ? n
Do you want to continue y/n ? y
1.Create
2.Count the
3.Copy words starting with A to new file
4.Count no of alpha,digits and spec char
5.Count no of words and avg word size
6.Find size
7.Reverse each word & store in new file
enter choice : 2
No. of the --> 1Do you want to continue y/n ? y
1.Create
2.Count the
3.Copy words starting with A to new file
4.Count no of alpha,digits and spec char
5.Count no of words and avg word size
6.Find size
7.Reverse each word & store in new file
enter choice : 3
Changed file
alphabet Do you want to continue y/n ? y
1.Create
2.Count the
3.Copy words starting with A to new file
4.Count no of alpha,digits and spec char
5.Count no of words and avg word size
6.Find size
7.Reverse each word & store in new file
enter choice : 4
No. of alphabets are 16
No. of digits are 1
No. of special char are 5Do you want to continue y/n ? y
1.Create
2.Count the
3.Copy words starting with A to new file
4.Count no of alpha,digits and spec char
5.Count no of words and avg word size
6.Find size
7.Reverse each word & store in new file
enter choice : 5
No. of words : 5
Avg word size : 3Do you want to continue y/n ? y
1.Create
2.Count the
3.Copy words starting with A to new file

4.Count no of alpha,digits and spec char


5.Count no of words and avg word size
6.Find size
7.Reverse each word & store in new file
enter choice : 6
Size : 22
Do you want to continue y/n ? y
1.Create
2.Count the
3.Copy words starting with A to new file
4.Count no of alpha,digits and spec char
5.Count no of words and avg word size
6.Find size
7.Reverse each word & store in new file
enter choice : 7
ehT ht9 tebahpla si I Do you want to continue y/n ? n

P11a.txt
************************************************************************
#include<fstream.h>
#include<stdio.h>
#include<conio.h>
#include<ctype.h>
void write_file()
{
ofstream fout("Lines.txt");
char str[80],ans='y';
while(ans=='y')
{
cout<<"Enter text : ";
gets(str);
fout<<str<<'\n';
cout<<"Want to write more in the file y/n ? ";
cin>>ans;
}
fout.close();
}
void change()
{
ifstream fin("Lines.txt");
ofstream fout("change.txt");
char ch;
while(fin.get(ch))
{
if(isalpha(ch))
{ if(ch=='z')
ch='a';
else if(ch=='Z')
ch='A';
else
ch++;
}
else if(isdigit(ch))
{ if(ch=='9')
ch='0';
else
ch++;

}
else
ch='*';
fout<<ch;
}
fin.close();
fout.close();
fin.open("change.txt");
cout<<"Changed result \n";
while(fin.get(ch))
{
cout<<ch;
}
fin.close();
}
void main()
{ clrscr();
write_file();
change();
getch();
}

P11O.txt
************************************************************************
Enter text : this is a zoo
Want to write more in the file y/n ? n
Changed result
uijt*jt*b*app*
P12A.txt
************************************************************************
#include<fstream.h>
#include<stdio.h>
#include<string.h>
#include<conio.h>
class book
{ int bid;
char name[20];
int bno;
public:
void getd()
{ cout<<"enter book id:"; cin>>bid;
cout<<"enter book name:"; gets(name);
cout<<"enter no. of pages:";cin>>bno;
}
void showd()
{ cout<<"bookid:"<<bid;
cout<<"bookname:"<<name;
cout<<"no of pages "<<bno<<endl;
}
int retbno()
{ return bno;}
};
book b1,b2;
fstream f1,f2;
void create()

{char ans='y';
f1.open("file.dat",ios::out|ios::binary);
do
{ b1.getd();
f1.write((char*)&b1,sizeof(b1));
cout<<"want to cont y/n";
cin>>ans;
}while(ans=='y');
f1.close();
}
void read()
{ f1.open("file.dat",ios::in|ios::binary);
while(f1.read((char*)&b1,sizeof(b1)))
{ b1.showd();}
f1.close();
}
void nthedition()
{ int n;
cout<<"Which record is to be edited: ";
cin>>n;
f1.open("book1.dat",ios::ate|ios::out|ios::binary);
f1.seekp((n-1)*sizeof(b1),ios::beg);
cout<<"Enter new details: \n";
b1.getd();
f1.write((char*)&b1,sizeof(b1));
f1.close();
read();
}
void nthinsertion()
{ int n,r=1;
cout<<"Enter position to insert:";
cin>>n;
f1.open("file.dat",ios::in|ios::binary);
f2.open("temp.dat",ios::out|ios::binary);
while(f1.read((char*)&b1,sizeof(b1)))
{ if(r!=n)
f2.write((char*)&b1,sizeof(b1));
else
{ cout<<"Enter record: \n";
b2.getd();
f2.write((char*)&b2,sizeof(b2));
f2.write((char*)&b1,sizeof(b1));
}
r++;
}f1.close();f2.close();
remove("file.dat");
rename("temp.dat","file.dat");
read();
}
void userinsert()
{ int n;
cout<<"Enter book no after which you want to insert:";
cin>>n;
f1.open("file.dat",ios::in|ios::binary);
f2.open("temp.dat",ios::out|ios::binary);
while(f1.read((char*)&b1,sizeof(b1)))
{ if(b1.retbno()!=n)
f2.write((char*)&b1,sizeof(b1));
else
{ cout<<"Enter record: \n";

b2.getd();
f2.write((char*)&b1,sizeof(b1));
f2.write((char*)&b2,sizeof(b2));
}
}f1.close();f2.close();
remove("file.dat");
rename("temp.dat","file.dat");
read();
}
void main()
{ clrscr();
int ch;
char ans='y';
do
{ cout<<"1.Create \n";
cout<<"2.Read\n";
cout<<"3.Edit nth record\n";
cout<<"4.Insert at nth position\n";
cout<<"5.Insert after user given bno\n";
cout<<"Enter choice : ";
cin>>ch;
switch(ch)
{ case 1:create();
break;
case 2:read();
break;
case 3:edit();
break;
case 4:insertn();
break;
case 5:insert();
break;
}
cout<<"Do you want to continue y/n";
cin>>ans;
}while(ans=='y');getch();
}

P12O.txt
************************************************************************
1.Create
2.Read
3.Edit nth record
4.Insert at nth position
5:insert after user given bno
Enter choice : 1
enter book id:101

enter book name: CharlieAndTheChocolateFactory


enter no. of pages:294
want to cont y/ny
enter book id:102
enter book name:HardyBoys
enter no. of pages:148
want to cont y/nn
Do you want to continue y/ny
Enter choice : 2
bookid:101
bookname:CharlieAndTheChocolateFactory
no of pages 294
bookid:102
bookname:HardyBoys
no of pages 148
Do you want to continue y/ny
Enter choice : 3
Which record is to be edited:2
Enter new details
enter book id:103
enter book name:SteveJobs
enter no. of pages:321
bookid:101
bookname:CharlieAndTheChocolateFactory
no of pages 294
bookid:103
bookname:SteveJobs
no of pages 321
Do you want to continue y/ny
Enter choice : 4
Enter position at to insert:2
Enter record:
enter book id:104
enter book name:GreatExpectations
enter no. of pages:90
bookid:101
bookname:CharlieAndTheChocolateFactory
no of pages 294
bookid:990
bookname:SteveJobs
no of pages 321
bookid:104
bookname:GreatExpectations
no of pages 90
Do you want to continue y/ny
Enter choice : 5
Enter book id after which you want to insert: 101
Enter record:
enter book id:105
enter book name:InvisibleMan
enter no. of pages:127
bookid:101
bookname:CharlieAndTheChocolateFactory
no of pages 294
bookid:105
bookname:InvisibleMan
no of pages 120
bookid:104
bookname:SteveJobs
no of pages 321

bookid:550
bookname:GreatExpectations
no of pages 90
Do you want to continue y/nn

P13A.txt
************************************************************************
#include<fstream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
class employee
{ int eno;
char name[20];
double sal;
public:
void getd()
{ cout<<"enter employee no.:";cin>>eno;
cout<<"enter emp name:";gets(name);
cout<<"enter emp salary:";cin>>sal;
}
void showd()
{ cout<<"emp no:"<<eno<<"\nemp name:"<<name;
cout<<"emp salary:"<<sal<<'\n';
}
};
fstream f1,f2;
employee e1,e2;
void create()
{ char ans='y';f1.open("first.dat",ios::out|ios::binary);
do
{ e1.getd();
f1.write((char*)&e1,sizeof(e1));
cout<<"Want to write more? y/n";
cin>>ans;
}while(ans=='y');f1.close();
}
void read()
{ f2.open("first.dat",ios::in|ios::binary);
while(f2.read((char*)&e2,sizeof(e2)))
e2.showd();
f2.close();
}
int count()
{ f1.open("first.dat",ios::in|ios::binary);
f1.seekg(0,ios::end);
a1=f1.tellg();
a2=sizeof(e1);
a3=a1/a2;
return a3;
f1.close();
}
void nthdeletion()
{ f1.open("first.dat",ios::in|ios::binary);
f2.open("second.dat",ios::out|ios::binary);

int r=1,n;
cout<<"Enter record to delete:";
cin>>n;f1.seekg(0);
while(f1.read((char*)&e1,sizeof(e1)))
{ if(r!=n)
f2.write((char*)&e1,sizeof(e1));
r++;
}
f1.close();
f2.close();
remove("first.dat");
rename("second.dat","first.dat");
cout<<"Record no. "<<n<<" deleted \n";
}
void dellast()
{ f1.open("first.dat",ios::in|ios::binary);
f2.open("second.dat",ios::out|ios::binary);
f1.seekg(0,ios::end);int Ip=f1.tellg();int s=sizeof(e1);int Ir=Ip/s;int r=1;
cout<<"\nNo of records are : "<<Ir<<endl;f1.seekg(0);
while(f1.read((char*)&e1,sizeof(e1)))
{ if(r!=Ir)
f2.write((char*)&e1,sizeof(e1));r++;
}
f1.close();
f2.close();
remove("first.dat");
rename("second.dat","first.dat");
cout<<"last record deleted ";
}
void main()
{ clrscr();
int ch;
char ans1;
do
{cout<<"1.Create\n";
cout<<"2.Read\n";
cout<<"3.Count no of records\n";
cout<<"4.Delete nth record\n";
cout<<"5.Delete last record\n";
cout<<"Enter choice : ";
cin>>ch;
switch(ch)
{ case 1:create();
break;
case 2:read();
break;
case 3:int c=count();
cout<<"no. of records are "<<c<<'\n';
break;
case 4:nthdeletion();
break;
case 5:dellast();
break;
}cout<<"Do you want to cont y/n";
cin>>ans1;
}while(ans1=='y');
getch();
}

P13O.txt
************************************************************************
1.Create
2.Read
3.Count no of records
4.Delete nth record
5.Delete last record
Enter choice : 1
enter employee no.:123
enter emp name: Mukesh
enter emp salary:5000
Want to write more? y/ny
enter employee no.:456
enter emp name: rajesh
enter emp salary:10000
Want to write more? y/nn
Do you want to cont y/ny
Enter choice : 2
emp no:123
emp name:Mukesh
emp salary:5000
emp no:456
emp name:rajesh
emp salary:10000
Do you want to cont y/ny
Enter choice : 3
no. of records are 3
Do you want to cont y/ny
Enter choice : 4
Enter record to delete:2
Record no. 2 deleted
Do you want to cont y/ny
Enter choice : 5
No of records are : 1
last record deleted Do you want to cont y/nn

P14A.txt
************************************************************************
#include<iostream.h>
#include<conio.h>
int front=-1,rear=-1;
const int max=10;
int queue[max];
void insert(int n)
{ if(rear==max-1)
cout<<"queue overflow \n";
if(rear==-1 && front==-1)
{ rear++;
front++;
queue[rear]=n;
}
else
{ rear++;
queue[rear]=n;
}

}
void deletion()
{ if(front==-1 && rear==-1)
cout<<"queue underflow \n";
else if(rear==front)
{ cout<<queue[front]<<" getting deleted "<<endl;
rear=-1;
front=-1;
}
else
{ cout<<queue[front]<<" getting deleted "<<endl;
front++;
}
}
void traverse()
{ if(front==-1 && rear==-1)
cout<<"queue underflow \n";
else
{ cout<<"queue : ";
for(int i=front;i<=rear;i++)
cout<<q[i]<<' ';
}
}
void main()
{ int ch,num;
char ans1='y',ans='y';
do
{ cout<<"1.Insert \n";
cout<<"2.Delete \n";
cout<<"3.Traverse \n";
cout<<"Enter choice : ";
cin>>ch;
switch(ch)
{ case 1: do
{ cout<<"enter element:";
cin>>num;
insert(num);
cout<<"Want to insert more?y/n";
cin>>ans1;
}while(ans1=='y');
break;
case 2: deletion();
break;
case 3: traverse();
break;
}cout<<"Do you want to continue y/n";
cin>>ans;
}while(ans=='y');
}

P14O.txt
************************************************************************
1.Insert
2.Delete
3.Traverse
Enter choice : 1
enter element:2
Want to insert more?y/ny

enter element:8
Want to insert more?y/ny
enter element:6
Want to insert more?y/nn
Do you want to continue y/ny
Enter choice : 2
2 getting deleted
Do you want to continue y/ny
8 6
Do you want to continue y/nn

P15A.txt
************************************************************************
#include<iostream.h>
#include<conio.h>
const int max=10;
int q[max],front=-1,rear=-1;
void insert(int num)
{ if(front==(rear+1)%max)
{ cout<<"Circular queue overflow \n";
}
else if(front==-1 && rear==-1)
{ q[++rear]=num;
front=rear;
}
else
{ rear=(rear+1)%max;
q[rear]=num;
}
}
void deletion()
{ if(front==-1 && rear==-1)
cout<<"queue underflow \n";
else if(front==rear)
{ cout<<"deleting "<<q[front]<<'\n';
front=-1;
rear=-1;
}
else
{ cout<<"deleting "<<q[front]<<'\n';
front=(front+1)%max;
}
}
void show()
{ int i;
if(front==-1 && rear==-1)
cout<<"queue underflow \n";
else if(front<=rear)
{ for(i=front;i<=rear;i++)
cout<<q[i]<<' ';
}
else
{ for(i=front;i<max;i++)
cout<<q[i]<<' ';
for(i=0;i<=rear;i++)
cout<<q[i]<<' ';
}
}

void main()
{ int ch,n;
char ans1='y',ans='y';
while(ans=='y')
{cout<<"1.Insert\n";
cout<<"2.Delete\n";
cout<<"3.Show\n";
cout<<"Enter choice : ";
cin>>ch;
switch(ch)
{case 1: do{
cout<<"Enter element:";
cin>>n;
insert(n);
cout<<"want to enter more y/n";
cin>>ans1;
}while(ans1=='y');
break;
case 2: deletion();
break;
case 3: show();
break;
}
cout<<"Do you want to continue y/n";
cin>>ans;
} }
P15O.txt
************************************************************************
1.Insert
2.Delete
3.Show
Enter choice : 1
Enter element:1
want to enter more y/ny
Enter element:20
want to enter more y/ny
Enter element:3
want to enter more y/ny
Enter element:40
want to enter more y/ny
Enter element:5
want to enter more y/nn
Do you want to continue y/ny
1.Insert
2.Delete
3.Show
Enter choice : 2
deleting 1
Do you want to continue y/ny
1.Insert
2.Delete
3.Show
Enter choice : 3
20 3 40 5Do you want to continue y/nn

P16A.txt
************************************************************************
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
class employee
{ int empno;
char name[20];
float sal;
public:
empoyee *next;
void getd()
{ cout<<"Enter employee no:";cin>>empno;
cout<<"Enter name of employee:";gets(name);
cout<<"Enter salary:";cin>>sal;
next=NULL;
}
void showd()
{ cout<<"empno:"<<empno<<endl<<"name:"<<name<<'\n';
cout<<"salary:"<<sal<<endl;
}
};
employee *newptr,*front=NULL,*rear=NULL,*ptr;
void insert()
{ newptr=new employee;
if(!newptr)
cout<<"memory allocation error \n";
newptr->getd();
if(front==NULL)
{ front=newptr;
rear=newptr;
}
else
{rear->next=newptr;
rear=newptr;
}
}
void deletion()
{ if(front==NULL)
cout<<"queue underflow \n";
else if(front==rear)
{ ptr=front;
front=NULL;
rear=NULL;
}
else
{ ptr=front;
front=front->next;
}
cout<<"deleting.. \n";
ptr->showd();
delete ptr;
}
void traverse()
{ ptr=front;
if(front==NULL)

cout<<"queue underflow\n";
while(ptr!=NULL)
{ ptr->showd();
ptr=ptr->next;
}
}
void main()
{ int ch;
char ans1='y',ans='y';
do
{ cout<<"1.Insert \n";
cout<<"2.Delete \n";
cout<<"3.Traverse \n";
cout<<"Enter choice : ";
cin>>ch;
switch(ch)
{ case 1: do
{ insert();
cout<<"Want to add more ? y/n";
cin>>ans1;
}while(ans1=='y');
break;
case 2: deletion();
break;
case 3: traverse();
break;
}cout<<"Do you want to continue y/n";
cin>>ans;
}while(ans=='y');
}

P16O.txt
************************************************************************
1.Insert
2.Delete
3.Transverse
Enter choice : 1
Enter employee no:123
Enter name of employee:Alankar
Enter salary:10000
Want to add more ? y/ny
Enter employee no:456
Enter name of employee:Nitin
Enter salary:15000
Want to add more ? y/nn
Do you want to continue y/ny
1.Insert
2.Delete
3.Transverse
Enter choice : 2
deleting..
empno:123
name:Alankar
salary:10000
Do you want to continue y/ny
1.Insert
2.Delete

3.Transverse
Enter choice : 3
empno:456
name:Nitin
salary:15000
Do you want to continue y/nn

P8A.txt
************************************************************************
#include<iostream.h>
#include<conio.h>
#include<process.h>
#include<stdio.h>
struct employee
{ int eno; char name[15];
float sal; employee *link;
};
employee *top=NULL;
void push()
{ employee *newptr=new employee;
if(!newptr)
cout<<"node not created\n";
cout<<"Enter employee no.:";cin>>newptr->eno;
cout<<"Enter name:";gets(newptr->name);
cout<<"Enter salary:";cin>>newptr->sal;cout<<endl;
newptr->link=NULL;
if(top==NULL)
top=newptr;
else
{ newptr->link=top;
top=newptr;
}
}
void pop()
{ if(top==NULL)
cout<<"stack underflow\n";
employee *ptr; ptr=top;
top=top->link;
cout<<"deleted "<<endl<<"eno:"<<ptr->eno<<"name:";
cout<<ptr->name;cout<<"salary:"<<ptr->sal<<endl;
delete ptr;
}
void traverse()
{ employee *ptr; ptr=top;
if(top==NULL)
cout<<"stack underflow\n";
while(ptr!=NULL)
{ cout<<"eno:"<<ptr->eno<<"name:"<<ptr->nm;
cout<<"salary:"<<ptr->sal<<endl;
ptr=ptr->link;
}
}
void main()
{ clrscr();
int ch;char ans='y',ans1='y';
do

{ cout<<"1.Push\n";
cout<<"2.Pop\n";
cout<<"3.Traverse(Access&Manipulation)\n";
cout<<"Enter choice : ";
cin>>ch;
switch(ch)
{ case 1: do
{ push();
cout<<"Want to add more nodes y/n"; cin>>ans;
}while(ans=='y');
break;
case 2: pop();
break;
case 3: traverse();
break;
}cout<<"Do you want to continue y/n";
cin>>ans1;
}while(ans1=='y');getch();
}

P8O.txt
************************************************************************
1.Push
2.Pop
3.Traverse(Access&Manipulation)
Enter choice : 1
Enter employee no.:1
Enter name:ABC
Enter salary:100
Want to add more nodes y/ny
Enter employee no.:2
Enter name:XYZ
Enter salary:200
Want to add more nodes y/nn
Do you want to continue y/ny
Enter choice : 2
deleted
eno:2name:XYZsalary:200
Do you want to continue y/ny
Enter choice : 3
eno:1name:ABCsalary:100
Do you want to continue y/nn

You might also like