IMRANOOPSPROGRAM
IMRANOOPSPROGRAM
#include<iostream.h> #include<conio.h> class ar {private:float a; public:ar() {a=0;} ar() {a=0;} void area(float !) {a=".#$#%&!&!; } void area(float !'float () {a=!&(; } void area(float !'float ('int u) {a=(!&())%; } void sho*area() {cout<<+,n the area of the fi-ure is:+<<a; } }n$; void main() {int n=0'i; float h'b'r; clrscr(); *hile(n.=$) {clrscr(); cout<<+,n enter the choice of fi-ure *hose area is to be calculated ,n$/circle,n%/ rectan-le,n"/trian-le,nenter (our choice:+; cin>>i; s*itch(i) {case $:cout<<+,nfor circle,n+; cout<<+,n enter the radius of the circle:+; cin>>r; n$.area(r); n$.sho*area(); brea0; case %:cout<<+,nfor rectan-le,n+; cout<<+,n enter the len-th of the rectan-le:+; cin>>h; cout<<+,n enter the *idth of the rectan-el:+; cin>>b; n$.area(h'b);
n$.sho*area(); brea0; case ":cout<<+,nfor trian-le,n+; cout<<+,n enter the hei-ht of the trian-le:+; cin>>h; cout<<+,n enter the base len-th of the trian-el:+; cin>>b; n$.area(h'b'$); n$.sho*area(); brea0; default:cout<<+,n sorr( (ou have entered *ron- choice,n+; } cout<<+,n do (ou *ant to continue ((es:0'no:$):+; cin>>n; } -etch(); }
2- Write a program in C++ using classes to find out whether the entered number is automorphic or not.
#include<iostream.h> #include<conio.h> #include<math.h> void main() {int n'r=0'i's=0'm'a'b'l'0=0; cout<<+enter a number+; clrscr(); cin>>n; l=n; *hile(l.=0) {r=l1$0; s=s2$; l=l)$0; } b=n&n; m=po*($0's); 0=b)m; a=b/m&0; if (a==n) {cout<<+automorphic number+<<n;} else {cout<<+not automorphic+;} -etch(); }
"
3-Assume that a ban maintains two inds of accounts for its customers, one called as sa!ings account and other as current account. "he sa!ings account pro!ides compound interest and withdrawal facilities but no chec boo facilit#. "he current account pro!ides chec boo facilit# but no interest. Current account holders should maintain a minimum balance and if the balance falls below this le!el as ser!ice charge is imposed. Create a Class account that stress customer name, account number and t#pe of account. $rom this deri!e Classes cur%account and sa!%account to ma e them more specific to their re&uirements include necessar# member functions in order to achie!e the following tas s' 1( Accept deposits from a customer and update the balance. 2( )ispla# the balance. 3( Compute and deposit the interest. *( +ermit withdrawal and update the balance. ,(Chec for the minimum balance and impose penalt# necessar# and update the balance.
#include<iostream.h> #include<conio.h> #include<math.h> #include<strin-.h> class 3ccount {private:char c4name5%67; int acc4no; char t(pe587; public:void read(int); void displa((); }; class 9av4acc:public 3ccount {private:float balance; float debit; float deposit; float interest; public:void update(); }; class :ur4acc:public 3ccount {private:float balance; int pa-es4ch; float debit; float deposit; public:void update4cur(); }; void 3ccount::read(int !) #
{int i=0';=0; char sav587=+savin-s+'cur587=+current+; clrscr(); cout<<+,n<nter (our account number:+; cin>>acc4no; cout<<+,n<nter (our name:+; cin>>c4name; if(!==$) {for(i=0;i<8;i22) {t(pe5i7=sav5i7; } } else {for(;=0;;<8;;22) {t(pe5;7=cur5;7; } } } void 9av4acc::update() {int amt; cout<<+,n enter the balance:+; cin>>balance; cout<<+,n <nter the amount of mone( to be *ithdra*n:+; cin>>debit; cout<<+,n =he balance after the *ithdra*al is:+; balance=balance/debit; cout<<balance; cout<<+,n <nter the amount to be deposited:+; cin>>deposit; cout<<+,n =he amount after deposit is:+; balance=balance2deposit; cout<<balance; cout<<+,n =he compound interest for the t*o (ears is ".61 ,n+; amt=($2(".6)$00)); interest=po*(amt'%); cout<<+,n =he balance after the compound interest is:+; balance=balance2interest; cout<<balance; } void :ur4acc::update4cur() {int c=0; char ch; balance=0; cout<<+,n <nter the amount to be deposited:+; cin>>deposit; cout<<+,n =he amount after deposit is:+;
balance=balance2deposit; cout<<balance; cout<<+,n <nter the amount of mone( to be *ithdra*n:+; cin>>debit; cout<<+,n =he balance after the *ithdra*al is:+; balance=balance/debit; cout<<balance; if(balance<$000) {cout<<+,n =he balance in the account is less than the limit+; balance=balance/$00; cout<<+,n =he balance after the penalt( is:+<<balance; } *hile(c==0) {cout<<+,n do (ou *ant to issue the che>ue boo0 ((/(es'n/no): + ; cin>>ch; if(ch==?(?) {cout<<+,n <nter the number of pa-es to be issued of the che>ue boo0:+; cin>>pa-es4ch; cout<<+,n the boo0 *ill be issued to (ou after t*o da(s:+; c=$; } else {if(ch==?n?) {c=$;} else {cout<<+,n sorr( (ou have entered *ron- choice:+; -etch(); } } } } void 3ccount::displa(() {cout<<+,n=he account number is:+<<acc4no; cout<<+,n=he name of the customer is:+<<c4name; cout<<+,n=he t(pe of account is:+<<t(pe; -etch(); } void main() {int i=0'c=0; clrscr(); *hile(i==0) {clrscr(); cout<<+,n enter the choice of operation to be performed ,n $:savin-s ,n %:current ,n ":e!it ,n enter choice:+; cin>>c; s*itch(c)
{case $:9av4acc a; a.read(c); a.update(); a.displa((); -etch(); brea0; case %::ur4acc b; b.read(c); b.update4cur(); b.displa((); -etch(); brea0; case ":i=$; cout<<+,n than0s for usin- our services:+; -etch(); brea0; default:cout<<+,n sorr( (ou have entered *ron- choice enter a-ain:+; -etch(); } } }
*- Write a program in C++ to create Class called comple- and implement addition and subtraction of comple- numbers b# o!erloading the functions add and subtract which returns the complenumber. Also o!erload the operator .//0 to displa# a comple- number.
#include<iostream.h> #include<conio.h> class :omple! {private:int real; int ima-; public:void input(); void add(:omple!':omple!); void add(int); void sub(:omple!':omple!); void sub(int); void displa((); }; void main() {clrscr(); :omple! c$'c%'c"; c$.input(); c$.displa((); c%.input(); c%.displa((); cout<<+,n,nA<BCD< 3EEFGH =I< :CG9=3G====>,n+; c".add(c$'c%); c".displa((); cout<<+,n,n3B=<D 3EEFGH =I< :CG9=3G====>,n+; c".add($0); c".displa((); -etch(); c$.input(); c$.displa((); cout<<+A<BCD< 9JA9=D3:=FGH =I< :CG9=3G=,n+; c".sub(c$'c%); c".displa((); cout<<+3B=<D 9JA9=D3:=FGH =I< :CG9=3G=,n+; c%.input(); c%.displa((); c".sub($0); c".displa((); -etch(); } void :omple!::input() {cout<<+,n,n<G=<D =I< D<3K GJLA<D9,t+; cin>>real; M
cout<<+,n<G=<D =I< FL3HFG3DN GJLA<D9,t+; cin>>ima-; } void :omple!::add(:omple! 9':omple! D) {real=9.real2D.real; ima-=9.ima-2D.ima-; } void :omple!::add(int n) {real=real2n; } void :omple!::sub(:omple! 9':omple! D) {real=9.real/D.real; ima-=9.ima-/D.ima-; } void :omple!::sub(int n) {real=real/n; } void :omple!::displa(() {cout<<+,n,n=I< D<3K GJLA<D F9 +<<real; cout<<+,n=I< FL3HFG3DN GJLA<D F9 +<<ima-; cout<<+,n=I< :CLOK<P GJLA<D F9 +<<real<<+2+<<ima-<<+;+; }
,- Write a program in C++ to create a Class )ate and add and subtract two !alid dates. 1llustrate the use of cop# constructor.
#include<iostream.h> #include<conio.h> class date {private:int d; int m; int (; public:date() {d=0;m=0;(=0;} date(int a'int b'int c) {d=a;m=b;(=c;} void -etdata(); void sho*data() {cout<<+,n the date /> +<<d<<+:+<<m<<+:+<<(<<+.+; cout<<+,n+; } void sum(date a'date b) {d=a.d2b.d; m=a.m2b.m; (=a.(2b.(; } void diff(date a'date b) {d=a.d/b.d; m=a.m/b.m; (=a.(/b.(; } }d$'d%'d"; void date :: -etdata() {int c=0'0=0't; float l; clrscr(); *hile(c==0) {cout<<+,n enter the parameters of date ,n+; cout<<+,n enter (ear: +; cin>>(; if((>"$000 RR (</"$000) {cout<<+,n please enter the value *ithin computational limit bet. /"$000 and "$000)+; } else {l=(1$00; if(l==0) {t=()$00; l=t1#; if(l==0)
$0
{0=$;} } else {l=(1#; if(l==0) {0=$;} } c=$; } } c=0; *hile(c==0) {cout<<+,n enter month($/$%): +; cin>>m; if(m<$ RR m>$%) {cout<<+,n (ou have entered *ron- value enter a-ain+; } else {c=$;} } l=0; *hile(c==$) {cout<<+,n enter date: +; cin>>d; if(m==$ RR m==" RR m==6 RR m==8 RR m==M RR m==$0 RR m==$%) {if(d<$ RR d>"$) {cout<<+,n sorr( (ou have entered *ron- value enter a-ain+; } else {c=0;} } else if(m==% RR m==# RR m==@ RR m==Q RR m==$$) {if(d<$ RR d>"0) {cout<<+,n sorr( (ou have entered *ron- value enter a-ain+; } else {c=0;} } else {if(m==%) {if(0==$) {if(d<$ RR d>%Q) {cout<<+,n sorr( (ou have entered *ron- value enter a-ain+; } else
$$
{c=0;} } } else if(d<$ RR d>%M) {cout<<+,n sorr( (ou have entered *ron- value enter a-ain+; } else {c=0;} } } } void main() {int n'i; clrscr(); d$.-etdata(); d$.sho*data(); d%.-etdata(); d%.sho*data(); d".sum(d$'d%); d".sho*data(); d".diff(d$'d%); d".sho*data(); -etch(); }
$%
2- Write a program in C++ using classes to enter the data of an emplo#ee and displa# it.
#include<iostream.h> #include<conio.h> class <mp {public:char name5$07; int a-e; int salar(; public:void init(); void displa((); }; void main() {clrscr(); <mp ob;; ob;.init(); ob;.displa((); -etch(); } void <mp::init() {<mp ob;; cout<<+,n <G=<D =I< G3L< ==> ,n+; cin>>ob;.name; cout<<+,n <G=<D =I< 3H< ==> ,n+; cin>>ob;.a-e; cout<<+,n <G=<D =I< 93K3DN ==> ,n+; cin>>ob;.salar(; } void <mp::displa(() {<mp ob;; cout<<+,n <LOKCN<<?9 G3L< ,n+<<ob;.name; cout<<+,n <LOKCN<<?9 3H< ,n+<<ob;.a-e; cout<<+,n <LOKCN<<?9 93K3DN ,n+<<ob;.salar(; }
$"
3-Write a program in C++ to create a lin ed list with insert%front and delete%front as member functions b# creating to ob4ects. 5se constructor to initiali6e the ob4ects.
#include<iostream.h> #include<conio.h> struct node {int info; struct node &ne!t; }; t(pedef struct node node; class Kin0list {private:node &first; public:void insert4front(); void delete4front(); void displa((); Kin0list() {first=GJKK; } }; void main() {int a; clrscr(); Kin0list ob;; *hile (a.=#) {clrscr(); cout<<+,n $.FG9<D= FG BDCG=,n %.E<K<=< BDCL BDCG=,n ".EF9OK3N KFGSKF9=,n #.<PF=,n+; cout<<+,n <G=<D =I< :ICF:<:+; cin>>a; s*itch(a) {case $:ob;.insert4front(); brea0; case %:ob;.delete4front(); brea0; case ":ob;.displa((); brea0; case #:cout<<+,n than0s for usin- the pro-ram+; -etch(); brea0; default:cout<<+,n sorr( (ou have entered *ron- choice enter a-ain:+; -etch(); }; -etch(); } $#
} void Kin0list::insert4front() {node &temp; temp=ne*(node); if(temp==0) {cout<<+,n L<LCDN CT<DBKCU+; return; } cout<<+,n <G=<D =I< GJLA<D 3= =I< GCE<:+; cin>>temp/>info; if(first==GJKK) {first=temp; temp/>ne!t=GJKK; return; } temp/>ne!t=first; first=temp; } void Kin0list::delete4front() {node &ptr; if (first==GJKK) {cout<<+,n JGE<DBKCU+; } else {ptr=first; first=first/>ne!t; cout<<+,n+<<+,t,t+<<ptr/>info<<+ E<K<=<E+; delete ptr; } } void Kin0list::displa(() {node &ptr; ptr=first; *hile(ptr.=GJKK) {cout<<+,n+<<+,t,t+<<ptr/>info; cout<<endl; ptr=ptr/>ne!t; } }
$6
7- Write a program in C++ to create a Class 8ctal to perform decimal to octal con!ersion and addition of an octal and an interger b# o!erloading 9+ and 9:.
#include<iostream.h> #include<conio.h> class octal {private:int ov; public:octal() {ov=0;} void -etdata(); void octcon(int); octal operator=(int a); int operator2(int a); void sho*data(int iv'int !) {cout<<+,n the decimal number:+; cout<<iv; cout<<+,n the sum:+<<ov; -etch(); } void sho*data(int iv) {cout<<+,n the octal number:+; cout<<ov; cout<<+,n the decimal number:+; cout<<iv; -etch(); } }n$'n%; void octal :: -etdata() {int !=0'i=0'temp'c=0; cout<<+,n for addition ,n+; *hile(!.=$) {temp=0;i=0;c=0; cout<<+,n enter octal number to be added:+; cin>>ov; temp=ov; *hile(i==0) {if((temp1$0)>8) {c22;} temp=temp)$0; if(temp==0) {i=$;} } if(c.=0) $@
{cout<<+,n invalid value enter a-ain ,n+; } if(c==0) {!=$;} } } int octal :: operator2(int v) {int c=0'l'0=$'temp; temp=ov; *hile(temp.=0) {l=temp1$0; l=l&0; c=c2l; temp=temp)$0; 0=0&M; } temp=c2v; return temp; } octal octal:: operator=(int iv) {int r=0'i=0';'l'0'temp; temp=iv; *hile(temp.=0) {0=$; for(;=0;;<i;;22) {0=0&$0;} l=temp1M; temp=temp)M; r=0&l2r; i22; } ov=r; } void octal :: octcon(int iv) {int r=0'i=0';'l'0'temp; temp=iv; *hile(temp.=0) {0=$; for(;=0;;<i;;22) {0=0&$0;} l=temp1M; temp=temp)M; r=0&l2r; i22; } ov=r;
$8
} void main() {int c=0'0=0'v; clrscr(); *hile(0==0) {clrscr(); cout<<+,n enter the choice of operation to be performed ,n$/conversion of decimal to octal ,n%/addition of an octal and an inte-er ,n"/e!it,n ,n enter choice:+; cin>>c; s*itch(c) {case $:cout<<+,n enter the inte-er value to be converted:+; cin>>v; n$.octcon(v); n$.sho*data(v); brea0; case %:n$.-etdata(); cout<<+,n enter the inte-er value to be added:+; cin>>v; n%=n$2v; n%.sho*data(v'0); brea0; case ":0=$; cout<<+,n than0s for usin- the pro-ram+; brea0; default:cout<<+,n (ou have entered *ron- choice tr( a-ain+; -etch(); } } -etch(); }
$M
;-Create a Class time that has separate int member data for hours,minutes and seconds.8ne constructor should initiali6e this data to < and another should initial=i6e it to fi-ed !alues. Another member function should displa# it in 11',;',; format. "he final member function should add two time ob4ects passed as arguments.
#include<iostream.h> #include<conio.h> class time {private:int h; int m; int s; public:time() {h=0;m=0;s=0;} time(int a'int b'int c) {h=a;m=b;s=c;} void -etdata(); void sho*data() {cout<<+,n the time /> +<<h<<+:+<<m<<+:+<<s<<+.+; cout<<+,n+; -etch(); } void sum(time a'time b) {int t=0; h=a.h2b.h; m=a.m2b.m; s=a.s2b.s; if(s>@0) {t=s)@0; s=s/(@0&t); m=m2t; } t=0; if(m>@0) {t=m)@0; m=m/(@0&t); h=h2t; } } }t$'t%'t"; void time :: -etdata() {int c=0't=0; clrscr(); *hile(c==0) {cout<<+,n enter the parameters of time ,n+; cout<<+,n enter seconds: +; $Q
cin>>s; if(s<0) {cout<<+,n please enter the positive value ,n+; } else {if(s>@0) {t=s)@0; s=s/(t&@0); } c=$; } } c=$; *hile(c==$) {cout<<+,n enter minutes: +; cin>>m; if(m<0) {cout<<+,n (ou have entered *ron- value enter a-ain+; } else {m=m2t; if(m>@0) {t=m)@0; m=m/(t&@0); } else {t=0;} c=0; } } c=0; *hile(c==0) {cout<<+,n enter hour: +; cin>>h; if(h<0) {cout<<+,n sorr( (ou have entered *ron- value enter a-ain+; } else {h=h2t; c=$; } } } void main() {int n'i; clrscr();
%0
t$.-etdata(); t$.sho*data(); t%.-etdata(); t%.sho*data(); cout<<+ sum of+; t".sum(t$'t%); t".sho*data(); -etch(); }
%$
1<-Write a program to creat a base Class shape. 5se this Class to store two double t#pe !alues that could be used to compute the area of figures. )eri!e two specific classes triangle and rectangle from the base class shape.Add to the base class a member function get%data>( to initiali6e base class data members and another function displa#%area>( to compute and displa# the area of figures.?a e the displa#%area function a !irtual function and redefine this function in the deri!ed classes to suit their re&uirements. 5sing these three classes design a program that will accept dimensions of a triangle or a rectangle interacti!el# and displa# the area.
#include<iostream.h> #include<conio.h> class shape {protected:double d$'d%; public:virtual void displa(area()=0; void -etdata() {cout<<+,n enter the parameters for area to be calculated:+; cout<<+,n enter len-th: +; cin>>d$; cout<<+,n enter *idth or hei-ht: +; cin>>d%; } }; class trian-le:public shape {public:void displa(area() {cout<<+,n the area of trian-le is:+<<d$&d%)%; } }t; class rectan-le:public shape {public:void displa(area() {cout<<+,n the area of rectan-le is:+<<d$&d%; } }r; void main() {int n=0'i; shape &ptr; clrscr(); *hile(n.=$) {clrscr(); cout<<+,n enter the choice of fi-ure *hose area is to be calculated ,n$/rectan-le,n%/ trian-le,n"/e!it,nenter (our choice:+; cin>>i; %%
s*itch(i) {case $:cout<<+,nfor rectan-le,n+; ptr=Vr; ptr/>-etdata(); ptr/>displa(area(); brea0; case %:cout<<+,nfor trian-le,n+; ptr=Vt; ptr/>-etdata(); ptr/>displa(area(); brea0; case ":n=$; brea0; default:cout<<+,n sorr( (ou have entered *ron- choice,n+; } cout<<+,n do (ou *ant to continue ((es:0'no:$):+; cin>>n; } -etch(); }
%"