Download - 40 programs of c++
-
7/25/2019 40 programs of c++
1/78
PROGRAM TO CHECK IF STRING IS
PALINDROM OR NOT:
#include#include
void main()
{
clrscr();
intn,num,digit,rev=0;
coutnum;
n=num;
do
{
digit=num0;
rev=(rev*0)+digit;
num=num0;
-
hile(num/=0);
cout
-
7/25/2019 40 programs of c++
2/78
PROGRAM FOR FACTORIAL USING
RECURSION:
#include
#include
int rec(int);
void main()
{
clrscr();
intn,1act;
coutn;
1act=rec(n);
cout
-
7/25/2019 40 programs of c++
3/78
-
82'
FUNCTION OVERLOADING:
#include
#include
#include
?oat area(?oat a,?oat !,?oat c)
{
?oats,ar;
s=(a+!+c)$;
ar=s@rt(s*(sa)*(s!)*(sc));
return ar;
-
?oat area (?oat a,?oat !){
return a*!;
-
?oat area (?oat a)
{
return a*a;
-
void main()
{
clrscr();
int choice, s,s$,s,ar;
do
-
7/25/2019 40 programs of c++
4/78
{
cout
-
7/25/2019 40 programs of c++
5/78
-
82'
-
7/25/2019 40 programs of c++
6/78
SERIES: (1+1/2+1/3+1/4 .1/n:
#include
#include
?oat series(?oat);
void main()
{
clrscr();
?oatn,s;
coutn;
s=series(n);
cout
-
7/25/2019 40 programs of c++
7/78
82'
SERIES:(1+(1!2+(1+2+3:
#include
#include
?oat sum(int);
void main()
{
clrscr();
?oatn,;
coutn;
=sum(n);
cout
-
7/25/2019 40 programs of c++
8/78
82'
CLASSES AND O"#ECT:
#include
#include
#include
class student{
introllno;
char nameE$0F;
chardo!E0F;
?oat ercent;
u!lic'
voidreaddata()
{
coutrollno;
cout
-
7/25/2019 40 programs of c++
9/78
cout
-
7/25/2019 40 programs of c++
10/78
PROGRAM TO S$AP VALUES (CALL "%
REFERENCE:
#include
#include
int main()
{
void sa(intC,intC);
int a,!;
couta>>!;
cout coutvoid sa(intC,intC)
{
int tem;
tem=; =;
=tem;
cout
-
7/25/2019 40 programs of c++
11/78
-
82'
PROGRAM TO S$AP T$O NUM"ERS(CALL "%
VALUE:
#include
#include
int sa(int,int);
void main()
{
inta,!;
cin>>a>>!;
cout cout-
int sa(int,int )
{
int tem;
tem=;
=;
=tem;
cout
-
7/25/2019 40 programs of c++
12/78
return 0;
-
82'
LINEAR SEARCH:
#include
#include
Int lsearch(intE F,int,int);
void main()
{
clrscr();
int arEG0F,item,n,inde;
coutn;
cout
-
7/25/2019 40 programs of c++
13/78
cout
-
7/25/2019 40 programs of c++
14/78
"INAR% SEARCH:
#include
#include
int !search(intE F,int,int);
void main()
{
clrscr();
int arEG0F,item,n,inde;
coutn;
cout
-
7/25/2019 40 programs of c++
15/78
cout
-
7/25/2019 40 programs of c++
16/78
SELECTION SORT IN ARRA%:
#include
#include
voidselsort(intE F,int);
void main()
{ clrscr();
intarEG0F,item,n,inde;
coutn;
cout
-
7/25/2019 40 programs of c++
17/78
getch();
-
voidselsort (intarE F,int siHe)
{
int small ,os,tm;
1or(inti=0;i
-
7/25/2019 40 programs of c++
18/78
"U""LE SORT IN ARRA%:
#include
#include
void !u!!lesort(int E F,int);
void main()
{
clrscr();
int 37EG0F,Item,5,inde;
cout5;
cout
-
7/25/2019 40 programs of c++
19/78
cin>>37EiF;
!u!!lesort(37,5);
cout
-
7/25/2019 40 programs of c++
20/78
-
82'
INSERTION SORT IN ARRA%:
#include
#include
#include
void Insort(int E F,int);
void main()
{
clrscr();
int 37EG0F,Item,5,inde;
cout5;
cout
-
7/25/2019 40 programs of c++
21/78
cin>>37EiF;
Insort(37,5);
cout
-
7/25/2019 40 programs of c++
22/78
-
o'
MERGING OF ARRA%:
#include
#include
void merge(int 3EF,int m,int NEF, int n,int OEF){
int a,!,c;
1or(a=0,!=,c=0;a
-
7/25/2019 40 programs of c++
23/78
OEc++F=NE!F;
-
-
i1(a
-
7/25/2019 40 programs of c++
24/78
cin>>3EiF;
-
coutn;
mn=m+n;
cout
-
7/25/2019 40 programs of c++
25/78
-
7/25/2019 40 programs of c++
26/78
-
-;
class erimeter
{
?oat er;
u!lic'
void calM(?oat a,?oat !)
{
er=$*(a+!);
cout
-
7/25/2019 40 programs of c++
27/78
cin>>a>>!;
r.calMa(a,!);
r.calM(a,!);
r.sho();
getch();
-
82'
INHERITANCE (MULTILEVEL:
#include
#include
#include
#include
class erson
{
char nameE$GF;
char do!EGF;
char addressEQ0F;
u!lic'
void getdata();
-
7/25/2019 40 programs of c++
28/78
void shodata();
-;
void erson''getdata()
{
cout
-
7/25/2019 40 programs of c++
29/78
-;
void student''get()
{
coutrollno;
coutercentage;
-
void student''disla()
{
cout
-
7/25/2019 40 programs of c++
30/78
INHERITANCE (MULTIPLE:
#include
#include
class area
{
u!lic'
void a(?oat ,?oat @);
-;
void area''a(?oat ,?oat @)
{
cout
-
7/25/2019 40 programs of c++
31/78
u!lic'
void (?oat ,?oat );
-;
void erimeter''(?oat ,?oat )
{
cout
-
7/25/2019 40 programs of c++
32/78
-
82'
INHERITANCE (MULTILEVEL:
#include
#include
#include
class erson
{
char nameE0F;
char do!E$GF;
u!lic'
void getdata();
void shodata();
-;
void erson''getdata()
{
cout
-
7/25/2019 40 programs of c++
33/78
gets(name);
cout
-
7/25/2019 40 programs of c++
34/78
coutercent;
-
void student''shodata$()
{
cout
-
7/25/2019 40 programs of c++
35/78
cout
-
7/25/2019 40 programs of c++
36/78
INHERITANCE (HEIRACHIAL:
#include
#include
#include
class erson
{
char nameE0F;
char do!E$GF;
u!lic'
void getdata();
void shodata();
-;
void erson''getdata()
{
-
7/25/2019 40 programs of c++
37/78
cout
-
7/25/2019 40 programs of c++
38/78
cin>>rollno;
coutercent;
-
void student''shodata$()
{
cout
-
7/25/2019 40 programs of c++
39/78
{
cout
-
7/25/2019 40 programs of c++
40/78
INHERITANCE (H%"RID:
#include
#include
#include
class erson
{
char nameE0F;
char do!E$GF;
u!lic'
void getdata()
{
cout
-
7/25/2019 40 programs of c++
41/78
void shodata()
{
cout
-
7/25/2019 40 programs of c++
42/78
shodata();
cout
-
7/25/2019 40 programs of c++
43/78
-;
class sorts'u!lic student,u!lic emloee
{
char gameE0F;
int age;
u!lic'
void getdataA()
{
cout
-
7/25/2019 40 programs of c++
44/78
s.getdataA();
cout
-
7/25/2019 40 programs of c++
45/78
FILE HANDLING (MEMOR% TO FILE:
#include
#include
int main()
{ o1stream Plout;
Plout.oen("marBs.dat",ios''out);
char ans=SS;
int rollno; ?oat marBs;
hile(ans==SSTTans==SJS)
{ coutrollno;
coutmarBs;
Plout
-
7/25/2019 40 programs of c++
46/78
-
82'
FILE HANDLING (FILE TO MEMOR%:
#include
#include
#include
#include
void main()
{
clrscr();
o1stream 1out("student",ios''out);
char nameE0F,ch;
?oat marBs=0.0;
4oo to get G records
1or (int i=0;i
-
7/25/2019 40 programs of c++
47/78
cin>>marBs; cin.get(ch);
1out
-
7/25/2019 40 programs of c++
48/78
STAC IMPLEMENTATION USINGARRA%:
#include
#include
#include
const int ma=0;
int stacBEmaF;
int to=,item;
void 6isla()
{
int i;
i1(to==)
{
cout
-
7/25/2019 40 programs of c++
49/78
else
{
1or(i=to;i>=0;i)
{
cout
-
7/25/2019 40 programs of c++
50/78
getch();
-
void 2o()
{
i1(to==)
{
cout
-
7/25/2019 40 programs of c++
51/78
cout
-
7/25/2019 40 programs of c++
52/78
getch();
-
82'
STAC IMPLEMENTATION USING LINK LIST :
#include
#include
#include
struct node
{
int in1o;
node *net;
-*to,*ntr,*save,*tr;
node * neMnode(int n)
{
tr=ne node ;
tr>in1o=n;
tr>net=5V44;
return tr;
-
void ush(node *n)
-
7/25/2019 40 programs of c++
53/78
{
i1(to==5V44)
to=n;
else
{
save=to; to=n;
n> net=save;
-
-
void o()
{
i1(to==5V44)
cout
-
7/25/2019 40 programs of c++
54/78
n=n>net;
-
cout
-
7/25/2019 40 programs of c++
55/78
do
{
cout
-
7/25/2019 40 programs of c++
56/78
&UEUE IMPLEMENTATION USING ARRA%:
#include
#include
#include
const int siHe=0;
int WueueEsiHeF;
int rear=,1ront=,item;
void 6isla()
{ clrscr();
int i;
i1(1ront==) cout
-
7/25/2019 40 programs of c++
57/78
{
i1(rear==siHe)
cout
-
7/25/2019 40 programs of c++
58/78
1ront=,rear=;
else
1ront=1ront+;
cout
-
7/25/2019 40 programs of c++
59/78
!reaB;
case $'
6elete();
!reaB;
case '
6isla();
!reaB;
case A'
eit(0);
de1ault'
cout
-
7/25/2019 40 programs of c++
60/78
&UEUE IMPLEMENTATION USING LINK LIST:
#include
#include
#include
struct node
{
int in1o;
node *net;
-*1ront,*ntr,*save,*tr,*rear;
node * neMnode(int n)
{
tr=ne node ;tr>in1o=n;
tr>net=5V44;
return tr;
-
7/25/2019 40 programs of c++
61/78
-
void insert(node *n)
{
i1(1ront==5V44)
{ 1ront=rear=n;-
else
{
rear> net=n;
rear=n;
-
-
void del()
{
i1(1ront==5V44)
cout
-
7/25/2019 40 programs of c++
62/78
{
cout
-
7/25/2019 40 programs of c++
63/78
clrscr();
do
{
cout
-
7/25/2019 40 programs of c++
64/78
CIRCULAR &UEUE:
#include
#include
const int siHe=G;
int WueueEsiHeF;
int rear=,1ront=,item;
void 6isla()
{
int i;
i1(1ront==)
cout
-
7/25/2019 40 programs of c++
65/78
-
7/25/2019 40 programs of c++
66/78
-
-
void 6elete()
{
i1(1ront==)
cout
-
7/25/2019 40 programs of c++
67/78
cout
-
7/25/2019 40 programs of c++
68/78
-
82'
-
7/25/2019 40 programs of c++
69/78
STRUCTURE PROGRAM:
#include
#include
#include
struct student
{
int rollno ;
char nameE$F ;
?oat marBs EGF ;
char grade ;
- ;
student learner ;
void main()
{
cout
-
7/25/2019 40 programs of c++
70/78
1or(int i=0; i
-
7/25/2019 40 programs of c++
71/78
82'
-
7/25/2019 40 programs of c++
72/78
3773J 8X 8NY:O'
#include
#include
class Item
{
int itemno;
?oat rice;
u!lic'
void getdata(int i,?oat D)
{
itemno=i;
rice=D;
-
void utdata(void)
{
cout
-
7/25/2019 40 programs of c++
73/78
const int siHe=;
Item orderEsiHeF;
void main()
{
clrscr();
int ino;
?oat cost;
1or(int a=0;a
-
7/25/2019 40 programs of c++
74/78
M%S&L:
Oreating a!le ZXurniture[
6escri!ing a!le
electing all values 1rom a!le
-
7/25/2019 40 programs of c++
75/78
Oreating 3nother a!le Z3rrivals[
Inserting values in a!le
6escri!ing a!le
electing all values 1rom a!le
-
7/25/2019 40 programs of c++
76/78
&UERIES:
a) electing all values 1rom Xurniture here e=Na! cot!) electing Item name 1rom Xurniture here 2rice > G000
-
7/25/2019 40 programs of c++
77/78
c) electing Item name, e 1rom Xurniture here 6ate o1 tocB $G
e) Oounting the num!er o1 Items, hose e is o1a 1rom
Xurniture.1) Inserting a ne ro in the 3rrivals a!le
-
7/25/2019 40 programs of c++
78/78