You are on page 1of 81

COMPUTER PROGRAMS

1.Write a program that accepts elements of a 44 arra!


an" "ispla!s it as 1 "imension arra!.
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int A[4][4];
cout<<"Enter elements"<<endl;
for(int i!;i<4;i"")
{
cout<<"Enter elements of ro# "<<i"$<<endl;
for(int %!;%<4;%"")
{
cin>>A[i][%];
&
&
int '[$(];
static int )!;
for(i!;i<4;i"")
{
for(int %!;%<4;%"")
{
'[)]A[%][i];
)"";
&
&
cout<<"Arra* is+"<<endl;
for(i!;i<$(;i"")
cout<<'[i];
,etch();
&
O#tp#t$
Enter elements of -rst ro#
$
.
/
4
Enter elements of second ro#
0
(
1
2
Enter elements of third ro#
3
$!
$$
$.
Enter elements of fourth ro#
$/
$4
$0
$(
Arra* is+$03$/.($!$4/1$$$042$.$(
%.Write a program that accepts a three "igit n#m&er an"
"ispla!s all possi&le perm#tations of its three "igits.
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int n;
cout<<"Enter / di,it no"<<endl;
cin>>n;
int an4$!!;
nn5$!!;
int 6n4$!;
nn5$!;
int cn;
cout<<"7um6ers+"<<endl;
cout<<a<<6<<c<<endl;
cout<<a<<c<<6<<endl;
cout<<6<<a<<c<<endl;
cout<<6<<c<<a<<endl;
cout<<c<<a<<6<<endl;
cout<<c<<6<<a<<endl;
,etch();
&
O#tp#t$
Enter / di,it no
$./
7um6ers+
$./
$/.
.$/
./$
/$.
/.$
'.Write a program that "ispla!s area of s(#are) rectangle
an" triangle #sing *al#es gi*en &! #ser &eforehan".
#include<iostream.h>
#include<conio.h>
#include<math.h>
int area(int);
int area(int8int);
int area(int8int8int);
void main()
{
clrscr();
int a.86/8c4;
cout<<"Area of s9uare"<<area(a)<<endl;
cout<<"Area of rectan,le"<<area(a86)<<endl;
cout<<"Area of trian,le"<<area(a868c)<<endl;
,etch();
&
int area(int a)
{
return(a:a);
&
int area(int a8int 6)
{
return(a:6);
&
int area(int a8int 68int c)
{
int s(a"6"c)4.;
return(s9rt(s:(s+a):(s+6):s+c));
&
O#tp#t$
Area of s9uare4
Area of rectan,le(
Area of trian,le0
4.Write a program class acco#nt +ith s#&classes sa*ings
an" c#rrent.
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<math.h>
class account
{
;u6lic<
char name[.0];
int accno;
int o;6al;
void read()
{
cout<<"Enter name of customer"<<endl;
,ets(name);
cout<<"Enter account no"<<endl;
cin>>accno;
cout<<"Enter o;enin, 6alance"<<endl;
cin>>o;6al;
&
void de;()
{
int de;osit;
cout<<"Enter mone* to 6e de;osited"<<endl;
cin>>de;osit;
o;6al"de;osit;
&
void dis;()
{
cout<<"7ame of customer+";
;uts(name);
cout<<"Account num6er+"<<accno<<endl;
cout<<"'alance"<<o;6al<<endl;
&
&acc;
class savin,s<;u6lic account
{
;u6lic<
int ta)e;
void #ithdra#()
{
cout<<"Enter ammount *ou #ish to #ithdra#"<<endl;
cin>>ta)e;
o;6al+ta)e;
&
void ci()
{
ta)eta)e:;o#(($"!.!4)8/)+ta)e;
cout<<"=ustomer must ;a* interest of "<<ta)e<<endl;
&
&sav;
class current<;u6lic account
{
;u6lic<
int chec);
void chec)6oo)()
{
cout<<"Enter ammount *ou #ish to #ithdra#"<<endl;
cin>>chec);
o;6al+chec);
&
void min6al()
{
if(o;6al<$!!)
cout<<">ou must ;a* ;enalt* of "<<($!!+o;6al):!.!4<<endl;
&
&cur;
void main()
{
clrscr();
int ch;
cout<<"Enter $ for savin,s account8 . for current account"<<endl;
cin>>ch;
if(ch$)
{
cout<<"Enter customer details"<<endl;
sav.read();
cout<<"Enter $ to de;osit8 . to #ithdra#"<<endl;
cin>>ch;
if(ch$)
sav.de;();
else
{
sav.#ithdra#();
&
cout<<"?etails+"<<endl;
sav.dis;();
if(ch.)
sav.ci();
&
else
{
cout<<"Enter customer details"<<endl;
cur.read();
cout<<"Enter $ to de;osit and . to #ithdra#"<<endl;
cin>>ch;
if(ch$)
cur.de;();
else
{
cur.chec)6oo)();
&
cout<<"?etails+"<<endl;
cur.dis;();
if(ch.)
cur.min6al();
&
,etch();
&
O#tp#t$
Enter $ for savin,s account8 . for current account
$
Enter customer details
Enter name of customer
@aran
Enter account no
$./
Enter o;enin, 6alance
$!!!
Enter $ to de;osit8 . to #ithdra#
$
Enter mone* to 6e de;osited
$!!
?etails+
7ame of customer+@aran
Account num6er+$./
'alance+$$!!
,.Write a program that accepts a n#m&er in "ecimal form
an" "ispla!s &inar! form of it.
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int n;
int r$;
cout<<"Enter decimal no"<<endl;
cin>>n;
#hile(n>!)
{
int dn5.;
rr:$!"d;
nn4.;
&
rr4$!;
cout<<"'inar*"<<r;
,etch();
&
O#tp#t$
Enter decimal no
.
'inar*$!
-.Write a program class &an. +ith t+o s#&classes &oo.
an" a#"io cassette.
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
class ;u6lication
{
;u6lic<
char title[.0];
Aoat ;rice;
void ,etdata()
{
cout<<"Enter title"<<endl;
,ets(title);
cout<<"Enter ;rice"<<endl;
cin>>;rice;
&
void ;utdata()
{
cout<<"Bitle+";
;uts(title);
cout<<"Crice+"<<;rice<<endl;
&
&;u6;
class 6oo)<;u6lic ;u6lication
{
;u6lic<
;u6lication cheat;
int count;
void ,etdata()
{
cout<<"Enter count"<<endl;
cin>>count;
&
void ;utdata()
{
cout<<"=ount+"<<count<<endl;
&
&6o;
class audio<;u6lic ;u6lication
{
;u6lic<
;u6lication cheat;
Aoat ta;e;
void ,etdata()
{
cout<<"Enter runnin, time of ta;e in mins"<<endl;
cin>>ta;e;
&
void ;utdata()
{
cout<<"Bime in minutes+"<<ta;e<<endl;
&
&aud;
void main()
{
clrscr();
;u6.,etdata();
6o.,etdata();
aud.,etdata();
;u6.;utdata();
6o.;utdata();
aud.;utdata();
,etch();
&
O#tp#t$
Enter title
=om;uter Dcience
Enter ;rice
.!!
Enter count
/!!
Enter runnin, time of ta;e in minutes
0!
Bitle+=om;uter Dcience
Crice+.!!
=ount+/!!
Bime in minutes+0!
/.Write a program to accept ra"i#s of circle an" "ispla!
area an" circ#mference.
#include<iostream.h>
#include<conio.h>
class circle
{
int r;
;u6lic<
Aoat ar8ci;
void in;ut(int radius)
{
rradius;
&
void calc();
Aoat area();
Aoat circum();
&;
void circle <<calc()
{
ar/.$4:r:r;
ci.:/.$4:r;
&
Aoat circle <<area()
{
return(ar);
&
Aoat circle <<circum()
{
return(ci);
&
void main()
{
clrscr();
circle c;
int radius;
cout<<"Enter radius"<<endl;
cin>>radius;
c.in;ut(radius);
c.calc();
cout<<"Area"<<c.area();
cout<<"=ircumference"<<c.circum();
,etch();
&
O#tp#t$
Enter radius
$
Area/.$4
=ircumference(..2
0.Write a program class emplo!ee +ith s#&class manager.
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
class em;lo*ee
{
;u6lic<
int em;no;
char name[.0];
char add[0!];
char de;t[.0];
void in;ut()
{
cout<<"Enter em;lo*ee no"<<endl;
cin>>em;no;
cout<<"Enter em;lo*ee name"<<endl;
,ets(name);
cout<<"Enter em;lo*ee address"<<endl;
,ets(add);
cout<<"Enter em;lo*ee de;artment"<<endl;
,ets(de;t);
&
void dis;()
{
cout<<"Em;lo*ee num6er+"<<em;no<<endl;
cout<<"Em;lo*ee name+";
;uts(name);
cout<<"Em;lo*ee address+";
;uts(add);
cout<<"Em;lo*ee de;artment+";
;uts(de;t);
&
&em;;
class mana,er<;u6lic em;lo*ee
{
;u6lic<
int no;
void ino()
{
cout<<"Enter no of em;lo*ees"<<endl;
cin>>no;
&
void ono()
{
cout<<"7um6er of em;lo*ees+"<<no<<endl;
&
&man;
void main()
{
clrscr();
man.in;ut();
man.ino();
man.dis;();
man.ono();
,etch();
&
O#tp#t$
Enter em;lo*ee num6er
$
Enter em;lo*ee name
@aran
Enter em;lo*ee address
'an,alore
Enter em;lo*ee de;artment
EF?
Enter no of em;lo*ees
$!
Em;lo*ee num6er+$
Em;lo*ee name+@aran
Em;lo*ee address+'an,alore
Em;lo*ee de;artment+EF?
7um6er of em;lo*ees+$!
1.Write a program to "emonstrate a""ition of "ata
mem&ers of a class #n"er "i2erent o&3ects.
#include<iostream.h>
#include<conio.h>
class distance
{
int feet8inches;
;u6lic<
void ,etdata(int f8int i)
{
feetf;
inchesi;
&
void ;rintit()
{
cout<<"Geet"<<feet<<endl;
cout<<"Hnches"<<inches<<endl;
&
distance sum(distance d.);
&;
distance distance <<sum(distance d.)
{
distance d/;
d/.feet(feet"d..feet)"(inches"d..inches)4$.;
d/.inches(inches"d..inches)5$.;
return d/;
&
void main()
{
clrscr();
distance l$8l.8total;
l$.,etdata($18();
l..,etdata($/82);
totall$.sum(l.);
cout<<endl<<"Ien,th $+"<<endl;
l$.;rintit();
cout<<endl<<"Ien,th .+"<<endl;
l..;rintit();
cout<<endl<<"Botal+"<<endl;
total.;rintit();
cout<<endl;
,etch();
&
O#tp#t$
Ien,th $+
Geet$1
Hnches(
Ien,th .+
Geet$/
Hnches2
Botal+
Geet/$
Hnches.
14.Write a c55 program to "ispla! 6&&onaci series #pto n
terms.
#include<iostream.h>
#include<conio.h>
void -6(int8int8int);
void main()
{
clrscr();
int n;
int a!86$;
cout<<"Enter n"<<endl;
cin>>n;
cout<<a<<"8"<<6;
-6(n8a86);
,etch();
&
void -6(int J8int a8int 6)
{
int c!;
static int d.;
if(d<J)
{
ca"6;
a6;
6c;
cout<<"8"<<c;
d"";
-6(J8a86);
&
&
O#tp#t$
Enter n
0
!8$8$8.8/
11.Write a program to accept t+o n#m&ers an" "ispla!
their hcf.
#include<iostream.h>
#include<conio.h>
int a86;
int hcf(int J)
{
if(a5J! FF 65J!)
return J;
else
return(hcf(J+$));
&
void main()
{
clrscr();
cout<<"Enter a and 6"<<endl;
cin>>a>>6;
cout<<KLcfK<<hcf(a);
,etch();
&
O#tp#t$
Enter a and 6
2
$.
Lcf4
1%.Write a program to 6n" hcf an" gc" of t+o n#m&ers.
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a86;
int hcf8lcm;
cout<<"Enter . num6ers"<<endl;
cin>>a>>6;
for(int i$;i<a;i"")
{
if(a5i! FF 65i!)
hcfi;
&
for(int %a;%<a:6;%"")
{
if(%5a! FF %56!)
{
lcm%;
6rea);
&
&
cout<<"L=G"<<hcf<<endl;
cout<<"I=M"<<lcm;
,etch();
&
O#tp#t$
Enter . num6ers
2
$.
L=G4
I=M.4
1'.Write a program to accept a string an" "ispla! n#m&er
of characters in it.
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
char str[$!!];
cout<<"Enter strin,"<<endl;
cin.,etline(str8$!!);
for(int i!;i<$!!;i"")
{
if(str[i]NO!N)
6rea);
&
cout<<"7o of characters"<<i<<endl;
,etch();
&
O#tp#t$
Enter strin,
=om;uters
7o of characters3
14.Write a program to "ispla! follo+ing pattern$
1
% '
4 , -
/ 0 1 14
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int s!;
for(int i$;i<0;i"")
{
for(int )4;)>i;)++)
cout<<" ";
for(int %$;%<i;%"")
{
s"";
cout<<s<<" ";
&
cout<<endl;
&
,etch();
&
O#tp#t$
$
. /
4 0 (
1 2 3 $!
1,.Write a program class person +ith s#&class spo#se.
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
class ;erson
{
;u6lic<
char name[.0];
int ;hone;
;erson()
{
;hone$./4;
&
void ,et()
{
cout<<"Enter ;erson name"<<endl;
,ets(name);
cout<<"Enter ;hone no"<<endl;
cin>>;hone;
&
void dis;()
{
cout<<"Cerson name+";
;uts(name);
cout<<"Chone no+"<<;hone<<endl;
&
&;
class s;ouse<;u6lic ;erson
{
;u6lic<
char s;ousename[.0];
void ,ets;()
{
cout<<"Enter s;ouse name"<<endl;
,ets(s;ousename);
&
void dis;s()
{
cout<<"Cerson name+";
;uts(name);
cout<<"Chone num6er+"<<;hone<<endl;
cout<<"D;ouse name+";
;uts(s;ousename);
&
&s;
void main()
{
clrscr();
cout<<"Enter data for ;erson"<<endl;
s.,et();
s.dis;();
cout<<"Enter s;ouse data"<<endl;
s.,ets;();
s.dis;s();
,etch();
&
O#tp#t$
Enter data of ;erson
Enter ;erson name
Amit
Enter ;hone no
$./4
Cerson name+Amit
Chone no+$./4
Enter s;ouse data
Enter s;ouse name
Aditi
Cerson name+Amit
Chone no+$./4
D;ouse name+Aditi
1-.Write a program to accept a n#m&er an" "ispla! prime
n#m&ers #p to it.
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int n8c;
cout<<"Enter n ,reater than 0"<<endl;
cin>>n;
#hile(n<0)
{
cout<<"Preater than 0"<<endl;
cin>>n;
&
for(int i.;i<n;i"")
{
c!;
for(int %$;%<i;%"")
{
if(i5%!)
c"";
&
if(c.)
cout<<i<<endl;
&
,etch();
&
O#tp#t$
Enter n ,reater than 0
(
.
/
0
1/.Write a program to "ispla! follo+ing series$
s71 5 18%9 5 18'9...518n9
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int n;
dou6le s$8t$;
cout<<"Enter n"<<endl;
cin>>n;
for(int i$;i<n;i"")
{
t:i;
s"$4t;
&
cout<<"Dum"<<s;
,etch();
&
O#tp#t$
Enter n
.
Dum..0
10.Write a program to "emonstrate ho+ the compiler
han"les f#nctions +ith same name &#t "i2erent
parameters.
#include<iostream.h>
#include<conio.h>
dou6le si(int ;8int t8int r/);
void main()
{
clrscr();
int ;$!!!8r48t.;
cout<<endl<<"Dim;le interest"<<si(;8t8r)<<endl;
cout<<"?efault sim;le interest"<<si(;8t)<<endl;
,etch();
&
dou6le si(int ;8int t8int r)
{
return((;:t:r)4$!!);
&
O#tp#t$
Dim;le interest2!
?efault sim;le interest(!
11.Write a program to accept st#"ent "etails an" "ispla!
them.
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
class student
{
;u6lic<
char name[.0];
int a,e;
void readdata()
{
cout<<"Enter name"<<endl;
,ets(name);
cout<<"Enter a,e"<<endl;
cin>>a,e;
&
void dis;la*()
{
cout<<"7ame of student+";
;uts(name);
cout<<"A,e+"<<a,e<<endl;
&
&;
class ;rimar*student<;u6lic student
{
;u6lic<
char activit*[.0];
int nohrs;
void read;rimar*()
{
cout<<"Enter activit*"<<endl;
,ets(activit*);
cout<<"Enter num6er of hours s;ent in activit*"<<endl;
cin>>nohrs;
&
void dis;la*;rimar*()
{
cout<<"Activit*+";
;uts(activit*);
cout<<"7um6er of hours s;ent+"<<nohrs<<endl;
&
&;rime;
class secondar*student<;u6lic student
{
;u6lic<
char com6o[.0];
void readsecondar*()
{
cout<<"Enter com6ination of student"<<endl;
,ets(com6o);
&
void dis;la*secondar*()
{
cout<<"=om6ination of student+";
;uts(com6o);
&
&sec;
class e9ui;ment<;u6lic secondar*student
{
;u6lic<
char namee[.0];
int roll;
void reade9ui;()
{
cout<<"Enter name of e9ui;ment"<<endl;
,ets(namee);
cout<<"Enter roll no of e9ui;ment"<<endl;
cin>>roll;
&
void dis;la*e9ui;()
{
cout<<"7ame of e9ui;ment+";
;uts(namee);
cout<<"Eoll no+"<<roll<<endl;
&
&e9ui;;
class 6oo)<;u6lic student
{
;u6lic<
char 6oo)name[.0];
int no;,s;
char author[.0];
void read6()
{
cout<<"Enter name of 6oo)"<<endl;
,ets(6oo)name);
cout<<"Enter num6er of ;a,es"<<endl;
cin>>no;,s;
cout<<"Enter author name"<<endl;
,ets(author);
&
void dis;la*6()
{
cout<<"7ame of 6oo)+";
;uts(6oo)name);
cout<<"7um6er of ;a,es+"<<no;,s<<endl;
cout<<"Author+";
;uts(author);
&
&6o;
void main()
{
clrscr();
int ch;
cout<<"Enter 6oo) details"<<endl;
6o.read6();
cout<<"Enter $ if ;rimar* student8 . if secondar*"<<endl;
cin>>ch;
if(ch$)
{
cout<<"Enter 6asic details"<<endl;
;rime.readdata();
cout<<"Enter s;eci-c details"<<endl;
;rime.read;rimar*();
cout<<"'oo) details+"<<endl;
6o.dis;la*6();
cout<<"Dtudent details+"<<endl;
;rime.dis;la*();
;rime.dis;la*;rimar*();
&
else
{
cout<<"Enter 6asic details"<<endl;
e9ui;.readdata();
cout<<"Enter s;eci-c details"<<endl;
e9ui;.readsecondar*();
cout<<"Enter e9ui;ment details"<<endl;
e9ui;.reade9ui;();
cout<<"'oo) details+"<<endl;
6o.dis;la*6();
cout<<"Dtudent details+"<<endl;
e9ui;.dis;la*();
e9ui;.dis;la*secondar*();
cout<<"E9ui;ment details"<<endl;
e9ui;.dis;la*e9ui;();
&
,etch();
&
O#tp#t$
Enter 6oo) details
Enter name of 6oo)
=om;uter Dcience
Enter num6er of ;a,es
.!!
Enter author name
Dumita Arora
Enter $ if ;rimar* student8. if secondar*
$
Enter 6asic details
Enter name
Amit
Enter a,e
3
Enter s;eci-c details
Enter activit*
Goot6all
Enter num6er of hours s;ent in activit*
/
'oo) details+
7ame of 6oo)+=om;uter Dcience
7um6er of ;a,es+.!!
Author+Dumita Arora
Dtudent details+
7ame of student+Amit
A,e+3
Activit*+Goot6all
7um6er of hours s;ent+/
%4.Write a program to accept t+o n#m&ers an" s+ap
them.
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a86;
cout<<"Enter num6ers to 6e s#a;;ed"<<endl;
cin>>a>>6;
cout<<"Qri,inal num6ers"<<a<<"8"<<6<<endl;
aa"6;
6a+6;
aa+6;
cout<<"D#a;;ed num6ers"<<a<<"8"<<6<<endl;
,etch();
&
O#tp#t$
Enter num6ers to 6e s#a;;ed
.
/
Qri,inal num6ers+.8/
D#a;;ed num6ers+/8.
%1.Write a program that accepts "ate) month an" !ear)
an" chec.s if it is a *ali" "ate.
#include<iostream.h>
#include<conio.h>
#include<ct*;e.h>
void date(int8int8int);
void main()
{
clrscr();
int da*8month8*ear;
char c;
cout<<"Enter da*"<<endl;
cin>>da*;
cout<<"Enter month"<<endl;
cin>>month;
cout<<"Enter *ear"<<endl;
cin>>*ear;
date(da*8month8*ear);
,etch();
&
void date(int d8int m8int *)
{
int val$;
int t*;e!;
int thirt*[]{48(838$$8!8!8!&;
int thirone[]{$8/8081828$!8$.&;
int fe6[]{.8!8!8!8!8!8!&;
int t$!8t.!8t/!;
if(m>$.)
val!;
if(d!)
val!;
for(int i!;i<1;i"")
{
if(thirt*[i]m)
t$$;
if(thirone[i]m)
t.$;
if(fe6[i]m)
t/$;
&
if(t$$)
{
if(d>/!)
val!;
&
else if(t.$)
{
if(d>/$)
val!;
&
else
{
if(d>.2 FF *54R!)
val!;
else if(d>.3 FF *54!)
val!;
&
if(val$)
cout<<"?ate is valid"<<endl;
else
cout<<"?ate is invalid"<<endl;
if(*54!)
cout<<"Iea; *ear"<<endl;
else
cout<<"7ot lea; *ear"<<endl;
&
O#tp#t$
Enter da*
$0
Enter month
(
Enter *ear
.!$4
?ate is valid
7ot a lea; *ear
%%.Write a program to "emonstrate f#nction o*erloa"ing.
#include<iostream.h>
#include<conio.h>
#include<math.h>
int vol(int);
int vol(int8int);
int vol(int8int8int);
void main()
{
clrscr();
int s.8r/8h4;
cout<<"Solume of cu6e"<<vol(s)<<endl;
cout<<"Solume of c*linder"<<vol(r8h)<<endl;
cout<<"Solume of cu6oid"<<vol(s8r8h)<<endl;
,etch();
&
int vol(int s)
{
return(s:s:s);
&
int vol(int r8int h)
{
return(/.$4:r:r:h);
&
int vol(int s8int r8int h)
{
return(s:r:h);
&
O#tp#t$
Solume of cu6e2
Solume of c*linder$$/
Solume of cu6oid.4
%'.Write a program to accept +or.er "etails an" "ispla!
them along +ith monthl! salar!.
#include<iostream.h>
#include<conio.h>
class #or)er
{
char #name[.0];
Aoat hr#r)8#,rate;
Aoat total#a,e;
Aoat calc#a,e();
;u6lic<
void inTdata();
void outTdata();
&#or;
Aoat #or)er <<calc#a,e()
{
return(hr#r):#,rate);
&
void #or)er <<inTdata()
{
cout<<"Enter name of #or)er"<<endl;
cin>>#name;
cout<<"Enter hours #or)ed"<<endl;
cin>>hr#r);
cout<<"Enter hourl* #a,e"<<endl;
cin>>#,rate;
total#a,ecalc#a,e();
&
void #or)er <<outTdata()
{
cout<<"7ame of #or)er+"<<#name<<endl;
cout<<"Lours #or)ed+"<<hr#r)<<endl;
cout<<"Lourl* #a,e+"<<#,rate<<endl;
cout<<"Botal #a,e+"<<total#a,e<<endl;
&
void main()
{
clrscr();
#or.inTdata();
#or.outTdata();
,etch();
&
O#tp#t$
Enter name of #or)er
@aran
Enter hours #or)ed
.4
Enter hourl* #a,e
!
7ame of #or)er+@aran
Lours #or)ed+.4
Lourl* #a,e+!
Botal #a,e+!
%4.Write a program that accepts t+o n#m&ers) sets the
smaller as 4 an" "ispla!s them.
#include<iostream.h>
#include<conio.h>
void Uerosmall(int F8int F);
void main()
{
clrscr();
int a86;
cout<<"Enter . num6ers"<<endl;
cin>>a>>6;
Uerosmall(a86);
cout<<"Bhe . num6ers are+"<<a<<"8"<<6<<endl;
,etch();
&
void Uerosmall(int Fa8int F6)
{
if(a<6)
a!;
else
if(a>6)
6!;
else
{&
&
O#tp#t$
Enter . num6ers
.
/
Bhe . num6ers are+!8/
%,.RECOR:;Write a f#nction program +ith s#m<= as
f#nction +ith % arg#ments$
"o#&le > an" int n.The f#nction sho#l" ret#rn a *al#e of
t!pe
"o#&le an" 6n" s#m of the follo+ing series$
1 5 >819 5 >?'8%9 5>?,8'9...5>?%n$18n9
#include<iostream.h>
#include<conio.h>
dou6le sum(dou6le8int);
void main()
{
clrscr();
dou6le J;
int n;
cout<<"Enter J and n"<<endl;
cin>>J>>n;
cout<<"Dum of series"<<sum(J8n)<<endl;
,etch();
&
dou6le sum(dou6le J8int n)
{
dou6le sum$8tem;$4J;
for(int i$;i<n;i"")
{
tem;:J:J4i;
sum"tem;;
&
return(sum);
&
O#tp#t$
Enter J and n
.
/
Dum of series$..//////
%-.RECOR:;:eclare a str#ct#re to represent a comple>
n#m&er ha*ing real
an" imaginar! parts. Write f#nctions to a"") s#&tract)
m#ltipl!
an" "i*i"e the t+o comple> n#m&ers.
#include<iostream.h>
#include<conio.h>
struct com;leJ
{
dou6le r8i;
&n$8n.8n/;
void add()
{
n/.rn$.r"n..r;
n/.in$.i"n..i;
&
void su6()
{
n/.rn$.r+n..r;
n/.in$.i+n..i;
&
void mul()
{
n/.r(n$.r:n..r)+(n$.i:n..i);
n/.i(n$.r:n..i)"(n$.i:n..r);
&
void div()
{
n..i:+$;
n/.r(n$.r:n..r)+(n$.i:n..i);
n/.i(n$.r:n..i)"(n$.i:n..r);
dou6le den(n..r:n..r)"(n..i:n..i);
n/.r4den;
n/.i4den;
&
void main()
{
clrscr();
char ch;
int real8ima,;
cout<<"Enter real and com;leJ ;art of -rst num6er"<<endl;
cin>>n$.r>>n$.i;
cout<<"Enter real and com;leJ ;art of second num6er"<<endl;
cin>>n..r>>n..i;
cout<<"Enter " for addition8 + for su6traction8 : for multi;lication8 4 for
division"<<endl;
cin>>ch;
s#itch(ch)
{
case N"N<cout<<"Addition"<<endl;
add();
6rea);
case N+N<cout<<"Du6traction"<<endl;
su6();
6rea);
case N:N<cout<<"Multi;lication"<<endl;
mul();
6rea);
case N4N<cout<<"?ivision"<<endl;
div();
6rea);
default<cout<<"Hnvalid in;ut"<<endl;
n/.r!8n/.i!;
&
if(n/.i>!)
cout<<"7um6er"<<n/.r<<"""<<n/.i<<"i";
else
cout<<"7um6er"<<n/.r<<n/.i<<"i";
,etch();
&
O#tp#t$
Enter real and com;leJ ;art of -rst num6er
$
.
Enter real and ima,inar* ;art for second num6er
/
4
Enter " for addition8 + for su6traction8 : for multi;lication8 4 for division
"
Addition
7um6er4"(i
%/.RECOR:;@rom a %: arra! AA4BA4B +rite a program to
prepare
a 1: arra! CA1-B that +ill ha*e all the elements of A
if the! are store" in col#mn ma3or form.
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int A[4][4]8'[$(];
for(int i!;i<4;i"")
{
cout<<"Enter elements of ro# no."<<i"$<<endl;
for(int %!;%<4;%"")
{
cin>>A[i][%];
&
&
int )!;
for(i!;i<4;i"")
{
for(int %!;%<4;%"")
{
'[)]A[%][i];
)"";
&
&
cout<<"Din,le dimension arra* is+"<<endl;
for(i!;i<$(;i"")
cout<<'[i]<<"8";
,etch();
&
O#tp#t$
Enter elements of -rst ro#
$
.
/
4
Enter elements of second ro#
0
(
1
2
Enter elements of third ro#
3
$!
$$
$.
Enter elements of fourth ro#
$/
$4
$0
$(
Arra* is+$80838$/8.8(8$!8$48/818$$8$084828$.8$(
%0.RECOR:;Write t+o o*erloa"e" f#nctions to 6n" GC: of
t+o n#m&ers amongst
+hich one f#nction +o#l" &e normal) other rec#rsi*e.
#include<iostream.h>
#include<conio.h>
int ,cd(int a8int 6);
int ,cd(int n);
int c8d;
void main()
{
clrscr();
int a86;
int ch;
cout<<"Enter the t#o num6ers"<<endl;
cin>>a>>6;
cout<<"Enter $ for normal function8 . for recursive function"<<endl;
cin>>ch;
if(ch$)
cout<<"P=?"<<,cd(a86);
else if(ch.)
{
ca8d6;
cout<<"P=?"<<,cd(a);
&
else
cout<<"Hnvalid in;ut"<<endl;
,etch();
&
int ,cd(int a8int 6)
{
int ,!;
for(int i$;i<a;i"")
{
if(a5i! FF 65i!)
,i;
&
return(,);
&
int ,cd(int n)
{
if(n$)
return $;
else if(c5n! FF d5n!)
return n;
else
return(,cd(n+$));
&
O#tp#t$
Enter the . num6ers
2
$.
Enter $ for normal function8 . for recursive
$
P=?4
%1.RECOR:;Write an o*erloa"e" f#nction po+er<= ha*ing
t+o *ersions. The 6rst
*ersion ta.es "o#&le n an" int p an" ret#rns a "o#&le
*al#e. The
secon" ta.es int n an" int p an" ret#rns int *al#e. Use a
"efa#lt *al#e
% for p in case p is omitte" in f#nction call.
#include<iostream.h>
#include<conio.h>
#include<math.h>
dou6le ;o#er(dou6le8int ;.);
int ;o#er(int8int ;.);
void main()
{
clrscr();
dou6le n;
int ;;
int c8ch;
cout<<"Enter n"<<endl;
cin>>n;
cout<<"Enter $ if *ou #ish to enter ;"<<endl;
cin>>c;
if(c$)
{
cout<<"Enter ;"<<endl;
cin>>;;
&
cout<<"Enter $ for nV;8 . for n:n:n....; times"<<endl;
cin>>ch;
if(c$ FF ch$)
cout<<"Eesult"<<;o#er(n8;);
else if(cR$ FF ch$)
cout<<"Eesult"<<;o#er(n);
else if(c$ FF ch.)
{
n(int)n;
cout<<"Eesult"<<;o#er(n8;);
&
else if(cR$ FF ch.)
{
n(int)n;
cout<<"Eesult"<<;o#er(n);
&
else
cout<<"Hnvalid choice"<<endl;
,etch();
&
dou6le ;o#er(dou6le n8int ;)
{
dou6le tem;;o#(n8;);
return tem;;
&
int ;o#er(int n8int ;)
{
int tem;$;
for(int i$;i<;;i"")
{
tem;:n;
&
return tem;;
&
O#tp#t$
Enter n
.
Enter $ if *ou #ish to enter ;
!
Enter $ for nV;8 . for n:n:n...; times
.
Eesult4
'4.RECOR:;Write t+o *ersions of an o*erloa"e" f#nction
s#m<=. The 6rst *ersion
accepts an" int arra! an" ret#rns s#m of all elements. The
secon"
*ersion accepts an int arra! an" a character. Dt ret#rns
s#m of e*en
elements if character is EEE) s#m of o"" elements if
character is EOE)
an" 4 if an! other character.
#include<iostream.h>
#include<conio.h>
int sum(int ar[0]);
int sum(int ar[0]8char);
void main()
{
clrscr();
int ar[0];
char ch;
cout<<"Enter 0 elements for the arra*"<<endl;
for(int i!;i<0;i"")
cin>>ar[i];
cout<<"Enter $ for sum of even or odd elements"<<endl;
cin>>ch;
if(chN$N)
{
cout<<"Enter E for even8 Q for odd"<<endl;
cin>>ch;
cout<<"Dum"<<sum(ar8ch);
&
else
cout<<"Dum"<<sum(ar);
,etch();
&
int sum(int ar[0])
{
int s!;
for(int i!;i<0;i"")
{
s"ar[i];
&
return s;
&
int sum(int ar[0]8char ch)
{
int e!8o!;
for(int i!;i<0;i"")
{
if(ar[i]5.!)
e"ar[i];
else
o"ar[i];
&
if(chNEN)
return e;
else if(chNQN)
return o;
else
return !;
&
O#tp#t$
Enter 0 elements for the arra*
$
.
/
4
0
Enter $ for sum of even or odd elements
!
Dum$0
'1.RECOR:;Write a program to .eep co#nt of o&3ects
create" #sing static mem&ers.
#include<iostream.h>
#include<conio.h>
class counter
{
static int c;
;u6lic<
counter()
{
c"";
&
void dis;la*()
{
cout<<"7um6er of o6%ects created"<<c<<endl;
&
&;
int counter <<c!;
void main()
{
clrscr();
char ch;
cout<<"Enter $8.8/ to create $8.8/ o6%ects res;ectivel*"<<endl;
cin>>ch;
if(chN$N)
{
counter A;
cout<<"Q6%ect called A created"<<endl;
A.dis;la*();
&
else if(chN.N)
{
counter ';
counter =;
cout<<"Q6%ects called ' and = created"<<endl;
=.dis;la*();
&
else if(chN/N)
{
counter ?;
counter E;
counter G;
cout<<"Q6%ects called ?8E8G created"<<endl;
G.dis;la*();
&
else
cout<<"Hnvalid in;ut"<<endl;
,etch();
&
O#tp#t$
Enter $8.8/ to create $8.8/ o6%ects res;ectivel*
$
Q6%ect called A created
7um6er of o6%ects created$
'%.RECOR:;Write a program to perform *ario#s operations
on a string class +itho#t
#sing lang#age s#pporte" &i#lt$in string f#nctions.
Operations are rea"
a string) "ispla!) re*erse) cop! to empt!) concatenate.
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
class strin,
{
char str[.0]8str.[.0]8r[.0]8co;[.0]8con[0!];
;u6lic<
read();
dis;();
rev();
co;*();
concat();
&s;
strin, <<read()
{
cout<<"Enter strin,"<<endl;
,ets(str);
&
strin, <<dis;()
{
cout<<"Dtrin,";
;uts(str);
cout<<endl;
&
strin, <<rev()
{
for(int i!;str[i]RNO!N;i"");
for(int )!8%i+$;%>!;%++8)"")
{
r[)]str[%];
&
cout<<"Eeversed strin,";
;uts(r);
&
strin, <<co;*()
{
for(int i!;i<.0;i"")
co;[i]str[i];
cout<<"=o;ied strin,";
;uts(co;);
cout<<endl;
&
strin, <<concat()
{
cout<<"Enter second strin,"<<endl;
,ets(str.);
for(int i!;str[i]RNO!N;i"");
for(int %!;str.[%]RNO!N;%"");
for(int )!;)<i;)"")
con[)]str[)];
for(int l!;l<%;l"")
con[l"i]str[l];
cout<<"=oncatenated strin,s";
;uts(co;);
&
void main()
{
clrscr();
s.read();
s.dis;();
s.rev();
s.co;*();
s.concat();
,etch();
&
O#tp#t$
Enter strin,
=om;uter
Dtrin,=om;uter
Eeversed strin,retu;mo=
=o;ied strin,=om;uter
Enter second strin,
Dcience
=oncatenated strin,s=om;uterDcience
''.RECOR:;:e6ne a class Applicant that accepts
a"mission no) name) aggregate
mar.s) calc#lates gra"e an" "ispla!s all the "etails.
#include<iostream.h>
#include<conio.h>
class A;;licant
{
lon, int A7o;
char 7ame[.0];
Aoat A,,;
char Prade;
void PradeMe()
{
if(A,,>2!)
PradeNAN;
else if(A,,<2! FF A,,>(0)
PradeN'N;
else if(A,,<(0 FF A,,>0!)
PradeN=N;
else
PradeN?N;
&
;u6lic<
void E7BEE()
{
cout<<"Enter Admission num6er"<<endl;
cin>>A7o;
cout<<"Enter name"<<endl;
cin>>7ame;
cout<<"Enter A,,re,ate mar)s"<<endl;
cin>>A,,;
PradeMe();
&
void EEDWIB()
{
cout<<"Admission num6er"<<A7o<<endl;
cout<<"7ame"<<7ame<<endl;
cout<<"A,,re,ate mar)s"<<A,,<<endl;
cout<<"Prade"<<Prade<<endl;
&
&A;
void main()
{
clrscr();
A.E7BEE();
A.EEDWIB();
,etch();
&
O#tp#t$
Enter Admission num6er
$
Enter name
@aran
Enter A,,re,ate mar)s
$!!
Admission num6er$
7ame@aran
A,,re,ate mar)s$!!
PradeA
'4.RECOR:;:e6ne a class tic&ooth +hich co#nts n#m&er
of people +ho pass &! an"
+hether the! &#! a tic.et or not) an" "ispla!s all the
"etails.
#include<iostream.h>
#include<conio.h>
class tic6ooth
{
int tot;;
dou6le totm;
;u6lic<
tic6ooth()
{
tot;!8totm!;
&
void inc;()
{
tot;"";
&
void incm()
{
totmtotm"..0;
&
void dis;la*()
{
cout<<"7um6er of ;eo;le #ho visited"<<tot;<<endl;
cout<<"Amount collected"<<totm<<endl;
&
void tic)et()
{
cout<<"Bic)ets sold"<<totm4..0<<endl;
&
&t;
void main()
{
clrscr();
cout<<"Bic)et 6ooth"<<endl;
char chN!N86u*;
#hile(chN!N)
{
cout<<"A ;erson ;asses 6*"<<endl;
cout<<"Enter $ if he 6u*s a tic)et"<<endl;
cin>>6u*;
if(6u*N$N)
{
t.inc;();
t.incm();
&
else
t.inc;();
cout<<"Enter ! to continue"<<endl;
cin>>ch;
&
t.dis;la*();
t.tic)et();
,etch();
&
O#tp#t$
Bic)et 6ooth
A ;erson ;asses 6*
Enter $ if he 6u*s a tic)et
$
Enter ! to continue
!
A ;erson ;asses 6*
Enter $ if he 6u*s a tic)et
!
Enter ! to continue
$
7um6er of ;eo;le #ho visited.
Amount collected..0
Bic)ets sold$
',.RECOR:;:e6ne a class Tra*elPlan) #se constr#ctor to
initialise plan co"e)
place) n#m&er of tra*ellers an" n#m&er of &#ses. Allo+
#ser to enter the
*al#es) calc#late n#m&er of &#ses nee"e" an" "ispla! the
information.
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<strin,.h>
class BravelClan
{
lon, int Clan=ode;
char Clace[.0];
int 7um6erTofTtravellers;
int 7um6erTofT6uses;
;u6lic<
BravelClan()
{
Clan=ode$!!$;
strc;*(Clace8"A,ra");
7um6erTofTtravellers0;
7um6erTofT6uses$;
&
void 7e#Clan()
{
cout<<"Enter ;lan code"<<endl;
cin>>Clan=ode;
cout<<"Enter ;lace"<<endl;
,ets(Clace);
cout<<"Enter num6er of travellers"<<endl;
cin>>7um6erTofTtravellers;
if(7um6erTofTtravellers<.!)
7um6erTofT6uses$;
else if(7um6erTofTtravellers>.! FF 7um6erTofTtravellers<4!)
7um6erTofT6uses.;
else
7um6erTofT6uses/;
&
void Dho#Clan()
{
cout<<"Clan code"<<Clan=ode<<endl;
cout<<"Clace";
;uts(Clace);
cout<<"7um6er of travellers"<<7um6erTofTtravellers<<endl;
cout<<"7um6er of 6uses"<<7um6erTofT6uses<<endl;
&
&t;;
void main()
{
clrscr();
t;.7e#Clan();
t;.Dho#Clan();
,etch();
&
O#tp#t$
Enter ;lan code
$
Enter ;lace
'an,alore
Enter num6er of travellers
$!
Clan code$
Clace'an,alore
7um6er of travellers$!
7um6ers of 6uses$
'-.RECOR:;:e6ne a class Serial +ith information li.e
serial co"e) title) "#ration
an" no of episo"es. Dnitialise #sing constr#ctors an"
mem&er f#nctions
an" then "ispla!.
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
class Derial
{
int Derialcode;
char Bitle[.!];
Aoat ?uration;
int 7oofe;isodes;
;u6lic<
Derial()
{
?uration/!;
7oofe;isodes$!;
&
void 7e#serial()
{
cout<<"Enter serial code"<<endl;
cin>>Derialcode;
cout<<"Enter title"<<endl;
,ets(Bitle);
&
void Qtherentries(Aoat d8int n)
{
?urationd;
7oofe;isodesn;
&
?is;data()
{
cout<<"Derial code"<<Derialcode<<endl;
cout<<"Bitle";
;uts(Bitle);
cout<<"?uration"<<?uration<<endl;
cout<<"7o of e;isodes"<<7oofe;isodes<<endl;
&
&s;
void main()
{
clrscr();
Aoat d;
int n;
s.7e#serial();
cout<<"Enter duration and no of e;isodes"<<endl;
cin>>d>>n;
s.Qtherentries(d8n);
s.?is;data();
,etch();
&
O#tp#t$
Enter serial code
$
Enter title
Bom and Xerr*
Enter duration and no of e;isodes
/!
$!!
Derial code$
BitleBom and Xerr*
?uration/!
7o of e;isodes$!!
'/.RECOR:;:e6ne a class Clothing to accept co"e) t!pe)
siFe an" material) calc#late
price an" "ispla!.
#include<iostream.h>
#include<conio.h>
#include<strin,.h>
#include<stdio.h>
class =lothin,
{
char =ode[.0]8B*;e[.0];
int DiUe;
char Material[.0];
Aoat Crice;
=alcTCrice()
{
if(Rstrcm;(Material8"=QBBQ7"))
{
if(Rstrcm;(B*;e8"BEQWDEE"))
Crice$0!!;
else if(Rstrcm;(B*;e8"DLHEB"))
Crice$.!!;
else
{&
&
else
{
if(Rstrcm;(B*;e8"BEQWDEE"))
Crice$0!!+$0!!:!..0;
else if(Rstrcm;(B*;e8"DLHEB"))
Crice$.!!+$.!!:!..0;
else
{&
&
&
;u6lic<
=lothin,()
{
strc;*(=ode8"7QB ADDHP7E?");
strc;*(B*;e8"7QB ADDHP7E?");
strc;*(Material8"7QB ADDHP7E?");
DiUe!;
Crice!;
&
void Enter()
{
cout<<"Enter code8 t*;e8 siUe8 material"<<endl;
,ets(=ode);
,ets(B*;e);
cin>>DiUe;
,ets(Material);
=alcTCrice();
&
void Dho#()
{
cout<<"=ode";
;uts(=ode);
cout<<"B*;e";
;uts(B*;e);
cout<<"DiUe"<<DiUe<<endl;
cout<<"Material";
;uts(Material);
cout<<"Crice"<<Crice<<endl;
&
&c;
void main()
{
clrscr();
c.Enter();
c.Dho#();
,etch();
&
O#tp#t$
Enter code8 t*;e8 siUe8 material
$
DLHEB
4.
=QBBQ7
=ode$
B*;eDLHEB
DiUe4.
Material=QBBQ7
Crice$.!!
'0.RECOR:;Write a f#nction to accept time of % cloc.s in
ho#rs) min#tes) secon"s
an" o#tp#t time since last str#c. 1% in secon"s an"
"i2erence &et+een
the t+o in secon"s.
#include<iostream.h>
#include<conio.h>
#include<math.h>
void time(int h$8int m$8int s$8int h.8int m.8int s.);
void main()
{
clrscr();
int h$8m$8s$8h.8m.8s.;
cout<<"Enter -rst cloc)Ns time in hours8 minutes8seconds"<<endl;
cin>>h$>>m$>>s$;
cout<<"Enter second cloc)Ns time in hours8 minutes8 seconds"<<endl;
cin>>h.>>m.>>s.;
time(h$8m$8s$8h.8m.8s.);
,etch();
&
void time(int h$8int m$8int s$8int h.8int m.8int s.)
{
int t$h$:/(!!"m$:(!"s$;
int t.h.:/(!!"m.:(!"s.;
cout<<"Deconds since -rst cloc) struc) $."<<t$<<endl;
cout<<"Deconds since second cloc) struc) $."<<t.<<endl;
int t/(fa6s)(t$+t.);
cout<<"?iYerence 6et#een . cloc)s in seconds"<<t/<<endl;
&
O#tp#t$
Enter -rst cloc)Ns time in hours8 minutes8 seconds
$
$!
.!
Enter second cloc)sN time in hours8 minutes8 seconds
/
.!
4
Deconds since -rst cloc) struc) $.4..!
Deconds since second cloc) struc) $.$.!!4
?iYerence 6et#een t#o cloc)s in seconds1124

You might also like