Create a class Account. It has three data member account id, name and balance. Define function to assign value and display value. Define function that search account number given by the user. If account number exists, print detail of that account. Write a program using array of object. Declare at least 5 account and print details.
Code :
Output :
Code :
#include<iostream.h>
#include<conio.h>
int setflag = 0;
class account
{
public:
int ac_id, bal;
char name[5];
void get()
{
cout<<"Enter Account id : ";
cin>>ac_id;
cout<<"Enter Name of the account holder : ";
cin>>name;
cout<<"Enter available balance : ";
cin>>bal;
}
void show()
{
cout<<"\n\nID : "<<ac_id;
cout<<"\nName : "<<name;
cout<<"\nBalance : "<<bal;
}
void search(account ob,int s_id)
{
if(ob.ac_id == s_id)
{
setflag = ob.ac_id;
}
}
};
void main()
{
int sr_id;
clrscr();
account ac[5];
for(int d=0;d<5;d++)
{
ac[d].get();
}
for(d=0;d<5;d++)
{
ac[d].show();
}
cout<<"\nEnter the ID to search : ";
cin>>sr_id;
for(d=0;d<5;d++)
{
ac[d].search(ac[d],sr_id);
}
if(setflag == 0)
{
cout<<"\nRecord Not Found..";
}
else
{
cout<<"\nRecord Found : ";
ac[setflag-1].show();
}
getch();
}
Output :
No comments:
Post a Comment