0% found this document useful (0 votes)
9 views

C++ PROGRAMS

Uploaded by

Sunita Desai
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

C++ PROGRAMS

Uploaded by

Sunita Desai
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

Date %/14 Expt No. 03 Page No.

Wu a
program to Hind the trequtny
an element in an

#inudu<iostrcam.hs
#in dude < conio. h
#incd <iDmanip:h
clas ytqny
privat : int o, alioo],i, cle, 7rca,
public void input0j
void jinayquenyOj
void disployO)
void 4rcquny :: inputt)
cout ee Entur the anay5i3 )
cin>0;
cout e" Entu the aHay elemento'eendy,
7or Cieoj isn,itt)
cin> aCi;
Cout << Ente thc sarh elemet;
cin> ele

Teacher's Signature
Page No.
Date:4/611 Expt No.

void

toY Ci0; i<n, itt)


(aci)=- ele)

3
void trquony ti display)

elpc
cout ee Element dos not eust';
Yoid main C)

f inputcj
t findycaunyc);
f. oisplay)

Teacher's Signature_
Output
Entr the array sIB
Entr the anray dements
22 H 35 2 2
Entor he starch demtnt

Frequeny of a is Htims
Date/b/A9 Expt No. OH Page No.

write a þrogram toto inst an clement in


arnay
in cuu io sream.hs
#incuou <conio.h>
#incudu<iomanip.h>
#indude <procesS h>
class i b t

prívatt : int a, al u90), i, clc, pos;


publie:
Void inputt);
void nscrtiont);.
void di_play)
vOd insut i: input )
cot e<" Entu tht size o arrayj
cins nj
tout<e" Entou the anHay cltmena" <eendl;
7orCièoj iznj it)
Cin >> a CiJ;
Cout <e Entu an etement to inst;
Cin> ele
cout<e Entu the position'
cinzposj
Teacher's Signature_
Page No. 1D
Date:Ubn9 Expt No.

void insUt:: inseytion )

cout <'pos "is an invalidposibisn';


Cxit(o))
else
S
tor (ien-j iposj i )
alit]= alili
a oil ele;

Yod insot ' displayl)


cOut<"Reultant avay endl,.
or Cis0, isn) itt)
out ee setwcs) aliJ;
Void mainc)
inscrt bj
b. input))
b.1ertient
b.
Teacher's Signature_
Out put
Entor the
Entu
kntr the
5 |0
array eltmnla
15 20
Enter an elemnt to bt insrted

Entu the psition

Resutant anay
05 10 15 20
Signature Teacher's 4(posn-i)
deletgnt du Yoid
posj cin>>
2")": to'positionlo
<e the Entu COutee
CIj Cin>>a
en'<e
tnal: n: Cis0, or
clemenz" the Enter
Cowt"
s13j aay th
Entr LOute
imputt del Void
displayoj void
C)delci
inputO} on VDId.
void
publii
begi miposyh,
l, clk, C100,i, an,int privatt:
del class
procss.hs udu
< #in
anip.h <iom cdudu tin
conio.
h> cudu< #ìn
<iostcam.h #1ncudu
in
programpes0Hen given
Qn
7rom clemnt andelcu to Wraiu
I| No. Page 05 No. Expt b/9Date:4/
Page No. l2
Date:y/b/|9 Expt No.

tout <«poS <e" ip an invalid positien" 44tndly


exit(o);
clse

ele aCpBs];
tor Cie posy ien, it+)
al]= aCitJ

Cout e" Element"ele< o suecshuly.


umond from pesition pos ucnouj
void del :: display(O
cOut <endl ee "A;tt delctisn the arrcuy is'tnd
tor (io) ien t )
cotee setw(s<4 ari;.
void ma in C)

del dj
d. input ;
di deletionOj

Teacher's Signature
Outpul
Entr the
3
array oB
Enter the aray
2
clemnb

kntu the þosition (o to 2)


3 I6
Succasbully remomd
rcmowd trom position 2
A7tr deletion tht -array s
Expt No. Ob
Page No. 13
Datets/b A9

Writt a program to sort Altmero o an anay


in ascen díng oruorde
#in du du <ioshcam.h
##in cucu<conio. h>
tin cuu< iomanip-h>
class sort

rivatt : int o,ja.Cio ol;


void inputU)
void sorting )j
void disploay)
void sort i input )
cout ee" Entuu th away s3 )
cin >>n;
cout ee "Entor the aw ay elementp"eeendy
tor Ci=oj ien, itt)
Cin>> aliJ;
void sort sorting ()
!

int t, j i<njt+)
hor (ie;

Teacher's Signature
Page No. Ju
Date: /b/4 Expt No.

while Cj>=)

t- alj];
aj aci-D;
aj-i] t;

void sort display)

cout <<endl <«'An aay aftuu 4orting" z4 endj


tor Ci-oj i<nj itt)
Cout 6etwc5) << ali];

void main ()
Sort 6j

Ssinput );
6. 6ortingC
$. di_plascy
gctch)s

Teacher's Signature
Outpul
kntr the
H aray siz
Kntcr the aray elenento
70 50 60 100
An
50 array
60 7o
ater 6orting
Page No. 15
Date:4/619 Expt No. D

Writ a program to sarch for aa givcn


eltment in n aay using binay sarch
method

#incude <iostream.h
#inude <conio.h
#ineude <iomanip.h>
class seanch

privatt : int aCioo], n, ele, oc, i;


publie :
void inputO}
yoid bin_starch
Void display cOj
Void Searchi! input()
cout ee'Entee the size oh the aay"j
cin> n;
ot ee" Entu the arnay eltmnts'aetnalj
for Li=o) ianj itr)
Lin» a CiJ;
cout ee Entw th sanh elemcnt <<endly
cin> cley
vojd 6eanch bin scarchl)

int bg og , end= n-i1, midj


Teacher's Signature
Date:l/b19 Expt No. Page No.lb

ohile Lbeq<= cnd)


mid = Cotq +end)l2 j
i Cele == almia] )

loc midj
brtakj
dseiCele< aCmia])
end = Mid-L;

btq mid tl;

void search !!
displayc)
i, Cloc=o)
LOut < ele <eL1s5 n position' loc 24
endli

cOut << ele <" Elerment dos not eziss"


3
voi d main (

Starchbj

Teacher's Signature
Date:4/b/9 Expt No. Page No. 1

b.inputy
b. bin-sLarch LJj
b. aisplay C)
gctchc)j
Outpu
Enter the aray size
s'3
Enter the array clement
|35 7
Enter the sear ch element
7 e2iss in positi on 3.

You might also like