Program 2

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.

#include<iostream>
using namespace std;

int fg;

class account
{
int id;
char name[15];
float bal;

public:
void getdata()
{
cout<<endl<<"Enter id: ";
cin>>id;

cout<<"Enter name: ";
cin>>name;

cout<<"Enter balance: ";
cin>>bal;
}

void show()
{
cout<<endl<<"Id= "<<id<<endl<<"Name= "<<name<<endl<<"Bal= "<<bal<<endl;
}

void search(int s)
{
if(id==s)
fg=1;
}
};

int main()
{
account a[3];
int i;

for(i=0;i<3;i++)
a[i].getdata();

for(i=0;i<3;i++)
a[i].show();

int s;

cout<<endl<<"Enter id for search: ";
cin>>s;

for(i=0;i<3;i++)
{
a[i].search(s);

if(fg==1)
break;
}

if(fg==1)
{
cout<<endl<<"Found....";
a[i].show();
}

else
cout<<endl<<"Not Found........!";
}

Output :-


No comments:

Post a Comment

Programs

HOME Write a program to demonstrate the use of call byvalue and call by reference. Createa class Account. It has three data member a...