You are on page 1of 11

rogram for rlme number CeneraLlon

#lnclude sLdloh
maln()

lnL nl1[c
clrscr()
prlnLf(LnLer number Cf 1erms
)
prlnLf(rlme numbers Are lollwlng
)
scanf(dn)
whlle(ln)

c0
for([1[l[++)

lf(l[0)
c++

lf(c2)
prlnLf(d l)
l++

geLch()


C kGM
1est for |eap year

#|nc|ude std|oh

]* `1 |eap year `0 ! |eap year *]
|nt |s_|eap_year(|nt year)

|nt ma|n(vo|d)
|nt years4 2000 2004 2008 2012
|nt | 0

for(| 0 | 4 |++)
|f(|s_|eap_year(years|) 1)
pr|ntf(d |s a |eap yearn years|)
e|se
pr|ntf(d |s not a |eap yearn years|)


return 0


|nt |s_|eap_year(|nt year)
]*
]] |eap year
]] |s d|v|sab|e by 4 and not by 100
]] |s d|v|sab|e by 400
*]
|f((year 4 0 year 100 ! 0) || year 400 0)
return 1 ]* |eap *]
e|se
return 0 ]* no |eap *]






rogram to search for a pa||ndrome

#|nc|ude std|oh
#|nc|ude con|oh
#def|ne LCL

#def|ne 1kUL 1
#def|ne IALSL 0
vo|d ma|n()

char |etter80
|nt tagcountcountbackf|ag|oop1kUL
c|rscr()
wh||e (|oop)

f|ag1kUL
pr|ntf(

|ease enter a wordphrase or sentence be|ow(type LND to ex|t the program)
)
for (count0(|ettercountgetchar())!LCL++count)

|f ((toupper(|etter0)L) (toupper(|etter1)N) (toupper(|etter2)D))
break
tagcount1
for ((count0countbacktag)count(tag]2)(++countcountback))

|f (|ettercount!|ettercountback)

f|agIALSL
break


for (count0counttag++count)
putchar(|ettercount)
|f (f|ag)
pr|ntf( |s a pa||ndrome)
e|se
pr|ntf( |s not a pa||ndrome)





#lncludelosLreamh
#lncludelomanlpP
maln()

lnL ab
a10
b20
couL"values before swap'endl
couL"a"aendl
couL"b"bendl
swap(ab)
couL"values afLer swap"endl
couL"a"aendl
couL"b"bendl

vold swap(lnL a lnL b)

lnL L
La
ab
bL



To write a program to Iind out the payroll system using single inheritance.
ALGORITHM:
$tep 1: $tart the program.
$tep 2: Declare the base class emp.
$tep 3: DeIine and declare the Iunction get() to get the employee details.
$tep 4: Declare the derived class salary.
$tep 5: Declare and deIine the Iunction get1() to get the salary details.
$tep 6: DeIine the Iunction calculate() to Iind the net pay.
$tep 7: DeIine the Iunction display().
$tep 8: Create the derived class object.
$tep 9: Read the number oI employees.
$tep 10: Call the Iunction get(),get1() and calculate() to each employees.
$tep 11: Call the display().
$tep 12: $top the program.
PROGRAM:PAYROLL SYSTEM USING SINGLE
INHERITANCE
#include<iostream.h
#include<conio.h

class emp
,
public:
int eno;
char name20,,des20,;
void get()
,
cout<<"Enter the employee number:";
cineno;
cout<<"Enter the employee name:";
cinname;
cout<<"Enter the designation:";
cindes;
,
,;

class salary:public emp
,
float bp,hra,da,pf,np;
public:
void get1()
,
cout<<"Enter the basic pay:";
cinbp;
cout<<"Enter the Humen Resource Allowance:";
cinhra;
cout<<"Enter the Dearness Allowance :";
cinda;
cout<<"Enter the Profitablity Fund:";
cinpf;
,
void calculate()
,
np=bp+hra+da-pf;
,
void display()
,

cout<<eno<<"\t"<<name<<"\t"<<des<<"\t"<<bp<<"\t"<<hra<<"\t"<<da<<"\t"<<pf<<"
\t"<<np<<"\n";
,
,;

void main()
,
int i,n;
char ch;
salary s10,;
clrscr();
cout<<"Enter the number of employee:";
cinn;
for(i=0;i<n;i++)
,
si,.get();
si,.get1();
si,.calculate();
,
cout<<"\ne_no \t e_name\t des \t bp \t hra \t da \t pf \t np \n";
for(i=0;i<n;i++)
,
si,.display();
,
getch();
,
Output:
nter the Number oI employee:1
nter the employee No: 150
nter the employee Name: ram
nter the designation: Manager
nter the basic pay: 5000
nter the HR allowance: 1000
nter the Dearness allowance: 500
nter the proIitability Fund: 300

.No .name des BP HRA DA PF NP
150 ram Manager 5000 1000 500 300 6200



Simple Program for Function Uverloading Using C++ Programming
Contents
1 1 ALCC8l1PM
2 2 8CC8AM
3 CuLpuL

C++ Slmple Lxample rograms lor 8eglnners

1o calculaLe Lhe area of clrcle recLangle and Lrlangle uslng funcLlon overloadlng
ALGORITHM:
S1L 1 SLarL Lhe program
S1L 2 ueclare Lhe class name as fn wlLh daLa members and member funcLlons
S1L 3 8ead Lhe cholce from Lhe user
S1L 4 Cholce1 Lhen go Lo Lhe sLep 3
S1L 3 1he funcLlon area() Lo flnd area of clrcle wlLh one lnLeger argumenL
S1L 6 Cholce2 Lhen go Lo Lhe sLep 7
S1L 7 1he funcLlon area() Lo flnd area of recLangle wlLh Lwo lnLeger argumenL
S1L 8 Cholce3 Lhen go Lo Lhe sLep 9
S1L 9 1he funcLlon area() Lo flnd area of Lrlangle wlLh Lhree argumenLs Lwo as lnLeger and one as
floaL
S1L 10 Cholce4 Lhen sLop Lhe program
PROGRAM:
#include<iostream.h
#include<stdlib.h
#include<conio.h
#define pi 3.14
class fn
,
public:
void area(int); //circle
void area(int,int); //rectangle
void area(float ,int,int); //triangle
,;

void fn::area(int a)
,
cout<<"Area of Circle:"<<piaa;
,
void fn::area(int a,int b)
,
cout<<"Area of rectangle:"<<ab;
,
void fn::area(float t,int a,int b)
,
cout<<"Area of triangle:"<<tab;
,

vold maln()
,
int ch;
int a,b,r;
clrscr();
fn obj;
cout<<"\n\t\tFunction Jverloading";
cout<<"\n1.Area of Circle\n2.Area of Rectangle\n3.Area of
Triangle\n4.Exit\n:;
cout<<Enter your Choice:";
cinch;

switch(ch)
,
case 1:
cout<<"Enter Radious of the Circle:";
cinr;
obj.area(r);
break;
case 2:
cout<<"Enter Sides of the Rectangle:";
cinab;
obj.area(a,b);
break;
case 3:
cout<<"Enter Sides of the Triangle:";
cinab;
obj.area(0.5,a,b);
break;
case 4:
exit(0);
,
getch();
,
Output:

luncLlon Cverloadlng
1 Area of Clrcle
2 Area of 8ecLangle
3 Area of 1rlangle
4 LxlL
LnLer ?our Cholce 2

LnLer Lhe Sldes of Lhe 8ecLangle 3 3

Area of 8ecLangle ls 23

1 Area of Clrcle
2 Area of 8ecLangle
3 Area of 1rlangle
4 LxlL
LnLer ?our Cholce 4

You might also like