Adobe Scan 1 Nov 2023
Adobe Scan 1 Nov 2023
{
r11 h frequency fl;
Cla fi-l 'jU< n, Y clrscr();
void find(); }
void putrl.a ta( ) ,
}; Output 1: Output 2:
void frequency:: get.data(} Enter the size of the array Enter the size of the array
5 5
{
Enn,r the array elements Enn,r the array elements
cout<<' Enter the size of the array" «end!;
-1 1
cin>>n;
cout<<" Enn,r the array elements" <<end!; 23 2
783 3
for( int i=O; i<n; i++)
-1 4
cin»a[i];
coul<<" Enn,r the search element" <<end!; 2 4
il(a[i]==ele) #include<conio.h>
f++; #include<process.h>
#include<iornanip.h>
?
void frequency:: putdata()
class insertion
ii( f>O) {
cout<<" Frequency of • <<ele<<" is • <<f<<endl; int I\ a [1001 ele, p;
cout<<" The array a fter Inser ti on is"<<endl;
cout«setw( 4) «a (I);
void main( )
lnserdon i;
Ul Enter th numb< r ol I ment. < cndl ;
clrscr();
Jn n.
l.getdati( );
, ,urn" llnltr I.he arr.iy , lcrn:nr • <<: 11dl,
I.Insert();
, ..
for(lnt 1=0, l<n; l++J
cln>--a(IJ; f.putdata( ),
5
void insertion:: lnserl() Enter the array elements
1
11(p>n II p<0) 2
3
cout<<p<<" is an Invalid position" <<endl; 4
getch[ ); 5
exit(O); Enter the element to be inserted
6
else Enter the position from Oto 5
0
for (int i=n-1; i>=p; i-) 6 is successfully inserted
aP+l]=ap]; The array after inserti on is
a(p)=ele; 612345
n=n+l;
cout<<ele<<" is success fully inserted" <<end!; 3) Write a C++ program to delete ai element from ai array from given pos~lai .
#i nclude <iostreamh>
#i nclude<conio.h>
void insertion:: putdata( J
#i nclude<iomanip.h>
void deletion :: putda ta[ )
I l for(i=0;i<n;i++)
\I 1 l iY: { ), cout«setw( 4) <<a [I];
vc.. l r ,td:Jt:,( J,
void main( )
3
cout<<p<<" is an invalid position" <<endJ; 4
gett;h( ), 5
exit(0);
Enter the position from Oto 4
4
else
The element 5 at position 4 is successfully removed
The array after deletion is
1 2 3 4
cle=a[p];
for(i=p; i<n; i++)
4) Write a C++ program to sort the elements of an array in ascending orderusblg tisertlon sort.
a[i)=a[t+l);
#include<ios tream h>
n=n-1;
#include<conio.h>
cout<<" The element "<<ele<<" at position • <<p<<" ts successfully removed" «end!;
#include<iomanlp. h>
}
class sorting
H
void main( )
U I
sordng s;
void rn IJnl! 1 1J..t,1 ) clrscr( ) ;
s.gerda ta( );
cou1,<"Ent, 1 th ~"mb 1 rifclrmc'nlS"<<cndl, ssorl( );
cm>>n; s.putda ta( ) ;
...
cout<,... Pntcr the "r 1y, It me nts" <<cndl, gelX:h( );
for(lnt 1-0,l<n;I+ ➔)
cln»a(l]; Output 1.
EntEr the number of elements
void sorting:· puldata( ) 5
{ ' Enter the array elements
cout<<"The array after sorting is" <<endl, -999
for(lnl l=O;i<n;i++) 0
cout«sctw( 4) «a (I]; -23
6
5) Wrte a C++ program to search/or a given element ti ai array usrig bin rry search method
j=i; #include<iostreamh>
while(j>=l) #lnclude<eonio.h>
class binarysearch
il(aOJ<aO-lD
int a[100), n, ele, loc;
temp=aO); public:
void putrlata( );
else
Id)
b mid+l;
C
fo lint 1 0 vndl;
n, l+t)
cln>, I•). void main( )
b.getdata( ) ;
void blnarysearch :· putda1a( )
b.search( ) ;
{
b.putx:lata( );
il(loc >= O) getch( ),
mid= (b + e)/2;
ii( ele =a[mldD 6) Wr.i'.e a C++ program to create a class with data members principle, timeimdrate. 0-eatemmiber
fan ct ions to acce~ da:a vahJes tocomµitcstmple mterest mdto display the resut.
#include<iostreamh>
loc = mid;
#include<conio.h>
break;
class interest
else
private:
If{ ele<a[midD
double p, t r, sl;
e = mid-1; public:
Time: 3
Rote: as
Simple lncerest 2550
7) Write a c++ program to create a class with data members a, 4 c ondmember Jindlonstolnput dat."
c0t11pitet he dfscrimln ant based on lhe following conditions and print the root.s
1/lncludc<conlo. h>
void main( J };
interest i;
i.getdata( );
i.compute( ) ;
. cin>>a>>b>>c;
getch( ); {
x=b•b-4•a•c;
Output 1: if(x=O)
8) Wrf:e a C++ program to fin dthe area of a scp are, rectm g/e, trlmgle using jirnalan overlaadlng.
dll r r, ndl,
lllnclude<lostreamh>
/(Z' J.
1/lnclude<eonlo.h>
1. I b rt J , / ( l! ).
lllnclude<math.h>
class funoverload
C
floats;
cout<<" Roots are um gt nary" «e ndl; public:
getrh( ); double area( double a)
exit( OJ ;
return a*a:
void quadratic :: put.data( )
{
quadratic q; s ={a+b-+c)/20;
q.getdata( );
q.calcula te( ) ; };
gell:h( ); {
double x, y, z;
Enter three co-efficients Enter three co-efficients Enter three co-efficients funoverload f;
1 1 2 clrscr( );
Roots are imaginary Roots are equal Roots are positive and different cout<<" 3. lrlangle" «end!;
In
""· Ill nc lud,•<los trea m h>
1/lndudr.<conlo.h>
•ut Ar , r,J lh · ,11~,rr <<[drva(xJ< cndl,
If[ ans,,:2)
rclurn(a•o'a);
#include<math.h>
Output l; #include<eonio.h>
lSquare class series
2. Rectangle
3.lrlangle Int x, n. sum;
Enrer your choice public:
3
serles(int b, Int p)
Enrer three sides
4
x=b;
3
n=p;
cL1ss student
private:
Int x. n;
void putda ta( )
clrscr( );
cout<<" Enter the value for x' <<endl; cout<<" Foll number=" <<rollno<<endl;
cin>>x;
cout<<" Narre=" <<na me<<endf;
cout<<" Enter the value for n• <<endl;
cin>>n;
);
series s(x. n);
class rrarks : public sb.Jdent
series sl=s;
total=ml+m2;
11) Wri'.e aC++programtocrea:ea baseclasscontcmtigthe da:am embers roll num ber ai dnam e.Also
void print( )
crea:e a member jlnctlon to read a,1 d display the da:austzgthe caice,t: ofsingle in hertaice. lreate a
derived class thee ccntalnsmarks oftwo subjects at1 dt«al marks as the data members.
#fnc!ude<iostreamh>
cout<<"Subjectl marks ='<<ml<<endl;
#fnclude<conlo.h>
cout<<"Subject2 marks :c"<<m2«endl;
I!,
noat fees;
public:
void getdata();
void put.data( );
};
, Ir , , ( void student :: get.data( )
m td:!t.1[ J.
nu id( J, cout<<" Enter student register number" «end!;
cln>>regno;
niputd.1m( );
cout<<" l!nter student name" <<endl;
rnpr!nt( ),
cln>>name;
gelCh( J;
cout<<" Enter student fees" <<endl;
cln>>fees;
Output 1:
sp->getxlata( );
1Z) Wrte a C++ program tocrer1e a class contain ingthe following data members register number, name sp->putda ta( ) ;
an dfees.Al5ocreate a member junction to read and display the datausingtheconcefL ofpointersto
getch( );
#include<iastreamh>
Output!:
#include<conio.h>
Enter student register number
class student
161001
13)
-- --- - --------- ----- ---~----------------
Wrte a C++ pronram to per/om, Pl/SH operutJo,, a,, t11ck
#inciude<1Clf.tream.h,. ----------------------------
for( Int , .. o. c<■ r,:,p; c <-+)
cout<<a (c )<<"
cout<:<endl;
•;
lt1nclude<con10. h>
llinclude<process.h>
else
#include<ctype. h> cout<<"Stick Is empty• <<eTicil;
#define MAX 5
class stack. );
void rmin( J
int a[MAX);
mt top; stack s;
clrscr( );
char choice;
char choice;
public:
int elc;
stack( )
s.prinl( );
cout<<"Doyouw.inttopushanltem( Y/N)? •
top=-1;
cln>>cholcc;
top++;
a[top)=ltem; Output
l ls pushed
MIIIDPE'fltP'P!PYfffl'fffW«fRl«IW«rWltrfMmOe<ecvcz Ill Q
void push(lnt Item)
D 111,1~/Nl'Y
else
14) Wrte a C++ program to POP elements /i-cxn the stack
cout<<"Stack is empty''<<endl;
#include<iastreamb>
#include<conio.h>
void pop( )
llinclude<ct;ype.h> ,
#define MAX 5
if( top==-1)
class stack
{
public:
else
stack( )
Int data=a[top];
top=l;
top-;
s.irint( ); f=O;
s.pop( ); r=O;
• S.Jrint( );
};
gerrh( );
void queue:: enqueue(lnt x)
Output:
Stack contains -1 -2
r++;
-3 is pushed
q(r)=x;
Stack contains ·1 -2 -3
-3 is popped cout«endl«q[r)«" is inserted' «endl;
Stack contains ·1 -2
-2 ls popped
void queue :: dequeue( )
Stack contains ·1
-1 ls popped
lf(r=O)
nrns e eze
ql.dlsplay( );
ql.dequeue( );
ql.dlsplay( );
qt.dequeue( );
ql.dlsploy( );
f 0,
gctch( );
r fl;
else
Output
f++;
Que uc under now
eJe=qff); 3 ls lnserll.!d
Queue contains: 3
cout<<endl<<ele<<" is deleted" <<end!;
4 ls Jnscrted
11{r=()
Queue contains: 3 4 5
3 ls deleted
cout<<"Queue underflow "<<end!;
Queue contains: 4 5
else
4 ls deleted
• cout<<"Queue contains: ·;
Queue contains: 5
for(int i=f+l; l<=r; i++)
5 is deleted
cout«setw( 4) «qp];
Queue underflow
void main( J
16) Wr.te a C++ prooram to create a linked list and appending nodes.
#include<iostreamh>
queue ql;
#include<conio.h>
clrsa( );
class linklist
qldJsplay( );
qlenqueue(3);
struct node
qldisplay( );
ql.enqueue( 4);
int data;
qldisplay( );
node •link;
q lenqueue( 5);
}•start;
qldisplay( );
public:
ql.dequeue{ );
llnklis I( ) ;
riumJ cout<<endl<<num<<" Is inserted as the first node"<<endl;
nt[ )
else
II 11 ti I r>1 11 it l
lf(star~=NU LL)
{
void llnkllst :: count( )
cout<<" Linked list is empty" <<endl;
relllrn;
node •temp;
int c=O;
cout<<" Linked list contains" <<endl;
for(temp=start; ll!mp!=NULL; ll!mp=temp->link)
node • temp=astart;
c++;
while(temp!=NULL)
cout<<endl<<"Number of nodes in the linked list:'°<<c<<endl;
{
ohj->apµend( 100);
void linklist :: append( int num)
,1h1->print( ) ;
001 ->count( ) ;
node •nnode;
ohj•>append( 200);
nnode=new node;
ob1->print( ) ;
nnode->da ta=num;
obj->count( );
nnodc->link=NU LL;
obj->a ppcnd( 300);
obj->print( );
ll[start==NULL)
obj->count( );
{
getr:h( );
start= nnode;
For more than 100 uni IS Rs 5.50/ unit
6) Com puted ueda teas bill dat~ lS
days
7) Llsl all the bills gener ated
I I l d I• ' •r H
ll/11 Solution
1) Command tocre ateta ble
N "'"" 1 ·I n"d Ir, Lil h,d d If trl
lOOI ln,,rt cd create table ebill
l) bser t 10 recor ds lntoth etal.J le. nsert 1:,tn 1'bill ,,alu ·s('a4 567',' Appu rao','1 2-ma r-201
6',12 0);
3) <hec k the struc ture ofthe tahle . l ro·At~l inser ted
4) Add the following field stoth etabl
e
Field name Data t e inser t into ebill value s('c21 21','R
Bill amou nt aghu' ,'12-m ar-20 16',63 1);
float
Due date 1 row(s ) inser ted
date
inser t into ebill value s('a45 32','R
ani,'1 2-ma r-201 6',13 1);
S) Com putet hebil l amou nt for each
custo mer aspe r follow ing rules 1 row(s ) inser ted
Minim umam ount: Rs 50
✓
a453 2
c235 6
-
Ram
Mura li
-- -~ -
-~ -
12-M AR-1 6
12-M AR~1 6
131
"·
670.5
o.,.
20
✓
~
b876 5
..
~
Sriha ri 12-M AR-1 6
~ - ..,. 516
673
2788
3651 .5
27-M A
✓ 27-M
Numti. r c625 3 Nara yana 12-M AR-1 6 90 455
✓ gopa la 27- -
~---'---------------'--2425
- ; 2 ._M_A
-- -
b876 3 _._
- . . 27•M O__ j
R.:_1_6 __- -
I 1 ll t tf fll<k71t5 who have percc11togc orculer l/11a1 60. insert into student values(1102,'harish',89,34,54,4S,53,67);
14/ ort t/11: t o/,/c occord1J1otothc ore/er ofstudc11t ID. 1 row(s) Inserted
Soiul1011 Insert Into student values( 1104,' mahesh',56,43,89, 75, 93, 78];
1 J Command to create a table
1 row(s) inserted
crca11:- !able student
nse1 r in t • e
~ ~•·- ✓
SJ Commmaod tocaJculateta:almarks.
insert Into student values( 1134,'Hari', 99, 98, 99, 97, 91, 90); update srudent set total= physics+ chemistry+ mathematics• computer ..,science+ kannada + engllsh
1 row(s) Inserted 10 row(s) updated
lat p cnt111e
lntal/6.0,
8} Gomm a
nd
lo computer theresul as 'fall' by checking lfthestudmtbas scored less than 35 marlcs In
any oncsuhjc<.1.
!]
~
~
- 71
...z......_ _ _ _ _ _
5'
il
--
i~
--
!;,!
~El
[]
--- -
~
: ll!i . al',. 61 13 ~ ~
;-
H m :1: fa
I
I 11)~ R3ll 'r
t, .,
1·
-~ •'
;, [j r; 33:' :6,5 im 13) commaidto fist the students w/10 have resut as 'fall'
'1!6 Ve.', 61 .,, ..'• aa .cl~ct · irt•Mstudent where result='fail'
1131 Hai
.
:.. ~s f'
..
.--- -~
!1BJ ~H bi
-·-·-· ,..f~~ ~:..,.-
·\112 -~ ~3 ' l4 ,, 5-1. !5 :J fl 321 ill
llll rl &5 34 54 '5 5l 61, l11 , m fa?
College address:
!contact number:
IE-mail :
II
I
- :: .J I
i; Submit I~eset ] I Cance~] I