Professional Documents
Culture Documents
2007
void bank::getdata() { accno=acc++; cout<<"Your Account no is "<<accno<<endl; cout<<"Enter the Name ";cin>>name; cout<<"Enter the Amount ";cin>>amount; }
void bank::deposit(bank *b,int n,int acc) { float damt; LOVELY INSTITUTE OF MANAGEMENT PAGE 19
2007
int chk=0; cout<<"Enter the amount to deposit "; cin>>damt; for(int i=0;i<n;i++) { if(b[i].accno==acc) { b[i].amount=b[i].amount+damt; cout<<"ACCOUNT UPDATED\n "; chk=1; } } if(chk==0) { cout<<"\nTRANSACTION ABORTED"; } }
void bank::putdata(bank *p,int n,int acc) { for(int i=0;i<n;i++) { if(p[i].accno==acc) { cout<<"Name is "<<p[i].name<<"\n"; cout<<"account No is "<<p[i].accno<<"\n"; cout<<"Amount is "<<p[i].amount<<endl; } } }
void bank::withdraw(bank *b,int n,int acc) { float wamt; int chk=0; cout<<"Enter the Amount To WITHDRAW "; LOVELY INSTITUTE OF MANAGEMENT PAGE 20
2007
cin>>wamt; for(int i=0;i<n;i++) { if(b[i].accno==acc&&b[i].amount>wamt) { b[i].amount=b[i].amount-wamt; cout<<"ACCOUNT UPDATED"; chk=1; } } if(chk==0) { cout<<"\nTRANSACTION ABORTED\n "; } }
int bank::search(bank *b,int n,int acc) { int a=0; for(int i=0;i<n;i++) { if(b[i].accno==acc) { a=1; } } return a; }
PAGE 21
2007
void main() { bank *a;int n,opt,ano,rtn; clrscr(); cout<<"\nEnter the no of customer "; cin>>n; a=new bank[n]; if(!a) cout<<"\nAlloaction faioled"; clrscr(); for(int i=0;i<n;i++) { a[i].getdata(); } start: clrscr(); cout<<"\nTo display an information (Press 1 ) "; cout<<"\nTo deposit An Amount (Press 2 ) " ; cout<<"\nTo Withdraw An Amount (Press 3 ) " ; cout<<"\nTo EXIT (Press 4) "; cin>>opt; if(opt<=3) { cout<<"Enter your account No "; cin>>ano; } switch(opt) { case 1: rtn=a[0].search(a,n,ano); if(rtn==1) a[0].putdata(a,n,ano); else cout<<"Account Does't Exist "; getch(); goto start; case 2: rtn=a[0].search(a,n,ano); LOVELY INSTITUTE OF MANAGEMENT PAGE 22
2007
if(rtn==1) { a[0].deposit(a,n,ano); a[0].putdata(a,n,ano); } else { cout<<"Account Does't Exist "; } getch(); goto start; case 3: rtn=a[0].search(a,n,ano); if(rtn==1) { a[0].withdraw(a,n,ano); a[0].putdata(a,n,ano); } else { cout<<"Account Does't Exist "; } getch(); goto start; case 4: exit(0); default: cout<<"\nYOU ENTER WRONG CHOICE \tRETRY AGAIN"; getch(); goto start; }
PAGE 23
2007
PAGE 24
2007
2007
c++; r=a.r; i=a.i; } ~cplx() { cout<<"\nHello destructor "<<c; c--; } }; int cplx::c=0;
void main() { clrscr(); cplx c1=5; c1.show(); cplx c2(6,7); c2.show(); cplx c4; c4.show(); cplx c3(c1); c3.show(); getch(); }
PAGE 26
2007
PAGE 27
2007
class str { char *name; int len; public: str() { char *b; gets(b); len=strlen(b); name=new char[len+1]; strcpy(name,b); } str(char *a) { len=strlen(a); name=new char[len+1]; strcpy(name,a); } void display() { cout<<name; } }; LOVELY INSTITUTE OF MANAGEMENT PAGE 28
2007
void main() { clrscr(); str a; char *Name="gurpreet"; str name1(Name); str na("singh"); name1.display(); na.display(); getch(); }
PAGE 29
2007
2007
void emp::hsal(emp *a,int t) { int max=a[0].sal,c=0; for(int i=0;i<t-1;i++) { if(max<a[i+1].sal) { max=a[i+1].sal; c=i+1; } } cout<<"\nThe information Whose higher salary\n"; a[c].putdata(); }
void emp::avg(emp *a,int t) { int average=0; for(int i=0;i<t;i++) { average+=a[i].age; } cout<<"\nThe average age is: "<<average/t; } void main() { emp a[50]; int b,i; clrscr(); cout<<"Enter no of employee";cin>>b; cout<<"Enter the information of employee (Name,salary,age,department id) "; for(i=0;i<b;i++) { a[i].getdata(); LOVELY INSTITUTE OF MANAGEMENT PAGE 31
2007
PAGE 32
2007
PAGE 33
2007
class DI { int feet; int inche; public: void getdata(); friend DM add(DM,DI); };
void DI::getdata() { cout<<"Enter the height in FEET & INCHES \n Enter Feet "; cin>>feet; cout<<"Enter Inches "; ci:cin>>inche; if(inche>11) { cout<<"wrong Input Inches can Never > 11\n\n ENTER INCHES AGAIN \n"; goto ci; } }
DM add(DM dm,DI di) {DM temp;int i,k; i=(dm.meter*100)+dm.cmeter; k=(((di.feet*12)+di.inche)*2.54); i=i+k; temp.meter=i/100; temp.cmeter=i%100; return temp; }
PAGE 34
2007
void main() { DM dm,final; DI di; clrscr(); dm.getdata(); di.getdata(); final=add(dm,di); final.putdata(); getch(); }
PAGE 35
2007
#include<iostream.h> #include<conio.h> class vector { float vec[10]; public: void getdata(int); void modify(); void multiply(int,int); void putdata(int); }; void vector::putdata(int n) { cout<<"{"; for(int i=0;i<n;i++) { cout<<vec[i]<<","; } cout<<"}"; } void vector::getdata(int a) { for(int i=0;i<a;i++) { cout<<"Enter the Element Of Vector"; cin>>vec[i]; } } LOVELY INSTITUTE OF MANAGEMENT PAGE 36
2007
void vector::modify() { int a; cout<<"Enter the position of the element(1,2,3...."; cin>>a; cout<<"Entre the New Value"; cin>>vec[a-1]; } void vector::multiply(int n,int b) { for(int i=0;i<n;i++) { vec[i]=vec[i]*b; } }
void main() { vector v1; int n,val; char opt,opt1; clrscr(); cout<<"Enter the no of vector element"; cin>>n; v1.getdata(n); cout<<"Are u want to change any element(y/n)"; cin>>opt; if(opt=='y') { v1.modify(); } cout<<"Are u want to multiply by scaler(y/n)"; cin>>opt1; if(opt1=='y') { cout<<"Enter the value for scaler multiplication"; cin>>val; v1.multiply(n,val); LOVELY INSTITUTE OF MANAGEMENT PAGE 37
2007
} v1.putdata(n); getch(); }
PAGE 38
2007
TABLE OF CONTENT
Program to demonstrate Passing array to function (Taking example of Bank) ................ 19 Program to demonstrate the concept of the Constructor Overloading & Destructor ...... 25 Program to demonstrate the concept of Dynamic Allocation of Memory through Constructor ................................................................................................................ 28 Program to demonstrate the concept of ARRAY OF OBJECT ............................................. 30 Program to demonstrate the concept of FRIEND FUNCTION ............................................ 33 Program to demonstrate the Working of VECTOR and perform following task ............... 36 Enter the Vector elements ........................................................................................ 36 After ensure from user modify its element ............................................................. 36 Multiply vector with scalar ........................................................................................ 36
PAGE 39