computer programs(20)
TRANSCRIPT
8/9/2019 Computer programs(20)
http://slidepdf.com/reader/full/computer-programs20 1/70
Sr.N
o.
TOPIC DATE
TEACHER’s SIGN
1. Implementation ofPolymorphism
.Implementation of!
a" Sin#le inheritan$e%" &'ltiple inheritan$e
$" &'ltile(elinheritan$e)" Hierar$hi$al
inheritan$e*. A))ition of matri$es
+. &'ltipli$ation of matri$es
,. Insertion operation of an
array-. Deletion operation of an
array. Se/'ential sear$h in an
array0. inary sear$h in an array
2. Sort an array 'sin# %'%%le
sort13.
Sort an array 'sin#sele$tion sort
11.
Sort an array 'sin#insertion sort
1
8/9/2019 Computer programs(20)
http://slidepdf.com/reader/full/computer-programs20 2/70
1 &er#in# t4o arrays 'sin#mer#e sort
1*
.Rea) a te5t 6le an) $o'ntthe total no. of !
a" 7pper$ase letters%" 8o4er$ase letters$" Di#its)" Spe$ial sym%ols
1+
.Rea) te5t 6le an) $opy)ata in t4o te5t 6lessim'ltaneo'sly on the%asis of !
a" All the 'pper$aseletters an) )i#its in thete5t 6le
%" All the lo4er$aseletters an) spe$ialsym%ols
1,.
Operate all )ata 6lehan)lin# operations for a%inary 6le
1-
.
Perform p'sh an) pop
operation in linear sta$9 1.
Perform p'sh an) popoperation in lin9e) sta$9
10.
Perform insertion an))eletion operation in linear
2
8/9/2019 Computer programs(20)
http://slidepdf.com/reader/full/computer-programs20 3/70
/'e'e
12.
Perform insertion an))eletion operation in
lin9e) /'e'e3.
S:8 :'eries
3
8/9/2019 Computer programs(20)
http://slidepdf.com/reader/full/computer-programs20 4/70
1. Implementation of polymorphism
#include<iostream.h>
#include<stdlib.h>
#include<conio.h>
#defne pi 3.14
class n
{
public:
void area(int! ""circle
void area(intint! ""rectan$le
void area(%oat intint! ""trian$le
void area(!
&!
void n::area(int a
{cout<<'rea o )ircle:'<<pi*a*a! ""+unction 1&
void n::area(int aint b
{ cout<<'rea o rectan$le:'<<a*b! ""+unction 2&
void n::area(%oat tint aint b
{ cout<<'rea o cuboid:'<<2*(a*b,b*t,a*t! & ""+unction 3
void n::area( ""+unction 4
{cout<<'-n1.ectan$le/l*b-n2.)uboid/2*(l*h,h*b,b*l-n3.)ircle/3.14*r2'!&
void main(
4
8/9/2019 Computer programs(20)
http://slidepdf.com/reader/full/computer-programs20 5/70
{ int ch!
int abr!
char ch1/00!
clrscr(!
n ob!
cout<<'-n-t-t+unction verloadin$'!
cout<<'-n1.rea o )ircle-n2.rea o ectan$le-n3.rea o)uboid-n4.+ormulas-n'!
hile(ch1//0055ch1//060
{cout<<'7nter our )hoice:'!
cin>>ch!
sitch(ch
{ case 1: cout<<'7nter adius o the )ircle:'!
cin>>r!
ob.area(r! "")alls +unction 1
brea8!
case 2: )out<<'7nter 9ides o the ectan$le:'!
cin>>a>>b!
ob.area(ab! "")alls +unction 2
brea8!
case 3: cout<<'7nter 9ides o the )uboid:'!
cin>>a>>b!
ob.area(.;ab! "")alls +unction 3
;
8/9/2019 Computer programs(20)
http://slidepdf.com/reader/full/computer-programs20 6/70
brea8!
case 4: cout<<'+ormulas:'!
ob.area(! "")alls +unction 4
brea8!
&
cout<<'-t-tant to enter more==='!
cin>>ch1!
&
$etch(!&
O'tp't
8/9/2019 Computer programs(20)
http://slidepdf.com/reader/full/computer-programs20 7/70
. PROGRA& TO I&P8E&ENT THE CONCEPT
A" SING8E INHERITANCE
" &78TIP8E INHERITANCE
C" &78TI8E;E8 INHERITANCE
D" HIERARCHIA8 INHERITANCE
#include<stdio.h>
#include<iostream.h>
#include<conio.h>
class ""?ase class
{
int a1a2!
public:
void $etdata(
{
cout<<'-n7nter value o a1 and a2-n'!
cin>>a1>>a2!
&
void putdata(
{
cout<<'a1'<<a1<<'a2'<<a2<<endl!
&&!
class 1 ""?ase class
{
@
8/9/2019 Computer programs(20)
http://slidepdf.com/reader/full/computer-programs20 8/70
int a11a21!
public:
void $etdata1(
{
cout<<'-n7nter value o a11 and a21-n'!
cin>>a11>>a21!
&
void putdata1(
{
cout<<'-na11'<<a11<<'a21'<<a21<<endl!
&&!
class ?: public
{
int b1b2!
public:
void indata(
{
cout<<'-n'!
cin>>b1>>b2!
&
void outdata(
{
cout<<'-nb1'<<b1<<'b2'<<b2<<endl!
A
8/9/2019 Computer programs(20)
http://slidepdf.com/reader/full/computer-programs20 9/70
&&!
class ): public ?
{
int c1c2!
public:
void input(
{
cout<<'-n7nter the value o c1 and c2-n'!
cin>>c1>>c2!
&
void output(
{
cout<<'c1'<<c1<<'c2'<<c2!
&&!
class B: public
{
int d1d2!
public:
B(
{
d1/!
d2/!
&&!
C
8/9/2019 Computer programs(20)
http://slidepdf.com/reader/full/computer-programs20 10/70
class 7: public public 1
{
int e1e2!
public:
7(
{
e1/!
e2/!
&&!
void main(
{
clrscr(!
7 ob1! ""Dultiple Enheritance
B ob2! ""Fierarchical Enheritance sin$le inheritance
) ob3! ""Dultilevel Enheritance
int i!
cout<<'1.9in$le inheritance-n'!
cout<<'2.Dultiple inheritance-n'!
cout<<'3.Dultilevel inheritance-n'!
cout<<'4.Fierarchial inheritance-n'!
cin>>i!
sitch(i
{
1
8/9/2019 Computer programs(20)
http://slidepdf.com/reader/full/computer-programs20 11/70
case 1:cout<<'ccessin$ class throu$h obect o ?-n'!
ob2.$etdata(!
ob2.putdata(! ""member unctions o class
brea8!
case 2:cout<<'-nccessin$ class and 1(?ase classes b obect o 7-n'!
ob1.$etdata(!
ob1.$etdata1(!
ob1.putdata(! ""member unctions o class and 1!
ob1.putdata1(!
brea8!
case 3:cout<<'ccessin$ ?ase class b obect o )'!
ob3.$etdata(!
cout<<'-nccessin$ subclass ? b obect o )'!
ob3.indata(!
cout<<'-nGhe values o class and ? are:-n'!
ob3.putdata(!
ob3.outdata(!
brea8!
case 4:cout<<'ccessin$ class b obect o its suclass ?-n'!
ob3.$etdata(!
ob3.putdata(!
cout<<'-nccessin$ class b obect o its subclass B-n'!
ob2.$etdata(!
11
8/9/2019 Computer programs(20)
http://slidepdf.com/reader/full/computer-programs20 12/70
ob2.putdata(!
cout<<'-nccessin$ class b obect o its subclass 7-n'!
ob1.$etdata(!
ob1.putdata(!
brea8! &
$etch(!
&
O7TP7T
12
8/9/2019 Computer programs(20)
http://slidepdf.com/reader/full/computer-programs20 13/70
13
8/9/2019 Computer programs(20)
http://slidepdf.com/reader/full/computer-programs20 14/70
*. A))ition of matri$es
#include<iostream.h>
#include<conio.h>
void main(
{ int aH;IH;IbH;IH;IcH;IH;Ii8ln!
cout<<'enter the to arras:'!
cout<<'enter siJe o arras:'!
cin>>n!
cout<<'1.:'!
or(i/!i<n!,,i
{ or(/!<n!,,
{cin>>aHiIHI!
&
&
cout<<'2.:'!
or(i/!i<n!,,i
{ or(/!<n!,,
{cin>>bHiIHI!
&
&
cout<<'ddition o matrices:'!
or(8/!8<n!,,8
{ or(l/!l<n!,,l
14
8/9/2019 Computer programs(20)
http://slidepdf.com/reader/full/computer-programs20 15/70
{ cH8IHlI/aH8IHlI , bH8IHlI!
&
&
cout<<'esult:-n'!
or(i/!i<n!,,i
{ or(/!<n!,,
{cout<<cHiIHI!
cout<<'-t'!
&
cout<<'-n'
&
$etch(! &
+. &'ltipli$ation of matri$es
1;
8/9/2019 Computer programs(20)
http://slidepdf.com/reader/full/computer-programs20 16/70
#include<iostream.h>
#include<conio.h>
void main(
{ int aH1IH1I bH1IH1I cH1IH1Imnn1m1ii1!
cout<<'enter the no. o ro0s in arra 1.:'!
cin>>m!
cout<<'enter the no. o column0s in arra 1.:'!
cin>>n!
cout<<'enter the no. o ro0s in arra 2.:'!
cin>>m1!
cout<<'enter the no. o column0s in arra 2.:'!
cin>>n1!
i(n//m1
cout<<'arra can be multiplied'!
cout<<'enter the arra 1.:'!
or(i/!i<m!i,,
{ or(/!<n!,,
{ cin>>aHiIHI!
&!
&!
cout<<'enter the arra 2.:'!
1
8/9/2019 Computer programs(20)
http://slidepdf.com/reader/full/computer-programs20 17/70
or(i/!i<m1!i,,
{ or(/!<n1!,,
{ cin>>bHiIHI!
&!
&!
or(i/!i<m!,,i
or(/!<n1!,,
{ or(i1/!i1<m1!,,i1
{ cHiIHI/cHiIHI,(aHiIHi1I*bHi1IHI!
cout<<'-t'! &
cout<<'-n'! &
cout<<' the product o the to matriK :'!
or(i/!i<m!i,,
{ cout<<'-n'!
or(/!<n1!,,
{ cout<<cHiIHI!
cout<<'-t'! &&
$etch(!&
1@
8/9/2019 Computer programs(20)
http://slidepdf.com/reader/full/computer-programs20 18/70
1A
8/9/2019 Computer programs(20)
http://slidepdf.com/reader/full/computer-programs20 19/70
,. Insertion operation in an array
#include<iostream.h>
#include<conio.h>
#include<process.h>
int insert(intHIintint!
void main(
{int aH1;IinKs!
cout<<'7nter the siJe o the arra :'!
cin>>n!
cout<<'7nter the arra:'!
or(i/!i<n!,,i
{ cin>>aHiI!
&
char ch/00!
hile(ch//0055ch//060
{ cout<<'7nter the item to be inserted :'!
cin>>K!
i(n//1;
{ cout<<'over%oLLL'!
&
s/insert(anK!
or(i/n!i>s!iMM
{ aHiI/aHiM1I!
1C
8/9/2019 Computer programs(20)
http://slidepdf.com/reader/full/computer-programs20 20/70
&
,,n!
aHsI/K!
cout<<'ant to insert more=='!
cin>>ch!
&
cout<<'Ghe arra no is:'!
or(i/!i<n!,,i
{ cout<<aHiI<<'-t'!
&
$etch(!
&
int insert(int bHIint siJeint item
{ int pi!
i(item<bHI
p/!
else
{or(i/!i<siJeM1!,,i
{ i(bHiI</itemNNbHi,1I>item
{p/i,1!
brea8!
&
&
2
8/9/2019 Computer programs(20)
http://slidepdf.com/reader/full/computer-programs20 21/70
i(i//siJeM1
p/siJe!
&
return p!
&
-. Deletion operation in an array
#include<iostream.h>
21
8/9/2019 Computer programs(20)
http://slidepdf.com/reader/full/computer-programs20 22/70
#include<conio.h>
int search(intHI intint!
void main(
{ int aH1;InKis!
cout<<'7nter the siJe o arra :'!
cin>>n!
cout<<'7nter the arra:'!
or(i/!i<n!,,i
{ cin>>aHiI! &
char ch/00!
hile(ch//0055ch//060
{ cout<<'7nter the item to be deleted :'!
cin>>K!
s/search(anK!
i(s//M1
{cout<<'Etem not ound...'!
&
else
or(i/s!i<n!i,,
{aHiI/aHi,1I!&
nM/1!
cout<<'ant to delete more items==='!
cin>>ch!&
22
8/9/2019 Computer programs(20)
http://slidepdf.com/reader/full/computer-programs20 23/70
cout<<'ter deletion the arra is:'!
or(i/!i<n!,,i
{ cout<<aHiI!&
$etch(!
&
int search(int bHI int siJe int item
{int $lm!
$/!
l/siJeM1!
hile($</l
{m/($,l"2!
i(item//bHmI
return m!
else i(item >bHmI
$/m,1!
else l/mM1!
&return M1 !&
23
8/9/2019 Computer programs(20)
http://slidepdf.com/reader/full/computer-programs20 24/70
24
8/9/2019 Computer programs(20)
http://slidepdf.com/reader/full/computer-programs20 25/70
. Se/'ential sear$h in an array
#include<iostream.h>
#include<conio.h>
int search(intHIint int!
void main(
{int aH1;InKis!
cout<<'7nter the siJe o the arra :'!
cin>>n!
cout<<'7nter the arra :'!
2;
8/9/2019 Computer programs(20)
http://slidepdf.com/reader/full/computer-programs20 26/70
or(i/!i<n!,,i
{cin>>aHiI!
&
cout<<'7nter the element to be searched or:'!
cin>>K!
s/search(anK!
i(s//M1
{ cout<<'Ghe element could not be ound LLLL'!
&
cout<<'Ghe element is at this position:'<<s!
$etch(!
&
int search(int bHIint siJe int item
{int i!
or(i/!i<siJe!,,i
{ i(bHiI//item
return i!&
return M1!
&
2
8/9/2019 Computer programs(20)
http://slidepdf.com/reader/full/computer-programs20 27/70
0. inary sear$h in an array
#include<iostream.h>
#include<conio.h>
int search(intHI intint!
void main(
{ int aH1;InKis!
2@
8/9/2019 Computer programs(20)
http://slidepdf.com/reader/full/computer-programs20 28/70
cout<<'7nter the siJe o arra :'!
cin>>n!
cout<<'7nter the arra:'!
or(i/!i<n!,,i
{ cin>>aHiI! &
cout<<'7nter the item to be searched :'!
cin>>K!
s/search(anK!
i(s//M1
{cout<<'Etem not ound...'!
&
else
cout<<'Etem ound at this position:'<<s,1!
$etch(!
&
int search(int bHI int siJe int item
{int $lm!
$/!
l/siJeM1!
hile($</l
{m/($,l"2!
i(item//bHmI
return m!
2A
8/9/2019 Computer programs(20)
http://slidepdf.com/reader/full/computer-programs20 29/70
else i(item >bHmI
$/m,1!
else l/mM1!
&
return M1!
&
2. Sort an array 'sin# %'%%le sort
#include<iostream.h>
#include<conio.h>
void bsort(int HIint!
void main(
{ int aH1;InKi!
cout<<'7nter the siJe o arra:'!
2C
8/9/2019 Computer programs(20)
http://slidepdf.com/reader/full/computer-programs20 30/70
cin>>n!
cout<<'7nter the arra:'!
or(i/!i<n!,,i
{cin>>aHiI!
&
bsort(an!
cout<<'Ghe sorted arra is:'!
or(i/!i<n!,,i
{ cout<<aHiI!
&
$etch(!
&
void bsort(int bHIint siJe
{int itc/m!
or(i/!i<siJe!,,i
{ or(/!<(siJeM1!,,
{ i(bHI>bH,1I
{ t/bH,1I!
bH,1I/bHI!
bHI/t!
&
&
cout<<'rra ater iteration '<<,,c<<'-t'!
3
8/9/2019 Computer programs(20)
http://slidepdf.com/reader/full/computer-programs20 31/70
or(m/!m<siJe!,,m
{cout<<bHmI!
&
cout<<'-n'!
&
&
13. Sort an array 'sin# sele$tion sort
#include<iostream.h>
#include<conio.h>
void selsort(intHIint!
void main(
{ clrscr(!
int arH;IitemnindeK!
31
8/9/2019 Computer programs(20)
http://slidepdf.com/reader/full/computer-programs20 32/70
cout<<'Fo man elements do ou ant to create arra ith=(maK.;...'!
cin >>n!
cout<<'-n7nter arra elements...-n'!
or(int i/!i<n!i,,
cin >>arHiI!
selsort(arn!
cout<<'-n-nGhe sorted arra is as shon belo...-n'!
or(i/!i<n!i,,
cout<<arHiI<<' '!
cout<<endl!
$etch(!
&
void selsort(int arHIint siJe
{ int smalltmppos!
or(int i/!i<siJe!i,,
{ small/arHiI!
or(int /i,1!<siJe!,,
{ i(arHI<small
{ small/ arHI!
pos/!
&
&
32
8/9/2019 Computer programs(20)
http://slidepdf.com/reader/full/computer-programs20 33/70
tmp/arHiI!
arHiI/arHposI!
arHposI/tmp!
&
cout<<endl!
&
11. Sort an array 'sin# insertion sort
#include<iostream.h>
#include<conio.h>
#include<limits.h>
void inssort(intHIint!
void main(
{ clrscr(!
33
8/9/2019 Computer programs(20)
http://slidepdf.com/reader/full/computer-programs20 34/70
int arH;IitemnindeK!
cout<<'Fo man elements do ou ant to create arra ith=(maK.;...'!
cin >>n!
cout<<'-n7nter arra elements...-n'!
or(int i/1!i</n!i,,
cin >>arHiI!
inssort(arn!
cout<<'-n-nGhe sorted arra is as shon belo...-n'!
or(i/1!i</n!i,,
cout<<arHiI<<' '!
cout<<endl!
$etch(!
&
void inssort(int arHIint siJe
{ int tmp!
arHI/EOGPDEO!
or(int i/1!i</siJe!i,,
{ tmp/arHiI!
/iM1!
hile(tmp<arHI
{ arH,1I/arHI!
MM!
34
8/9/2019 Computer programs(20)
http://slidepdf.com/reader/full/computer-programs20 35/70
&
arH,1I/tmp!
cout<<endl!
&
&
3;
8/9/2019 Computer programs(20)
http://slidepdf.com/reader/full/computer-programs20 36/70
1. &er#in# an array 'sin# mer#e sort
#include<iostream.h>
#include<conio.h>
void mer$e(intHIintintHIintintHI!
void main(
{ clrscr(!
int H;I?H;I)H;IDO/DO!
cout<<'Fo man elements do ou ant to create frst arra ith=
(maK. ;...'!
cin >>D!
cout<<'-n7nter frst arra0s elements Hascendin$I...-n'!
or(int i/!i<D!i,,
{ cin >>HiI!&
cout<<'Fo man elements do ou ant to create second arra ith=
(maK. ;...'!
cin >>O!
DO/D,O!
cout<<'-n7nter frst arra0s elements Hdescendin$I...-n'!
or(i/!i<O!i,,
{ cin >>?HiI!&
mer$e(D?O)!
cout<<'-n-nGhe mer$ed arra is as shon belo...-n'!
or(i/!i<DO!i,,
3
8/9/2019 Computer programs(20)
http://slidepdf.com/reader/full/computer-programs20 37/70
{ cout<<)HiI<<' '!&
cout<<endl!
$etch(!
&
void mer$e(int HI int D int ?HI int O int )HI
{ int abc!
or(a/b/OM1c/ ! a<D NN b>/!
{ i(HaI</?HbI
{ )Hc,,I/Ha,,I!
&
else
{ )Hc,,I/?HbMMI!&
&
i(a<D
{ hile(a<D
{ )Hc,,I/Ha,,I!&&
else
{ hile(b>/
{ )Hc,,I/?HbMMI!&&&
3@
8/9/2019 Computer programs(20)
http://slidepdf.com/reader/full/computer-programs20 38/70
3A
8/9/2019 Computer programs(20)
http://slidepdf.com/reader/full/computer-programs20 39/70
1*. Rea) a te5t 6le an) $o'nt total n'm%er of!a" 7pper$ase letters%" 8o4er$ase letters$" Di#its
)" Spe$ial sym%ols
#include<iostream.h>
#include<conio.h>
#include<stream.h>
#include<ctpe.h>
void main(
{ clrscr(!
char ch!
ostream o('teKt1.tKt'!
or(int i/1!i</;!i,,
{ cout<<'7nter a character : ' !
cin >>ch!
o<<ch!
&
o.close(!
istream i1('teKt1.tKt'!
int u/l/d/s/!
i1.see8$(!
cout<<'-n'!
or(i/1!i</;!i,,
3C
8/9/2019 Computer programs(20)
http://slidepdf.com/reader/full/computer-programs20 40/70
{ i1.$et(ch!
i(isupper(ch
u,,!
else i(isloer(ch
l,,!
else i(isdi$it(ch
d,,!
else
s,,!
cout<<')haracter '<<i<<' / '<<ch!
cout<<'-n'!
&
i1.close(!
cout<<'Gotal Qpper value / '<<u!
cout<<'-nGotal loer value / '<<l!
cout<<'-nGotal di$it value / '<<d!
cout<<'-nGotal special smbol value / '<<s!
$etch(!&
4
8/9/2019 Computer programs(20)
http://slidepdf.com/reader/full/computer-programs20 41/70
41
8/9/2019 Computer programs(20)
http://slidepdf.com/reader/full/computer-programs20 42/70
1+. Rea) a te5t 6le an) $opy the )ata in te5t 6les sim'ltaneo'slyon the %asis of!a" All the 'pper$ase letters an) )i#its in the te5t 6le%" All the lo4er$ase letters an) spe$ial sym%ols
#include<iostream.h>
#include<conio.h>
#include<stream.h>
#include<ctpe.h>
void main(
{ clrscr(!
char ch!
ostream o('teKt1.tKt'!
or(int i/1!i</@!i,,
{ cout<<'7nter a character : '!
cin >>ch!
o << ch!
&
o.close(!
istream i1('teKt1.tKt'!
ostream o1('ud.tKt'!
ostream o2('ls.tKt'!
int u/l/!
i1.see8$(!
42
8/9/2019 Computer programs(20)
http://slidepdf.com/reader/full/computer-programs20 43/70
cout<<'-n'!
or(i/1!i</@!i,,
{
i1.$et(ch!
i(isupper(ch55isdi$it(ch
{ o1<<ch!
u,,!
&
else
{ o2<<ch!
l,,!
&
cout<<')haracter '<<i<<' / '<<ch!
cout<<'-n'!
&
i1.close(!
o1.close(!
o2.close(!
cout<<'total upper and di$it value / '<<u!
cout<<'-nGotal loer and special smbol value / '<<l!
istream i2('ud.tKt'!
istream i3('ls.tKt'!
cout<<'-n-n)ontents o the fle1-n'!
43
8/9/2019 Computer programs(20)
http://slidepdf.com/reader/full/computer-programs20 44/70
8/9/2019 Computer programs(20)
http://slidepdf.com/reader/full/computer-programs20 45/70
#include<iostream.h>
#include<conio.h>
#include<stream.h>
#include<stdio.h>
int cnt/!
class student
{
public:
char nameHAI!
int rno!
void $etdata(
{
cout<<'7nter the roll no.'!
cin>>rno!
cout<<'-n7nter the name: '!
$ets(name!
&
void putdata(
{
cout<<'-n-noll no: '<<rno!
cout<<'-nOame: '<<name!
&
&s!
4;
8/9/2019 Computer programs(20)
http://slidepdf.com/reader/full/computer-programs20 46/70
void main(
{
void rfle(!
void afle(!
void mfle(!
void dfle(!
char ans/00!
int choice/!
hile(ans//00
{
clrscr(!
cout<<'7nter our choice'<<'-n'!
cout<<'-n1.read fle'!
cout<<'-n2.append fle'!
cout<<'-n3.modi in fle'!
cout<<'-n4.delete rom fle'!
cout<<'-n7nter our choice: '!
cin>>choice!
i(choice//1
rfle(!
i(choice//2
afle(!
i(choice//3
4
8/9/2019 Computer programs(20)
http://slidepdf.com/reader/full/computer-programs20 47/70
mfle(!
i(choice//4
dfle(!
cout<<'-n-nBo ou ant to continue= '!
cin>>ans!
&
$etch(!
&
void rfle(
{
istream r!
r.open('temp'ios::in5ios::binar!
hile(r
{
r.read((char*NssiJeo(s!
s.putdata(!
&
r.close(!
&
void afle(
{
ostream r!
4@
8/9/2019 Computer programs(20)
http://slidepdf.com/reader/full/computer-programs20 48/70
r.open('temp'ios::app5ios::binar!
s.$etdata(!
r.rite((char*NssiJeo(s!
r.close(!
cout<<'ecord added successul'!
&
void mfle(
{
stream r!
r.open('temp'ios::in5ios::out5ios::binar!
int item!
cout<<'7nter searchin$ rollno: '!
cin>>item!
int record/!
r.see8$(!
hile(r
{
r.read((char*NssiJeo(s!
record,,!
i(item//s.rno
{
s.putdata(!
cout<<'-n7nter the modifed data: '!
4A
8/9/2019 Computer programs(20)
http://slidepdf.com/reader/full/computer-programs20 49/70
s.$etdata(!
r.see8p((recordM1*siJeo(sios::be$!
$etch(!
r.rite((char*NssiJeo(s!
&
&
r.close(!
&
void dfle(
{ stream r2!
r.open('temp'ios::in5ios::out5ios::binar!
2.open('tr'ios::out5ios::binar!
int item!
cout<<'7nter the roll number to be deleted: '!
cin>>item!
hile(r
{
r.read((char*NssiJeo(s!
i(item//s.rno!
else
2.rite((char*NssiJeo(s!
&
r.close(!
4C
8/9/2019 Computer programs(20)
http://slidepdf.com/reader/full/computer-programs20 50/70
2.close(!
remove('temp'!
rename('tr''temp'!
&
;
8/9/2019 Computer programs(20)
http://slidepdf.com/reader/full/computer-programs20 51/70
1-. Perform p'sh an) pop operation in a linear sta$9
#include<iostream.h>
#include<conio.h>
#include<process.h>
int p(int HIintNint!
int pop(int HIintN!
void d(int HIint!
;1
8/9/2019 Computer programs(20)
http://slidepdf.com/reader/full/computer-programs20 52/70
int const siJe/1;!
void main(
{ int isHsiJeIrrest/M1!
char ch/00ch1!
hile(ch//0055ch//060
{ cout<<'-n7nter the item or insertion:'!
cin>>i!
r/p(sti!
i(r//M1
{ cout<<'ver%oLLL'!
eKit(1!
&
cout<<'-nGhe stac8 is:'!
d(st!
cout<<'-nant to insert more=='!
cin>>ch!
&
ch1/00!
cout<<' delete elements'!
hile(ch1//0055ch1//060
{ res/pop(st!
i(res//M1
{ cout<<'Qnder%oLLL'!
;2
8/9/2019 Computer programs(20)
http://slidepdf.com/reader/full/computer-programs20 53/70
eKit(1!
&
cout<<'Ghe element hich is deleted is:'<<res!
cout<<'-nGhe stac8 is:'!
d(st!
cout<<'-nant to delete more elements=='!
cin>>ch1!&
$etch(!
&
int p(int aHIint N topint e
{ i(top//siJeM1
{ return M1!
&
else
{ top,,!
aHtopI/e!
return !&
&
int pop(int aHIintNtop
{int !
i(//siJeM1
{return M1!&
else
;3
8/9/2019 Computer programs(20)
http://slidepdf.com/reader/full/computer-programs20 54/70
{ /aHtopI!
topMM!
return !&&
void d(int aHI int top
{ i(top//M1 return!
cout<<aHtopI<<'M'!
or(int i/topM1!i>/!iMM
cout<<'-n'<<aHiI!&
;4
8/9/2019 Computer programs(20)
http://slidepdf.com/reader/full/computer-programs20 55/70
1. Perform p'sh an) pop operation in lin9e) sta$9
#include<iostream.h>
#include<conio.h>
#include<process.h>
struct Oode{ int ino !
Oode * neKt !
& *top *neptr *save *ptr !
Oode * )reatePOePOode( int !
void Rush( Oode* !
void Bispla( Oode* !
void Rop( !
void main(
{ top / OQSS !
int in ! char ch / 00 !
hile ( ch //00 55 ch // 060
;;
8/9/2019 Computer programs(20)
http://slidepdf.com/reader/full/computer-programs20 56/70
{ cout << '-n 7nter EO+rmation or the ne node...' !
cin >> in !
neptr / )reatePOePOode( in !
i ( neptr // OQSS
{ cout <<'-n)annot create ne nodeLLL bortin$LL-n' !
$etch( !
eKit(1 !
&
Rush( neptr !
cout << '-n Rress 6 to enter more nodes O to eKit...'!
cin >> ch !
&
clrscr( !
do
{ cout << '-n Ghe 9tac8 no is : -n' !
Bispla( top ! $etch( !
cout << 'ant to pop an element= ("n...' !
cin >> ch !
i ( ch // 00 55 ch // 060 Rop( !
& hile ( ch // 00 55 ch // 060 !
&
Oode * )reatePOePOode( int n
{ ptr / ne Oode !
;
8/9/2019 Computer programs(20)
http://slidepdf.com/reader/full/computer-programs20 57/70
ptr M> ino / n!
ptr M> neKt / OQSS !
return ptr !&
void Rush( Oode* np
{ i ( top // OQSS top / np !
else
{ save / top ! top / np !
np M> neKt / save !
&&
void Rop(
{ i( top // OQSS cout << ' QOB7+S LLL-n ' !
else
{ ptr / top ! top/ top M> neKt !
delete ptr !&
&
void Bispla( Oode* np
{ hile ( np L/OQSS
{ cout << np M> ino << ' M> ' !
np / np M> neKt !&
cout << 'LLL-n' !&
;@
8/9/2019 Computer programs(20)
http://slidepdf.com/reader/full/computer-programs20 58/70
;A
8/9/2019 Computer programs(20)
http://slidepdf.com/reader/full/computer-programs20 59/70
10. Perform p'sh an) pop operation in linear /'e'e
#include<iostream.h>
#include<conio.h>
#include<process.h>
int emove(int HI !
int Ensert(int HI int !
void Bispla(int HI int int !
const int siJe / ; !
int TueueHsiJeI ront / M1 rear / M1 !
void main(
{ int Etem res ! char ch/00 !
clrscr( !
hile ( ch //00 55 ch // 060
{ cout << '-n 7nter EG7D or insertion : ' !
cin >> Etem !
res / Ensert(TueueEtem !
i (res // M1
{ cout << 'U7+SLLL bortin$LL -n' !eKit(1 ! &
cout << '-n Oo the Tueue (+ront...to...ear is : -n' !
Bispla(Tueue ront rear !
cout << '-n ant to insert more elements= ("n...' !
cin >> ch !
&
;C
8/9/2019 Computer programs(20)
http://slidepdf.com/reader/full/computer-programs20 60/70
cout << 'Oo deletion o elements be$ins...-n' !
ch / 00 !
hile ( ch // 00 55 ch // 060
{ res / emove(Tueue !
i (res // M1
{ cout << 'QOB7+SLLL bortin$LL -n' ! eKit(1 ! &
else
{ cout << '-n7lement deleted is : ' << res << endl !
cout << 'Oo the Tueue( +ront...to...ear is : -n' !
Bispla(Tueue ront rear !
&
cout << 'ant to delete more elements= ("n...' !
cin >> ch !
&
&
int Ensert(int TueueHI int ele
{ i ( rear // siJe M1 return M1 !
else i ( rear // M1
{ ront / rear / !
TueueHrearI / ele !
&
else
{ rear,, !
8/9/2019 Computer programs(20)
http://slidepdf.com/reader/full/computer-programs20 61/70
TueueHrearI / ele !
&
return !
&
int emove( int TueueHI
{ int ret !
i ( ront // M1 return M1 !
else
{ ret / TueueHrontI !
i ( ront // rear ront / rear / M1 !
else ront,, !&
return ret !&
void Bispla(int TueueHI int ront int rear
{ i ( ront // M1 return !
or( int i / ront ! i < rear ! i,,
cout << TueueHiI << ' <M -t' !
cout << TueueHrearI << endl !
&
1
8/9/2019 Computer programs(20)
http://slidepdf.com/reader/full/computer-programs20 62/70
2
8/9/2019 Computer programs(20)
http://slidepdf.com/reader/full/computer-programs20 63/70
12. Perform p'sh an) pop operation in lin9e) /'e'e
#include<iostream.h>
#include<process.h>
#include<conio.h>
struct Oode { int ino !
Oode * neKt !
& *ront *neptr *save *ptr *rear !
Oode * )reatePOePOode( int !
void Ensert( Oode* !
void Bispla( Oode* !
void delOodePT( !
void main(
{ ront / rear / OQSS !
int in ! char ch / 00 !
hile ( ch // 00 55 ch // 060
{
cout << '-n 7nter EO+rmation or the ne node...' !
cin >> in !
neptr / )reatePOePOode( in !
i ( neptr // OQSS
{ cout << '-n)annot create ne nodeLLL bortin$LL-n' !eKit(1 ! &
Ensert ( neptr !
3
8/9/2019 Computer programs(20)
http://slidepdf.com/reader/full/computer-programs20 64/70
cout<< '-n Rress 6 to enter more nodes O to eKit...-n' !
cin >> ch !
&
clrscr( !
do
{ cout << '-n Ghe Sin8ed Tueue no is ( +ront...to...ear : -n' !
Bispla( ront !
cout << 'ant to delete frst node= ("n...' !
cin >> ch !
i ( ch // 00 55 ch // 060
delOodePT( !
& hile ( ch // 00 55 ch // 060 !
&
Oode * )reatePOePOode( int n
{ ptr / ne Oode !
ptr M> ino / n ! ptr M> neKt / OQSS !
return ptr !
&
void Ensert( Oode* np
{ i ( ront // OQSS { ront / rear / np ! &
else
{ rear M> neKt / np ! rear / np ! &
&
4
8/9/2019 Computer programs(20)
http://slidepdf.com/reader/full/computer-programs20 65/70
void delOodePT(
{ i ( ront // OQSS cout << ' QOB7+S LLL-n ' !
else
{ ptr / ront !
ront / ront M> neKt !
delete ptr !
&
&
void Bispla( Oode* np
{ hile ( np L/ OQSS
{ cout << np M> ino << ' M> ' !
np / np M> neKt !
&
cout << 'LLL-n' !
&
;
8/9/2019 Computer programs(20)
http://slidepdf.com/reader/full/computer-programs20 66/70
8/9/2019 Computer programs(20)
http://slidepdf.com/reader/full/computer-programs20 67/70
3. S:8 :'eries
@
8/9/2019 Computer programs(20)
http://slidepdf.com/reader/full/computer-programs20 68/70
A
8/9/2019 Computer programs(20)
http://slidepdf.com/reader/full/computer-programs20 69/70
C
8/9/2019 Computer programs(20)
http://slidepdf.com/reader/full/computer-programs20 70/70