Professional Documents
Culture Documents
Program based on
Constructor & Destructor ->
#include<iostream.h>
#include<stdio.>
class abc
{
int a,b;
float c;
public:
abc();
abc(int,char);
abc(abc&);
~abc();
void print();
}
abc::abc()
{
a=17;
b=y;
c=10.123;
}
abc::abc(int x,char y)
{
a=x;
b=y;
c=27.17;
}
abc::abc(abc&x)
{
a=x.a;
b=x.b;
}
~abc::abc()
{
cout<<Object Deallocated<<endl;
}
void abc::print()
{
cout<<a=<<a;
cout<<b=<<b;
cout<<c=<<c<<endl;
}
void main()
{
6
clrscr();
abc obj1;
abc obj2(25,g);
abc obj3(obj1);
obj1.print();
obj2.print();
obj3.print();
getch();
}
for(i=0;i<x;i++)
{
for(j=0;j<y;j++)
{
sum=a[i][j]+b[i][j];
}
}cout<<sum;
}
void main()
{
clrscr();
matrix m;
m.getvalues();
m.displaysum();
getch();
}
10
11
getch();
}
12
s=s+a*(pow(2,i));
i=i+1;
b=b/10;
}
Cout<<Answer:<<s<<endl;
}
break;
Case 2: { cout<<Enter the decimal<<endl;
cin>>d;
while(d>0)
{
a=d%2;
a=a*pow(10,i);
s=s+a;
i=i+1;
d=d/2;
}
cout<<Answer:<<s<<endl;
}
break;
Default: cout<<Not a valid choice<<endl;
}
}
Void bofunc()
{
int oc,p,r,ch,n,a,i=0,x=0d=0,j,o;
long int b,s=0,sum=0
cout<<Enter choice<<Endl;
cout<<1:Binary to Octal<<Endl;
cout<<2:Octal to Binary<<endl;
cin>>ch;
Switch(ch)
{
Case 1: { cout<<Enter the Binary digit<<endl;
Cin>>b;
While(b>0)
{
a=b%1000;
j=0;
d=0;
while(a>0)
{
n=(a%10);
d=d+(n*pow(2,i));
j=j+1;
a=a/10;
}
x=x+(d*pow(10,i);
i=i+1;
14
b=b/1000;
}
cout<<Answer:<<x;
}
break;
Case 2: { cout<<Enter the Octal<<endl;
cin>>oc;
i=0;
j=0;
sum=0;
s=0;
while(oc>0)
{
p=oc%1000;
while(p>0)
{
p=p%2;
s=s+r*pow(10,j);
j++;
p=p/2;
}
sum=sum+(s*pow(1000,i));
i++;
oc=oc/10;
i=0;
}
cout<<Binary<<sum<<endl;
}
break;
Default: cout<<Invalid choice<<endl;
}
}
15
16
}
void array::traversal()
{
clrscr();
int I;
for(i=0;i<n;i++)
{
cout<<setw(5)<<ar[i];
}
}
void array::insertion(int num,int pos)
{
if(n==10)
{
cout<<\nOverflow!!!\n;
getch();
}
else
{
int I;
for(i=n-1;i>=pos;i--)
{
ar[i+1]=ar[i];
}
ar[pos]=num;
n++;
}
}
void array::deletion(int pos)
{
int x;
if(n==0)
{
cout<<\nunderflow!!!\n;
getch();
}
else
{
int x;
for(x=pos;x<n;x++)
{
ar[x]=ar[x+1];
}
n--;
}
}
void array::bsort()
{
int x,y,temp;
17
for(x=0;x<n-1;x++)
{
for(y=0;y<((n-1)-x);y++)
{
if(ar[y]>ar[y+1])
{
temp=ar[y];
ar[y]=ar[y+1];
ar[y+1]=temp;
}
}
}
}
void array::bsearch()
{
bsort();
int num,pos;
cout<<\nEnter the number to be searched->\n;
cin>>num;
int beg,end,mid;
beg=0; end=n-1;
mid=(beg+end)/2;
while(num!=ar[mid]&&beg<=end)
{
if(num>ar[mid])
{
beg=mid+1;
}
else
{
end=mid-1;
}
mid=(beg+end)/2;
}
if(beg>end)
{
pos=-1;
cout<<\nNumber not found!!\n;
getch();
}
else
{
pos=mid;
cout<<endl<<wait while the list is being automatically
sorted!!\n;
delay(2000);
cout<<Number found at position ->pos+1;
}
getch();
18
}
void array::lsearch()
{
int i,pos,num;
int flag=0;
cout<<\nEnter the number to be searched ->;
cin>>num;
for(i=0;i<n;i++)
{
if(ar[i]==num)
{
flag=1;
break;
}
else
{
flag=0;
}
}
if(flag==1)
{
cout<<Element is at position:i+1;
}
else
{
cout<<Element not found;
}
getch();
}
void array::merging(int an)
{
bsort();
int bn,C[20],B[10];
cout<<Enter number of elements in second array(max 10)
->;
cin>>bn;
cout<<\nEnter elements ->;
int i,b,c,a;
for(i=0;i<bn;i++)
{
cin>>B[i];
int x,y,temp;
for(x=0;x<n-1;x++)
{
for(y=0;y<((n-1)-x);y++)
{
if(B[y]>B[y+1])
{
temp=B[y];
19
B[y]=B[y+1];
B[y+1]=temp;
}
}
}
}
for(a=0,b=0,c=0;a<an&&b<bn;)
{
if(ar[a]<=B[b])
{
C[c++]=ar[a++];
}
else
{
C[c++]=B[b++];
}
}
if(a<an)
{
while(a<an)
{
C[c++]=ar[a++];
}
}
else
{
while(b<bn)
{
C[c++]=B[b++];
}
}
for(i=0;i<(an+bn);i++)
{
Cout<<setw(5)<<C[i];
}
getch();
}
Void main()
{
array obj;
int opt,num,pos,no;
Start:
clrscr();
int x=5;
gotoxy(20,x);
cout<<OPERATION On 1-D ARRAY\n;
x=x+2;
gotoxy(20,x);
cout<<1.To Create an array;
20
x++;
gotoxy(20,x);
cout<<2.To display the array;
x++;
gotoxy(20,x);
cout<<3.To insert an element;
x++;
gotoxy(20,x);
cout<<4.To delete an element;
x++;
gotoxy(20,x);
cout<<5.To sort the list;
x++;
gotoxy(20,x);
cout<<6.To search for an element in the list (Binary
Search);
x++;
gotoxy(20,x);
cout<<7.To search for an element in tha list (Linear Search);
x++;
gotoxy(20,x);
cout<<8.To merge two arrays;
x++;
gotoxy(20,x);
cout<<\nEnter your option ->;
cin>>opt;
switch(opt)
{
Case 1: { cout<<\nEnter number of values to be
entered(max 10) ->\n;
cin>>no;
obj.creation(no);
}break;
Case 2: { obj.traversal();
getch();
}break();
Case 3: { cout<<Enter number and position ->;
cin>>num>>pos;
obj.insertion(num,pos);
}break;
Case 4: { cout<<Enter the position at which the
element which has to be deleted;
cin>>pos;
obj.deletion(pos);
}break;
Case 5: { obj.bsort();
}break;
Case 6: { obj.bsearch();
}break;
21
Case 7: { obj.lsearch();
}break;
Case 8: { obj.merging(no);
}break;
}
if(opt<8)
{
goto start;
}
getch();
}
cin>>a[i][j];
}
}
cout<<\nEnter matrix-B\n<<endl;
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<n;j++)
{
c[i][j]=a[i][j]+b[i][j];
}
}
cout<<The sum of the matrices is:\n;
for(i=0;i<m;i++)
{
cout<<\n;
for(j=0;j<n;j++)
{
cout<<\t<<c[i][j];
}
}
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
c[i][j]=a[i][j]-b[i][j];
}
}
cout<<The difference of the matrices is:\n;
for(i=0;i<m;i++)
{
cout<<\n;
for(j=0;j<n;j++)
{
cout<<\t<<c[i][j];
}
}
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
if(i==j||i+j==m-1)
{
23
sumA+=a[i][j];
}
}
}
cout<<\nThe sum of the diagonals of Matrix-A is:\tsumA;
for(i=0;i<p;i++)
{
for(j=0;j<q;j++)
{
if(i==j||i+j==p-1)
{
sumB+=b[i][j];
}
}
}
cout<<\nThe sum of the diagonals of Matrix-A is:\tsumB;
cout<<\nThe sum of the diagonals of Matrix-A and B
:\t<<sumA+sumB;
int ip;
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][ip]*b[ip][j]);
}
}
}
cout<<\nProduct of the two matrices is:<<endl;
for(i=0;i<m;i++)
{
cout<<\n;
for(j=0;j<q;j++)
{
cout<<c[i][j]<< ;
}
}
cout<<Transpose of Matrix-A is<<endl;
for(i=0;i<m;i++)
{
c[i][j]=0;
for(j=0;j<q;j++)
{
c[i][j]=a[j][i];
cout<<c[i][j]<< ;
}
24
}
cout<<Transpose of Matrix-B is<<endl;
for(i=0;i<m;i++)
{
c[i][j]=0;
for(j=0;j<q;j++)
{
c[i][j]=b[j][i];
cout<<c[i][j]<< ;
}
}
getch();
}
Program based on
implementing LIFO operations
using ARRAY ->
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
Class stack
{
Int A[6];
int top;
public:
stack()
{
top = -1;
}
void push();
void pop();
int isempty();
void display();
};
void stack::push()
{
if(top==6)
{
cout<<O/F;
}
else
{
top++;
cout<< enter number:;
25
cin>>A[top];
}
}
void stack::pop()
{
cout<<Deleted is:<<A[top];
top--;
}
int stack::isempty()
{
if(top==-1)
{
return 1;
}
else
{
return 0;
}
}
void main()
{
stack obj;
int opt;
start:
clrscr();
cout<<1.PUSH\n;
cout<<2.POP\n;
cout<<3.DISPLAY\n;
cout<<4.EXIT\n;
cin>>opt;
switch(opt)
{
Case1: obj.push();
Break;
Case2: if(obj.isempty()==1)
cout<<U/F;
else
obj.pop();
getch();
break;
case 3: obj.display();
getch();
break;
}
if(opt<4)
goto start;
getch();
}
26
Program based on
implementing LIFO operations
using LINKED LIST ->
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
Struct node
{
int data;
node*ptr;
};
void push(node*&top)
{
node*t;
t=new node;
cout<<enter number:;
cin>>t ->data;
top=t;
}
void pop(node*&top)
{
cout<<deleted element is:<<top->data;
node*t;
t=top;
top=top->ptr;
delete t;
}
int isempty(node*top)
27
{
if(top==NULL)
return 1;
else
return 0;
}
void display(node*top)
{
node*t;
t=top;
while(t!=NULL)
{
cout<<t->data<<\n;
t=t->ptr;
}
}
void main()
{
node*top;
top=NULL;
int opt;
start:
clrscr();
cout<<1.PUSH\n;
cout<<2.POP\n;
cout<<3.DISPLAY\n;
cout<<4.EXIT\n;
cin>>opt;
switch(opt);
{
case1:push(top);
break;
case2: if(isempty(top)==1)
cout<<U/F;
else
pop(top);
getch();
break;
}
if(opt<4)
goto start;
getch();
}
28
Program based on
implementing FIFO
operations using ARRAY:
#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
void insertion(intq[],int&f,int&r,int num)
{
if(f==0&&r==7)
{ cout<<overflow\n;
getch();}
else
{
if(f==-1)
f=r=0;
else if(r!=7)
r++;
else
for(int i=f;i<=r;i++)
q[i-1]=q[i];
q[r]=num;
}
}
void deletion(int q[],int&f,int&r)
{
cout<<the deleted element is:<<q[f];
if(f==r)
f=r=-1;
else
f++;
}
29
Int isempty(intf)
{
if(f==-1)
Return1;
else
return 0;
};
void display(int q[],int f,int r)
{
for(int i=f;i<=r;i++)
cout<<
setw(5)<<q[i];
}
void main ()
{
intq[8],opt,num,f,r;
f=r=-1;
start;
clrscr();
cout<<setw(10)<<QUEUE OPERATIONS\n\n;
cout<<1.Insertion\n;
cout<<2.Deletion\n;
cout<<3.Display\n;
cout<<4.Exit\n;
cout<<Enter your option\n;
cin>>opt;
switch(opt)
{
case1:cout<<enter the number to be inserted;
Cin>>num;
Insertion(q,f,r,num);
Break;
Case2:if(isempty(f)==1)
Cout<<underflow;
Else
deletion(q,f,r);
getch();
break;
case3:display(q,f,r);
getch();
break;
}
if(opt<4)
goto start;
}
30
Program based on
implementing FIFO
operations using LINKED LIST
->
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
struct node
{
int num;
node*ptr;
};
void insertion(node*&f,node*&r, int num)
{
node*t;
t=new node;
t->num=num;
t->ptr=NULL;
if(f==NULL)
f=r=t;
else
{
r->ptr=t;
r=t;
}
}
void deletion(node*&f,node*&r)
{
node*t;
31
32
Program based on
implementing FIFO
operations using ARRAY as
CIRCULAR QUEUE ->
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<iomanip.h>
void insertion (int q[],int&f,int&r)
{
if((f==0&&r==7)||(r+1==f))
Cout<<overflow\n;
else
{
int num;
cout<<enter element to be inserted\n;
cin>>num;
if(f==-1)
f=r=0;
else if(r==7)
r=0;
else
r=r+1;
q[r]=num;
}
}
void deletion(int q[],int&f,int&r)
{
cout<<the deleted element is:<<q[f];
33
if(f==r)
f=r=-1;
else
f=f+1;
}
int isempty(int f)
{
if(f==-1)
return 1;
else
return 0;
}
void display(int q[],int f,int r)
{
int i;
if(f<r)
for(i=f,i<r;i++)
cout<<setw(5)<<q[i];
else
for(i=f;i<=7;i++)
cout<<setw(5)<<q[i];
for(i=0;i<r;i++)
cout<<setw(5)<<q[i];
}
void main()
{
int f,r;
f=r=-1;
int q[8];
int opt;
start:
clrscr();
cout<<CIRCULAR QUEUE OPERATIONS\n;
cout<<1.Insertion\n;
cout<<2.Deletion\n;
cout<<3.Display\n;
cout<<4.Exit\n;
cout<<Enter your option\n;
cin>>opt;
switch(opt)
{
case1: insertion(q,r,f);
Break;
Case2: if(isempty(f)==1)
cout<<underflow\n;
else
deletion(q,f,r);
getch();
Break;
Case3:display(q,f,r);
getch();
}
if(opt<4)
goto start;
}
34
clrscr();
Ucase_alphabets();
getch();
}
{
tfile.get(str);
}
}
if(str== )
{
c++;
}
}
}
}
tfile.close();
cout<<Number of times the appear is:<<c;
}
void main()
{
clrscr();
count_word();
getch();
}
clrscr();
countline();
getch();
}
FLIGHT F;
fstream fin;
fin.open(FLIGHT.DAT, ios::app|ios::out|ios::binary);
int n, I;
clrscr();
cout<< Enter how many flight data you want to enter : ;
cin>> n;
for(i=0; i<n; i++)
{
cout<< Enter data for flight : <<i+1;
F. Enter();
fin.write((char*))&F,sizeof(FLIGHT));
}
fin.close();
}
Void Read()
{
FLIGHT F;
ifstream fin;
fin.open( FLIGHT.DAT, ios::binary);
while(fin.read((char*)&F,sizeof(FLIGHT)))
{
if(strcmp(F.GetTo(), Mumbai)==0)
F.Display();
}
Fin. Close();
}
void main()
{
clrscr();
Flight_Enter();
Read();
getch();
}
39
40
cin<<n;
for(i=0; i<n; i++)
{
cout<<\n Enter the telephone number;
cin>>tele.tno;
cout<<\n Enter the name;
cin>>tele.name;
tfile.write((char*)&tele,sizeof(tele));
}
}
void display()
{
Ifstream tfile;
tfile.open(tele.dat,ios :: binary);
int no, flag;
flag=0;
cout<<\n Enter the telephone number to be searched;
cin>>no;
while(tfile)
{
tfile.read((char*)&tele,sizeof(tele));
if(!tfile)
break;
if(tele.tno==no)
{
cout<<\n Name<<tele.name;
cout<<\n Telephone No<<tele.tno;
flag=1;
}
}
if(flag==0)
{
Cout<<\n Record does not exist;
}
}
void main()
{
clrscr();
append();
display();
getch();
}
41
42
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;
}
voidputdata()
{
cout<<rollno<<rollno<<\tname:<<name<<\nmarks:<<marks<<\
tgrade<<grade<<endl;
}
int getrno()
{
return rollno;
}
}s1,stud;
int main()
{
ifstream fio(stu.dat,ios::in);
ofstream file(temp.dat,ios::out);
int rno;
char found=f,confirm=n;
cout<<Enter rollno of student whose record is to be deleted\n;
cin>>rno;
while(!fio.eof())
{
fio.read((char*)&s1,size of(s1));
if(s1.getrno()==rno)
{
s1.putdata();
found=t;
cout<<are you sure,you want to delete this
record(y/n)..;
cin>>confirm;
if(confirm==n)
file.write((char*)&s1,size of(s1));
}
else
{
file.write((char*)&s1,size of(s1));
}
if(found==F)
cout<<record not found!!\n;
43
fio.close();
file.close();
remove(stu.dat);
rename(temp.dat,stu.dat);
fio.open(stu.dat,ios::in);
cout<<now the file contains\n;
while(!fio.eof())
{
fio.read((char*)&stud,size of(stud));
if(fio.eof())
Break;
stud.putdata();
}
fio.close();
return 0;
}
}
Name
Amit
Manoj
Abhai
Vinod
Ramesh
Dobirth
23-jan-1965
12-dec-1976
11-aug-1975
04-apr-1974
28-oct-1981
Native-place
Delhi
Mumbai
Allahabad
Mumbai
Pune
Name
Amit
Abhai
Dobirth
23-jan-1965
12-dec-1976
11-aug-1975
04-apr-1974
28-oct-1981
Dobirth
23-jan-1965
11-aug-1975
Native-place
Delhi
Mumbai
Allahabad
Mumbai
Pune
Hobby
Music
Writing
Music
Sports
Sports
Native-place
Delhi
Allahabad
Hobby
Music
Music
45
Table: 02
Table: Student
No.
1.
2.
3.
4.
5.
6.
7.
Name
Pankaj
Shalini
Sanjay
Sudha
Rakesh
Shikha
Surya
Age
24
21
22
25
22
23
23
Department
Computer
History
Hindi
History
Hindi
Hindi
Computer
Dateofadm
10/01/97
24/03/98
12/12/96
01/07/99
05/09/97
31/07/97
25/02/97
Fee
120
200
300
400
250
200
210
Sex
M
F
M
F
M
F
M
Pankaj
Rakesh
Sanjay
Shalini
Shikha
Sudha
Surya
24
22
22
21
23
25
34
Computer
Hindi
Hindi
History
Hindi
History
Computer
10/01/97
05/09/97
12/12/96
24/03/98
31/07/97
01/07/99
25/02/97
120
250
300
200
200
400
210
M
M
M
F
F
F
M
21
23
25
History
Hindi
History
24/03/98
31/07/97
01/07/99
200
200
400
F
F
F
Table: 03
Table:Furniture
No.
1
2
3
4
5
6
7
8
9
10
Itemname
White lotus
Pink feather
Dolphin
Decent
Comfort zone
Donald
Royal finish
Royal tiger
Econo sitting
Eating
paradise
Type
Double bed
Baby cot
Baby Cot
Office table
Double bed
Baby cot
Office table
Sofa
Sofa
Dining table
Dateofstock
23/02/02
20/01/02
19/02/02
01/01/02
12/01/02
24/02/02
20/02/02
22/02/02
13/12/01
19/02/02
Price
30000
7000
9500
25000
25000
18000
18000
31000
9500
11500
Discount
25
20
20
30
25
30
30
30
25
25
47
25
35
30
52.5
25
30000
18000
25000
31000
11500
Double bed
Baby Cot
Baby cot
Office table
Sofa
Dining table
23/02/02
19/02/02
24/02/02
20/02/02
22/02/02
19/02/02
30000
9500
18000
18000
31000
11500
25
20
30
30
30
25
Price
25000
18000
18000
31000
Discount
30
30
30
30
Table: 04
Table: Books
Book_id
C0001
F0001
Book_name
Fast Cook
The tears
T0001
T0002
My first C++
C++
brainworks
Thunderbolts
F0002
Author_name
Lata Kapoor
William
Hopkins
Brian & brooke
A.W. Rossaine
Publishers
EPB
First publ.
Price
355
650
Type
Cookery
Fiction
Qty
5
20
EPB
TDH
350
350
Text
Text
10
15
Anna Roberts
First publ.
750
Fiction
50
Publishers
First publ.
Price
650
Type
Fiction
Qty
30
First publ.
750
Fiction
60
UPDATE Books
SET Qty=Qty+10
WHERE Price>350;
Book_id
F0001
Book_name
The tears
F0002
Thunderbolts
Author_name
William
Hopkins
Anna Roberts
48
Book_name
Author_name
Publishe
rs
EPB
EPB
C0001
T0001
Fast Cook
My first C++
T0002
C++
brainworks
Lata Kapoor
Brian &
brooke
A.W. Rossaine TDH
Price
Type
Qty
355
350
Cookery
Text
5
10
350
Text
15
49
50